1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
TheBusyBiscuit 2020-08-28 20:03:45 +02:00
parent dc7d892ff9
commit 83b66232fa
11 changed files with 223 additions and 140 deletions

View File

@ -83,6 +83,8 @@
* Fixed #2243
* Fixed #2249
* Fixed #1022
* Fixed Fluid Pump treating low-level fluids like stationary fluids
* Fixed Fluid Pump not working on Bubble Columns
* Fixed #2208
## Release Candidate 15 (01 Aug 2020)

View File

@ -45,6 +45,7 @@ import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService;
import io.github.thebusybiscuit.slimefun4.core.services.plugins.ThirdPartyPluginService;
import io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor;
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GrapplingHook;
@ -144,7 +145,6 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
private final Config researches = new Config(this, "Researches.yml");
// Listeners that need to be accessed elsewhere
private final AncientAltarListener ancientAltarListener = new AncientAltarListener();
private final GrapplingHookListener grapplingHookListener = new GrapplingHookListener();
private final BackpackListener backpackListener = new BackpackListener();
private final SlimefunBowListener bowListener = new SlimefunBowListener();
@ -209,7 +209,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
networkManager = new NetworkManager(networkSize);
// Setting up bStats
new Thread(metricsService::start).start();
new Thread(metricsService::start, "Slimefun Metrics").start();
// Starting the Auto-Updater
if (config.getBoolean("options.auto-update")) {
@ -459,9 +459,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
new VampireBladeListener(this, (VampireBlade) SlimefunItems.BLADE_OF_VAMPIRES.getItem());
new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem());
new SeismicAxeListener(this, (SeismicAxe) SlimefunItems.SEISMIC_AXE.getItem());
new AncientAltarListener(this, (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem(), (AncientPedestal) SlimefunItems.ANCIENT_PEDESTAL.getItem());
grapplingHookListener.register(this, (GrapplingHook) SlimefunItems.GRAPPLING_HOOK.getItem());
ancientAltarListener.register(this, (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem());
bowListener.register(this);
// Toggleable Listeners for performance reasons
@ -623,10 +622,6 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
return instance.networkManager;
}
public static AncientAltarListener getAncientAltarListener() {
return instance.ancientAltarListener;
}
public static GrapplingHookListener getGrapplingHookListener() {
return instance.grapplingHookListener;
}

View File

@ -1,5 +1,8 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.altar;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.AncientAltarCraftEvent;
@ -26,6 +29,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class AncientAltar extends SlimefunItem {
private final int speed;
private final List<AltarRecipe> recipes = new ArrayList<>();
public AncientAltar(Category category, int speed, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -48,4 +52,8 @@ public class AncientAltar extends SlimefunItem {
return speed;
}
public List<AltarRecipe> getRecipes() {
return recipes;
}
}

View File

@ -1,30 +1,131 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.altar;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import java.util.Optional;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.AncientAltarTask;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
/**
* The {@link AncientPedestal} is a part of the {@link AncientAltar}.
* You can place any {@link ItemStack} onto the {@link AncientPedestal} to provide it to
* the altar as a crafting ingredient.
*
* @author Redemption198
* @author TheBusyBiscuit
*
* @see AncientAltar
* @see AncientAltarListener
* @see AncientAltarTask
*
*/
public class AncientPedestal extends SlimefunItem {
public static final String ITEM_PREFIX = ChatColors.color("&dALTAR &3Probe - &e");
public AncientPedestal(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, recipeType, recipe, recipeOutput);
SlimefunItem.registerBlockHandler(getID(), (p, b, tool, reason) -> {
AncientAltarListener listener = SlimefunPlugin.getAncientAltarListener();
Item stack = listener.findItem(b);
Optional<Item> entity = getPlacedItem(b);
if (stack != null) {
stack.removeMetadata("no_pickup", SlimefunPlugin.instance());
b.getWorld().dropItem(b.getLocation(), listener.fixItemStack(stack.getItemStack(), stack.getCustomName()));
stack.remove();
if (entity.isPresent()) {
Item stack = entity.get();
if (stack.isValid()) {
stack.removeMetadata("no_pickup", SlimefunPlugin.instance());
b.getWorld().dropItem(b.getLocation(), getOriginalItemStack(stack));
stack.remove();
}
}
return true;
});
}
public Optional<Item> getPlacedItem(Block pedestal) {
Location l = pedestal.getLocation().add(0.5, 1.2, 0.5);
for (Entity n : l.getWorld().getNearbyEntities(l, 0.5, 0.5, 0.5, this::testItem)) {
if (n instanceof Item) {
return Optional.of((Item) n);
}
}
return Optional.empty();
}
private boolean testItem(Entity n) {
if (n instanceof Item && n.isValid()) {
Item item = (Item) n;
ItemMeta meta = item.getItemStack().getItemMeta();
return meta.hasDisplayName() && meta.getDisplayName().startsWith(ITEM_PREFIX);
}
else {
return false;
}
}
public ItemStack getOriginalItemStack(Item item) {
ItemStack stack = item.getItemStack().clone();
String customName = item.getCustomName();
if (customName.equals(ItemUtils.getItemName(new ItemStack(stack.getType())))) {
ItemMeta im = stack.getItemMeta();
im.setDisplayName(null);
stack.setItemMeta(im);
}
else {
ItemMeta im = stack.getItemMeta();
if (!customName.startsWith(String.valueOf(ChatColor.COLOR_CHAR))) {
customName = ChatColor.WHITE + customName;
}
im.setDisplayName(customName);
stack.setItemMeta(im);
}
return stack;
}
public void placeItem(Player p, Block b) {
ItemStack hand = p.getInventory().getItemInMainHand();
ItemStack stack = new CustomItem(hand, ITEM_PREFIX + System.nanoTime());
stack.setAmount(1);
if (p.getGameMode() != GameMode.CREATIVE) {
ItemUtils.consumeItem(hand, false);
}
String nametag = ItemUtils.getItemName(stack);
Item entity = b.getWorld().dropItem(b.getLocation().add(0.5, 1.2, 0.5), stack);
entity.setVelocity(new Vector(0, 0.1, 0));
SlimefunUtils.markAsNoPickup(entity, "altar_item");
entity.setCustomNameVisible(true);
entity.setCustomName(nametag);
p.playSound(b.getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.3F, 0.3F);
}
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.Optional;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
@ -34,7 +35,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
/**
* This machine draws liquids from the world and puts them
* This machine collects liquids from the {@link World} and puts them
* into buckets provided to the machine by using energy.
*
* @author TheBusyBiscuit
@ -140,34 +141,47 @@ public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements Invent
}
private void consumeFluid(Block fluid) {
if (!fluid.isLiquid()) return;
if (fluid.getType() == Material.WATER) {
fluid.setType(Material.AIR);
return;
if (fluid.isLiquid()) {
if (fluid.getType() == Material.WATER || fluid.getType() == Material.BUBBLE_COLUMN) {
// With water we can be sure to find an infinite source whenever we go
// further than 2 blocks, so we can just remove the water here and save
// outselves all of that computing...
fluid.setType(Material.AIR);
}
else {
List<Block> list = Vein.find(fluid, RANGE, block -> isLiquid(block) && block.getType() == fluid.getType());
list.get(list.size() - 1).setType(Material.AIR);
}
}
List<Block> list = Vein.find(fluid, RANGE, block -> isLiquid(block) && block.getType() == fluid.getType());
list.get(list.size() - 1).setType(Material.AIR);
}
private Optional<ItemStack> getFilledBucket(Block fluid) {
if (fluid.getType() == Material.LAVA) {
return Optional.of(new ItemStack(Material.LAVA_BUCKET));
}
else if (fluid.getType() == Material.WATER) {
else if (fluid.getType() == Material.WATER || fluid.getType() == Material.BUBBLE_COLUMN) {
return Optional.of(new ItemStack(Material.WATER_BUCKET));
}
return Optional.empty();
}
private boolean isLiquid(Block block) {
if (!block.isLiquid()) return false;
BlockData data = block.getBlockData();
if (data instanceof Levelled) {
return ((Levelled) data).getLevel() == 0;
else {
return Optional.empty();
}
}
private boolean isLiquid(Block block) {
if (block.isLiquid()) {
BlockData data = block.getBlockData();
if (data instanceof Levelled) {
// Check if this is a full block.
return ((Levelled) data).getLevel() == 0;
}
else {
return false;
}
}
else {
return false;
}
return false;
}
@Override

View File

@ -8,14 +8,12 @@ import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
@ -25,9 +23,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
@ -54,19 +50,19 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
*/
public class AncientAltarListener implements Listener {
public static final String ITEM_PREFIX = ChatColors.color("&dALTAR &3Probe - &e");
private AncientAltar altarItem;
private AncientPedestal pedestalItem;
private AncientAltar altar;
private final Set<AltarRecipe> altarRecipes = new HashSet<>();
private final Set<Location> altarsInUse = new HashSet<>();
private final List<Block> altars = new ArrayList<>();
private final Set<UUID> removedItems = new HashSet<>();
public void register(SlimefunPlugin plugin, AncientAltar altar) {
public AncientAltarListener(SlimefunPlugin plugin, AncientAltar altar, AncientPedestal pedestal) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
this.altar = altar;
this.altarItem = altar;
this.pedestalItem = pedestal;
}
/**
@ -82,13 +78,9 @@ public class AncientAltarListener implements Listener {
return altars;
}
public Set<AltarRecipe> getRecipes() {
return altarRecipes;
}
@EventHandler
public void onInteract(PlayerRightClickEvent e) {
if (altar == null || altar.isDisabled() || e.useBlock() == Result.DENY) {
if (altarItem == null || altarItem.isDisabled() || e.useBlock() == Result.DENY) {
return;
}
@ -109,12 +101,12 @@ public class AncientAltarListener implements Listener {
String id = slimefunBlock.get().getID();
if (id.equals(SlimefunItems.ANCIENT_PEDESTAL.getItemId())) {
if (id.equals(pedestalItem.getID())) {
e.cancel();
usePedestal(b, e.getPlayer());
}
else if (id.equals(SlimefunItems.ANCIENT_ALTAR.getItemId())) {
if (!Slimefun.hasUnlocked(e.getPlayer(), SlimefunItems.ANCIENT_ALTAR.getItem(), true) || altarsInUse.contains(b.getLocation())) {
else if (id.equals(altarItem.getID())) {
if (!Slimefun.hasUnlocked(e.getPlayer(), altarItem, true) || altarsInUse.contains(b.getLocation())) {
e.cancel();
return;
}
@ -138,9 +130,9 @@ public class AncientAltarListener implements Listener {
}
// getting the currently placed item
Item stack = findItem(pedestal);
Optional<Item> stack = pedestalItem.getPlacedItem(pedestal);
if (stack == null) {
if (!stack.isPresent()) {
// Check if the Item in hand is valid
if (p.getInventory().getItemInMainHand().getType() != Material.AIR) {
// Check for pedestal obstructions
@ -150,17 +142,18 @@ public class AncientAltarListener implements Listener {
}
// place the item onto the pedestal
insertItem(p, pedestal);
pedestalItem.placeItem(p, pedestal);
}
}
else if (!removedItems.contains(stack.getUniqueId())) {
UUID uuid = stack.getUniqueId();
else if (!removedItems.contains(stack.get().getUniqueId())) {
Item entity = stack.get();
UUID uuid = entity.getUniqueId();
removedItems.add(uuid);
Slimefun.runSync(() -> removedItems.remove(uuid), 30L);
stack.remove();
p.getInventory().addItem(fixItemStack(stack.getItemStack(), stack.getCustomName()));
entity.remove();
p.getInventory().addItem(pedestalItem.getOriginalItemStack(entity));
p.playSound(pedestal.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1F, 1F);
}
}
@ -209,10 +202,10 @@ public class AncientAltarListener implements Listener {
List<ItemStack> input = new ArrayList<>();
for (Block pedestal : pedestals) {
Item stack = findItem(pedestal);
Optional<Item> stack = pedestalItem.getPlacedItem(pedestal);
if (stack != null) {
input.add(fixItemStack(stack.getItemStack(), stack.getCustomName()));
if (stack.isPresent()) {
input.add(pedestalItem.getOriginalItemStack(stack.get()));
}
}
@ -227,7 +220,9 @@ public class AncientAltarListener implements Listener {
}
b.getWorld().playSound(b.getLocation(), Sound.ENTITY_ILLUSIONER_PREPARE_MIRROR, 1, 1);
Slimefun.runSync(new AncientAltarTask(b, altar.getSpeed(), result.get(), pedestals, consumed, p), 10L);
AncientAltarTask task = new AncientAltarTask(this, b, altarItem.getSpeed(), result.get(), pedestals, consumed, p);
Slimefun.runSync(task, 10L);
}
else {
altars.remove(b);
@ -255,7 +250,7 @@ public class AncientAltarListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
if (altar == null || altar.isDisabled()) {
if (altarItem == null || altarItem.isDisabled()) {
return;
}
@ -264,82 +259,38 @@ public class AncientAltarListener implements Listener {
if (pedestal.getType() == Material.DISPENSER) {
String id = BlockStorage.checkID(pedestal);
if (id != null && id.equals(SlimefunItems.ANCIENT_PEDESTAL.getItemId())) {
if (id != null && id.equals(pedestalItem.getID())) {
SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "messages.cannot-place", true);
e.setCancelled(true);
}
}
}
public ItemStack fixItemStack(ItemStack itemStack, String customName) {
ItemStack stack = itemStack.clone();
if (customName.equals(ItemUtils.getItemName(new ItemStack(itemStack.getType())))) {
ItemMeta im = stack.getItemMeta();
im.setDisplayName(null);
stack.setItemMeta(im);
}
else {
ItemMeta im = stack.getItemMeta();
if (!customName.startsWith(String.valueOf(ChatColor.COLOR_CHAR))) customName = ChatColor.RESET + customName;
im.setDisplayName(customName);
stack.setItemMeta(im);
}
return stack;
}
public Item findItem(Block b) {
for (Entity n : b.getChunk().getEntities()) {
if (n instanceof Item && b.getLocation().add(0.5, 1.2, 0.5).distanceSquared(n.getLocation()) < 0.5D && n.getCustomName() != null) {
return (Item) n;
}
}
return null;
}
private void insertItem(Player p, Block b) {
ItemStack hand = p.getInventory().getItemInMainHand();
ItemStack stack = new CustomItem(hand, 1);
if (p.getGameMode() != GameMode.CREATIVE) {
ItemUtils.consumeItem(hand, false);
}
String nametag = ItemUtils.getItemName(stack);
Item entity = b.getWorld().dropItem(b.getLocation().add(0.5, 1.2, 0.5), new CustomItem(stack, ITEM_PREFIX + System.nanoTime()));
entity.setVelocity(new Vector(0, 0.1, 0));
SlimefunUtils.markAsNoPickup(entity, "altar_item");
entity.setCustomNameVisible(true);
entity.setCustomName(nametag);
p.playSound(b.getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.3F, 0.3F);
}
private List<Block> getPedestals(Block altar) {
List<Block> list = new ArrayList<>();
String id = SlimefunItems.ANCIENT_PEDESTAL.getItemId();
if (BlockStorage.check(altar.getRelative(2, 0, -2), id)) {
if (BlockStorage.check(altar.getRelative(2, 0, -2), pedestalItem.getID())) {
list.add(altar.getRelative(2, 0, -2));
}
if (BlockStorage.check(altar.getRelative(3, 0, 0), id)) {
if (BlockStorage.check(altar.getRelative(3, 0, 0), pedestalItem.getID())) {
list.add(altar.getRelative(3, 0, 0));
}
if (BlockStorage.check(altar.getRelative(2, 0, 2), id)) {
if (BlockStorage.check(altar.getRelative(2, 0, 2), pedestalItem.getID())) {
list.add(altar.getRelative(2, 0, 2));
}
if (BlockStorage.check(altar.getRelative(0, 0, 3), id)) {
if (BlockStorage.check(altar.getRelative(0, 0, 3), pedestalItem.getID())) {
list.add(altar.getRelative(0, 0, 3));
}
if (BlockStorage.check(altar.getRelative(-2, 0, 2), id)) {
if (BlockStorage.check(altar.getRelative(-2, 0, 2), pedestalItem.getID())) {
list.add(altar.getRelative(-2, 0, 2));
}
if (BlockStorage.check(altar.getRelative(-3, 0, 0), id)) {
if (BlockStorage.check(altar.getRelative(-3, 0, 0), pedestalItem.getID())) {
list.add(altar.getRelative(-3, 0, 0));
}
if (BlockStorage.check(altar.getRelative(-2, 0, -2), id)) {
if (BlockStorage.check(altar.getRelative(-2, 0, -2), pedestalItem.getID())) {
list.add(altar.getRelative(-2, 0, -2));
}
if (BlockStorage.check(altar.getRelative(0, 0, -3), id)) {
if (BlockStorage.check(altar.getRelative(0, 0, -3), pedestalItem.getID())) {
list.add(altar.getRelative(0, 0, -3));
}
@ -370,7 +321,7 @@ public class AncientAltarListener implements Listener {
}
private Optional<ItemStack> checkRecipe(ItemStack catalyst, List<ItemStackWrapper> items) {
for (AltarRecipe recipe : altarRecipes) {
for (AltarRecipe recipe : altarItem.getRecipes()) {
if (SlimefunUtils.isItemSimilar(catalyst, recipe.getCatalyst(), true)) {
Optional<ItemStack> optional = checkPedestals(items, recipe);

View File

@ -7,6 +7,7 @@ import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
/**
@ -28,7 +29,7 @@ public class ItemPickupListener implements Listener {
else if (e.getItem().getItemStack().hasItemMeta()) {
ItemMeta meta = e.getItem().getItemStack().getItemMeta();
if (meta.hasDisplayName() && meta.getDisplayName().startsWith(AncientAltarListener.ITEM_PREFIX)) {
if (meta.hasDisplayName() && meta.getDisplayName().startsWith(AncientPedestal.ITEM_PREFIX)) {
e.setCancelled(true);
e.getItem().remove();
}
@ -43,7 +44,7 @@ public class ItemPickupListener implements Listener {
else if (e.getItem().getItemStack().hasItemMeta()) {
ItemMeta meta = e.getItem().getItemStack().getItemMeta();
if (meta.hasDisplayName() && meta.getDisplayName().startsWith(AncientAltarListener.ITEM_PREFIX)) {
if (meta.hasDisplayName() && meta.getDisplayName().startsWith(AncientPedestal.ITEM_PREFIX)) {
e.setCancelled(true);
e.getItem().remove();
}

View File

@ -5,8 +5,8 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import io.github.thebusybiscuit.slimefun4.api.events.AncientAltarCraftEvent;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Location;
@ -18,8 +18,11 @@ import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.AncientAltarCraftEvent;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener;
import me.mrCookieSlime.Slimefun.api.Slimefun;
@ -37,7 +40,8 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
*/
public class AncientAltarTask implements Runnable {
private final AncientAltarListener listener = SlimefunPlugin.getAncientAltarListener();
private final AncientAltarListener listener;
private final AncientPedestal pedestalItem = (AncientPedestal) SlimefunItems.ANCIENT_PEDESTAL.getItem();
private final Block altar;
private final int speed;
@ -47,13 +51,14 @@ public class AncientAltarTask implements Runnable {
private final List<ItemStack> items;
private final Collection<Location> particleLocations = new LinkedList<>();
private final Map<Item, Location> itemLock = new HashMap<>();
private final Map<Item, Location> positionLock = new HashMap<>();
private boolean running;
private int stage;
private final Player player;
public AncientAltarTask(Block altar, int speed, ItemStack output, List<Block> pedestals, List<ItemStack> items, Player player) {
public AncientAltarTask(AncientAltarListener listener, Block altar, int speed, ItemStack output, List<Block> pedestals, List<ItemStack> items, Player player) {
this.listener = listener;
this.dropLocation = altar.getLocation().add(0.5, 1.3, 0.5);
this.speed = speed;
this.altar = altar;
@ -66,8 +71,12 @@ public class AncientAltarTask implements Runnable {
this.stage = 0;
for (Block pedestal : pedestals) {
Item item = listener.findItem(pedestal);
this.itemLock.put(item, item.getLocation().clone());
Optional<Item> item = pedestalItem.getPlacedItem(pedestal);
if (item.isPresent()) {
Item entity = item.get();
positionLock.put(entity, entity.getLocation().clone());
}
}
}
@ -94,7 +103,7 @@ public class AncientAltarTask implements Runnable {
}
private boolean checkLockedItems() {
for (Map.Entry<Item, Location> entry : itemLock.entrySet()) {
for (Map.Entry<Item, Location> entry : positionLock.entrySet()) {
if (entry.getKey().getLocation().distanceSquared(entry.getValue()) > 0.1) {
return false;
}
@ -114,22 +123,23 @@ public class AncientAltarTask implements Runnable {
}
private void checkPedestal(Block pedestal) {
Item item = listener.findItem(pedestal);
Optional<Item> item = pedestalItem.getPlacedItem(pedestal);
if (item == null || itemLock.remove(item) == null) {
if (!item.isPresent() || positionLock.remove(item.get()) == null) {
abort();
}
else {
Item entity = item.get();
particleLocations.add(pedestal.getLocation().add(0.5, 1.5, 0.5));
items.add(listener.fixItemStack(item.getItemStack(), item.getCustomName()));
items.add(pedestalItem.getOriginalItemStack(entity));
pedestal.getWorld().playSound(pedestal.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1F, 2F);
dropLocation.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, pedestal.getLocation().add(0.5, 1.5, 0.5), 16, 0.3F, 0.2F, 0.3F);
dropLocation.getWorld().spawnParticle(Particle.CRIT_MAGIC, pedestal.getLocation().add(0.5, 1.5, 0.5), 8, 0.3F, 0.2F, 0.3F);
itemLock.remove(item);
item.remove();
item.removeMetadata("no_pickup", SlimefunPlugin.instance());
positionLock.remove(entity);
entity.remove();
entity.removeMetadata("no_pickup", SlimefunPlugin.instance());
}
}
@ -143,7 +153,7 @@ public class AncientAltarTask implements Runnable {
// This should re-enable altar blocks on craft failure.
listener.getAltarsInUse().remove(altar.getLocation());
dropLocation.getWorld().playSound(dropLocation, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 1F, 1F);
itemLock.clear();
positionLock.clear();
listener.getAltars().remove(altar);
}

View File

@ -24,6 +24,7 @@ import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AltarRecipe;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@ -44,7 +45,8 @@ public class RecipeType implements Keyed {
public static final RecipeType ANCIENT_ALTAR = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "ancient_altar"), SlimefunItems.ANCIENT_ALTAR, (recipe, output) -> {
AltarRecipe altarRecipe = new AltarRecipe(Arrays.asList(recipe), output);
SlimefunPlugin.getAncientAltarListener().getRecipes().add(altarRecipe);
AncientAltar altar = ((AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem());
altar.getRecipes().add(altarRecipe);
});
public static final RecipeType MOB_DROP = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "mob_drop"), new CustomItem(Material.IRON_SWORD, "&bMob Drop"), RecipeType::registerMobDrop, "", "&rKill the specified Mob to obtain this Item");

View File

@ -61,7 +61,6 @@ public class TestPluginClass {
@Test
public void testListenersNotNull() {
Assertions.assertNotNull(SlimefunPlugin.getAncientAltarListener());
Assertions.assertNotNull(SlimefunPlugin.getGrapplingHookListener());
Assertions.assertNotNull(SlimefunPlugin.getBackpackListener());
Assertions.assertNotNull(SlimefunPlugin.getBowListener());

View File

@ -21,7 +21,7 @@ import be.seeseemelk.mockbukkit.ServerMock;
import be.seeseemelk.mockbukkit.entity.ItemEntityMock;
import be.seeseemelk.mockbukkit.inventory.ChestInventoryMock;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.ItemPickupListener;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.CSCoreLibPlugin.cscorelib2.item.CustomItem;
@ -83,7 +83,7 @@ class TestItemPickupListener {
ItemStack stack;
if (flag) {
stack = new CustomItem(Material.DIAMOND, AncientAltarListener.ITEM_PREFIX + System.nanoTime());
stack = new CustomItem(Material.DIAMOND, AncientPedestal.ITEM_PREFIX + System.nanoTime());
}
else {
stack = new CustomItem(Material.DIAMOND, "&5Just a normal named diamond");
@ -112,7 +112,7 @@ class TestItemPickupListener {
ItemStack stack;
if (flag) {
stack = new CustomItem(Material.DIAMOND, AncientAltarListener.ITEM_PREFIX + System.nanoTime());
stack = new CustomItem(Material.DIAMOND, AncientPedestal.ITEM_PREFIX + System.nanoTime());
}
else {
stack = new CustomItem(Material.DIAMOND, "&5Just a normal named diamond");