From 4678de16970bf43215f25d648f5ee98739bcb14a Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Wed, 10 Mar 2021 14:04:33 +0100 Subject: [PATCH] Fixes #2877 and added a new config option to crucibles --- CHANGELOG.md | 2 + .../implementation/items/blocks/Crucible.java | 48 +++++++++++++++---- .../interfaces/InventoryBlock.java | 4 +- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f9aa03ef..ea69fb3fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ #### Additions * Nether Wart Blocks can now be turned into Nether Warts using a Grind Stone * Added an option to allow Talismans to send their notifications via the Actionbar +* Added an option to enable/disable water in the nether via a crucible * /sf versions now shows the Java version and some useful tooltips #### Changes @@ -53,6 +54,7 @@ * Fixed #2861 * Fixed #2856 * Fixed #2876 +* Fixed #2877 ## Release Candidate 20 (30 Jan 2021) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java index 9f84d8bf9..4c9a6563c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java @@ -8,8 +8,10 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.Tag; +import org.bukkit.World.Environment; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.Levelled; @@ -19,6 +21,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; @@ -30,14 +33,26 @@ import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +/** + * The {@link Crucible} is a machine which turns blocks into liquids. + * It is a very reliable source of lava and water. + * The liquids will accumulate over time above the machine. + * + * @author TheBusyBiscuit + * @author Sfiguz7 + * + */ public class Crucible extends SimpleSlimefunItem implements RecipeDisplayItem { + private final ItemSetting allowWaterInNether = new ItemSetting<>("allow-water-in-nether", false); private final List recipes; + @ParametersAreNonnullByDefault public Crucible(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); recipes = getMachineRecipes(); + addItemSetting(allowWaterInNether); } @Override @@ -45,6 +60,7 @@ public class Crucible extends SimpleSlimefunItem implements Rec return recipes; } + @Nonnull private List getMachineRecipes() { List items = new LinkedList<>(); @@ -113,11 +129,11 @@ public class Crucible extends SimpleSlimefunItem implements Rec @ParametersAreNonnullByDefault private boolean craft(Player p, ItemStack input) { for (int i = 0; i < recipes.size(); i += 2) { - ItemStack convert = recipes.get(i); + ItemStack catalyst = recipes.get(i); - if (SlimefunUtils.isItemSimilar(input, convert, true)) { + if (SlimefunUtils.isItemSimilar(input, catalyst, true)) { ItemStack removing = input.clone(); - removing.setAmount(convert.getAmount()); + removing.setAmount(catalyst.getAmount()); p.getInventory().removeItem(removing); return true; @@ -127,15 +143,31 @@ public class Crucible extends SimpleSlimefunItem implements Rec return false; } - private void generateLiquid(@Nonnull Block block, boolean water) { - if (block.getType() == (water ? Material.WATER : Material.LAVA)) { - addLiquidLevel(block, water); - } else if (block.getType() == (water ? Material.LAVA : Material.WATER)) { + /** + * This method starts the process of generating liquids. + * + * @param block + * The {@link Block} where to generate the liquid + * @param isWater + * Whether we generate water or lava. + */ + private void generateLiquid(@Nonnull Block block, boolean isWater) { + // Fixes #2877 - If water in the nether is disabled, abort and play an effect. + if (isWater && block.getWorld().getEnvironment() == Environment.NETHER && !allowWaterInNether.getValue()) { + // We will still consume the items but won't generate water in the Nether. + block.getWorld().spawnParticle(Particle.SMOKE_NORMAL, block.getLocation().add(0.5, 0.5, 0.5), 4); + block.getWorld().playSound(block.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 1F, 1F); + return; + } + + if (block.getType() == (isWater ? Material.WATER : Material.LAVA)) { + addLiquidLevel(block, isWater); + } else if (block.getType() == (isWater ? Material.LAVA : Material.WATER)) { int level = ((Levelled) block.getBlockData()).getLevel(); block.setType(level == 0 || level == 8 ? Material.OBSIDIAN : Material.STONE); block.getWorld().playSound(block.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 1F, 1F); } else { - SlimefunPlugin.runSync(() -> placeLiquid(block, water), 50L); + SlimefunPlugin.runSync(() -> placeLiquid(block, isWater), 50L); } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/interfaces/InventoryBlock.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/interfaces/InventoryBlock.java index 348719f2d..59c1bb77c 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/interfaces/InventoryBlock.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/interfaces/InventoryBlock.java @@ -16,10 +16,10 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; /** * - * @deprecated This interface is not designed to be used by addons. + * @deprecated This interface is not designed to be used by addons. The entire inventory system will be replaced + * eventually. * */ -@Deprecated public interface InventoryBlock { /**