diff --git a/CHANGELOG.md b/CHANGELOG.md index a1ff7f54c..3c306a347 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ * Fixed some issues with the Book Binder * Fixed #2805 * Fixed #2861 +* Fixed #2856 ## Release Candidate 20 (30 Jan 2021) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java new file mode 100644 index 000000000..d2a558362 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java @@ -0,0 +1,62 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.blocks; + +import java.util.List; + +import javax.annotation.ParametersAreNonnullByDefault; + +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Dropper; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; +import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; +import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Smeltery; +import io.papermc.lib.PaperLib; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; + +/** + * The {@link IgnitionChamber} is used to re-ignite a {@link Smeltery}. + * + * @author TheBusyBiscuit + * + * @see Smeltery + * + */ +public class IgnitionChamber extends SimpleSlimefunItem { + + @ParametersAreNonnullByDefault + public IgnitionChamber(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + super(category, item, recipeType, recipe); + } + + @Override + public BlockBreakHandler getItemHandler() { + /* + * Explosions don't need explicit handling here. + * The default of "destroy the dispenser and drop the contents" is + * fine for our purposes already. + */ + return new BlockBreakHandler(false, true) { + + @Override + public void onPlayerBreak(BlockBreakEvent e, ItemStack item, List drops) { + // Fixes #2856 - Manually drop inventory contents + Block b = e.getBlock(); + BlockState state = PaperLib.getBlockState(b, false).getState(); + + if (state instanceof Dropper) { + for (ItemStack stack : ((Dropper) state).getInventory()) { + if (stack != null && !stack.getType().isAir()) { + drops.add(stack); + } + } + } + } + }; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MakeshiftSmeltery.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MakeshiftSmeltery.java index 83b044271..1efbe73f3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MakeshiftSmeltery.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MakeshiftSmeltery.java @@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks; import java.util.ArrayList; import java.util.List; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.Effect; import org.bukkit.Material; import org.bukkit.block.Block; @@ -17,6 +19,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class MakeshiftSmeltery extends AbstractSmeltery { + @ParametersAreNonnullByDefault public MakeshiftSmeltery(Category category, SlimefunItemStack item) { super(category, item, new ItemStack[] { null, new ItemStack(Material.OAK_FENCE), null, new ItemStack(Material.BRICKS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.BRICKS), null, new ItemStack(Material.FLINT_AND_STEEL), null }, BlockFace.DOWN); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java index 0d447e193..f119ce20b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java @@ -7,6 +7,8 @@ import java.util.Objects; import java.util.concurrent.ThreadLocalRandom; import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Effect; import org.bukkit.Material; @@ -26,6 +28,7 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.IgnitionChamber; import io.papermc.lib.PaperLib; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.BlockStorage; @@ -36,6 +39,7 @@ public class Smeltery extends AbstractSmeltery { private final BlockFace[] faces = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; private final ItemSetting fireBreakingChance = new IntRangeSetting("fire-breaking-chance", 0, 34, 100); + @ParametersAreNonnullByDefault public Smeltery(Category category, SlimefunItemStack item) { super(category, item, new ItemStack[] { null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.NETHER_BRICKS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.NETHER_BRICKS), null, new ItemStack(Material.FLINT_AND_STEEL), null }, BlockFace.DOWN); @@ -73,6 +77,7 @@ public class Smeltery extends AbstractSmeltery { } } + @ParametersAreNonnullByDefault private void consumeFire(Player p, Block dispenser, Block b) { Inventory chamber = findIgnitionChamber(dispenser); @@ -103,9 +108,12 @@ public class Smeltery extends AbstractSmeltery { } } + @Nullable private Inventory findIgnitionChamber(@Nonnull Block b) { for (BlockFace face : faces) { - if (b.getRelative(face).getType() == Material.DROPPER && BlockStorage.check(b.getRelative(face), "IGNITION_CHAMBER")) { + Block block = b.getRelative(face); + + if (block.getType() == Material.DROPPER && BlockStorage.check(block) instanceof IgnitionChamber) { BlockState state = PaperLib.getBlockState(b.getRelative(face), false).getState(); if (state instanceof Dropper) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index a3be57874..9ec9d2c06 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -52,6 +52,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.Crucible; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.EnhancedFurnace; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.HardenedGlass; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.HologramProjector; +import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.IgnitionChamber; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.OutputChest; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RepairedSpawner; @@ -402,7 +403,7 @@ public final class SlimefunItemSetup { new MakeshiftSmeltery(categories.basicMachines, SlimefunItems.MAKESHIFT_SMELTERY).register(plugin); new Smeltery(categories.basicMachines, SlimefunItems.SMELTERY).register(plugin); - new SlimefunItem(categories.basicMachines, SlimefunItems.IGNITION_CHAMBER, RecipeType.ENHANCED_CRAFTING_TABLE, + new IgnitionChamber(categories.basicMachines, SlimefunItems.IGNITION_CHAMBER, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {new ItemStack(Material.IRON_INGOT), new ItemStack(Material.FLINT_AND_STEEL), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.IRON_INGOT), SlimefunItems.BASIC_CIRCUIT_BOARD, new ItemStack(Material.IRON_INGOT), null, new ItemStack(Material.OBSERVER), null}) .register(plugin);