From 103bd8bbd4a7ff607cf7337870f9a65be17fa7cc Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Tue, 4 Jul 2023 15:10:40 -0500 Subject: [PATCH] Forward & Update svr's changes --- .../electric/machines/ElectricGoldPan.java | 49 ++++++-------- .../multiblocks/AutomatedPanningMachine.java | 65 ++++++++++--------- .../implementation/items/tools/GoldPan.java | 39 +++++++---- .../items/tools/NetherGoldPan.java | 10 ++- 4 files changed, 89 insertions(+), 74 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java index d3ccbcd60..8e494179a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java @@ -17,7 +17,6 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GoldPan; import io.github.thebusybiscuit.slimefun4.implementation.items.tools.NetherGoldPan; -import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; @@ -28,10 +27,11 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; * It also serves as a {@link NetherGoldPan}. * * @author TheBusyBiscuit - * + * @author svr333 + * @author JustAHuman + * * @see GoldPan * @see NetherGoldPan - * */ public class ElectricGoldPan extends AContainer implements RecipeDisplayItem { @@ -40,9 +40,6 @@ public class ElectricGoldPan extends AContainer implements RecipeDisplayItem { private final GoldPan goldPan = SlimefunItems.GOLD_PAN.getItem(GoldPan.class); private final GoldPan netherGoldPan = SlimefunItems.NETHER_GOLD_PAN.getItem(GoldPan.class); - private final ItemStack gravel = new ItemStack(Material.GRAVEL); - private final ItemStack soulSand = new ItemStack(Material.SOUL_SAND); - @ParametersAreNonnullByDefault public ElectricGoldPan(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(itemGroup, item, recipeType, recipe); @@ -50,21 +47,21 @@ public class ElectricGoldPan extends AContainer implements RecipeDisplayItem { } /** - * This returns whether the {@link ElectricGoldPan} will stop proccessing inputs + * This returns whether the {@link ElectricGoldPan} will stop processing inputs * if both output slots contain items or if that default behavior should be - * overriden and allow the {@link ElectricGoldPan} to continue processing inputs + * overridden and allow the {@link ElectricGoldPan} to continue processing inputs * even if both output slots are occupied. Note this option will allow players * to force specific outputs from the {@link ElectricGoldPan} but can be * necessary when a server has disabled cargo networks. * - * @return If output limits are overriden + * @return If output limits are overridden */ - public boolean isOutputLimitOverriden() { + public boolean isOutputLimitOverridden() { return overrideOutputLimit.getValue(); } @Override - public List getDisplayRecipes() { + public @Nonnull List getDisplayRecipes() { List recipes = new ArrayList<>(); recipes.addAll(goldPan.getDisplayRecipes()); @@ -80,30 +77,24 @@ public class ElectricGoldPan extends AContainer implements RecipeDisplayItem { @Override protected MachineRecipe findNextRecipe(BlockMenu menu) { - if (!isOutputLimitOverriden() && !hasFreeSlot(menu)) { + if (!isOutputLimitOverridden() && !hasFreeSlot(menu)) { return null; } for (int slot : getInputSlots()) { ItemStack item = menu.getItemInSlot(slot); + ItemStack output = null; - if (SlimefunUtils.isItemSimilar(item, gravel, true, false)) { - ItemStack output = goldPan.getRandomOutput(); - MachineRecipe recipe = new MachineRecipe(3 / getSpeed(), new ItemStack[] { gravel }, new ItemStack[] { output }); - - if (output.getType() != Material.AIR && menu.fits(output, getOutputSlots())) { - menu.consumeItem(slot); - return recipe; - } - } else if (SlimefunUtils.isItemSimilar(item, soulSand, true, false)) { - ItemStack output = netherGoldPan.getRandomOutput(); - MachineRecipe recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { soulSand }, new ItemStack[] { output }); - - if (output.getType() != Material.AIR && menu.fits(output, getOutputSlots())) { - menu.consumeItem(slot); - return recipe; - } + if (goldPan.isValidInput(item)) { + output = goldPan.getRandomOutput(); + } else if (netherGoldPan.isValidInput(item)) { + output = netherGoldPan.getRandomOutput(); + } + if (output != null && output.getType() != Material.AIR && menu.fits(output, getOutputSlots())) { + MachineRecipe recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { item }, new ItemStack[] { output }); + menu.consumeItem(slot); + return recipe; } } @@ -121,7 +112,7 @@ public class ElectricGoldPan extends AContainer implements RecipeDisplayItem { } @Override - public String getMachineIdentifier() { + public @Nonnull String getMachineIdentifier() { return "ELECTRIC_GOLD_PAN"; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AutomatedPanningMachine.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AutomatedPanningMachine.java index e58bba3b9..c5e407404 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AutomatedPanningMachine.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AutomatedPanningMachine.java @@ -27,7 +27,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.OutputChest; import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GoldPan; import io.github.thebusybiscuit.slimefun4.implementation.items.tools.NetherGoldPan; -import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; /** * The {@link AutomatedPanningMachine} is a {@link MultiBlockMachine} that @@ -35,9 +34,10 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; * * @author TheBusyBiscuit * @author Liruxo + * @author svr333 + * @author JustAHuman * * @see GoldPan - * */ public class AutomatedPanningMachine extends MultiBlockMachine { @@ -62,38 +62,41 @@ public class AutomatedPanningMachine extends MultiBlockMachine { @Override public void onInteract(Player p, Block b) { ItemStack input = p.getInventory().getItemInMainHand(); + Material material = input.getType(); + ItemStack output; - if (SlimefunUtils.isItemSimilar(input, new ItemStack(Material.GRAVEL), true, false) || SlimefunUtils.isItemSimilar(input, new ItemStack(Material.SOUL_SAND), true, false)) { - Material material = input.getType(); - - if (p.getGameMode() != GameMode.CREATIVE) { - ItemUtils.consumeItem(input, false); - } - - ItemStack output = material == Material.GRAVEL ? goldPan.getRandomOutput() : netherGoldPan.getRandomOutput(); - TaskQueue queue = new TaskQueue(); - - queue.thenRepeatEvery(20, 5, () -> b.getWorld().playEffect(b.getRelative(BlockFace.DOWN).getLocation(), Effect.STEP_SOUND, material)); - - queue.thenRun(20, () -> { - if (output.getType() != Material.AIR) { - Optional outputChest = OutputChest.findOutputChestFor(b.getRelative(BlockFace.DOWN), output); - - if (outputChest.isPresent()) { - outputChest.get().addItem(output.clone()); - } else { - b.getWorld().dropItemNaturally(b.getLocation(), output.clone()); - } - - SoundEffect.AUTOMATED_PANNING_MACHINE_SUCCESS_SOUND.playAt(b); - } else { - SoundEffect.AUTOMATED_PANNING_MACHINE_FAIL_SOUND.playAt(b); - } - }); - - queue.execute(Slimefun.instance()); + if (goldPan.isValidInputMaterial(material)) { + output = goldPan.getRandomOutput(); + } else if (netherGoldPan.isValidInputMaterial(material)) { + output = netherGoldPan.getRandomOutput(); } else { Slimefun.getLocalization().sendMessage(p, "machines.wrong-item", true); + return; } + + if (p.getGameMode() != GameMode.CREATIVE) { + ItemUtils.consumeItem(input, false); + } + + TaskQueue queue = new TaskQueue(); + + queue.thenRepeatEvery(20, 5, () -> b.getWorld().playEffect(b.getRelative(BlockFace.DOWN).getLocation(), Effect.STEP_SOUND, material)); + queue.thenRun(20, () -> { + if (output.getType() != Material.AIR) { + Optional outputChest = OutputChest.findOutputChestFor(b.getRelative(BlockFace.DOWN), output); + + if (outputChest.isPresent()) { + outputChest.get().addItem(output.clone()); + } else { + b.getWorld().dropItemNaturally(b.getLocation(), output.clone()); + } + + SoundEffect.AUTOMATED_PANNING_MACHINE_SUCCESS_SOUND.playAt(b); + } else { + SoundEffect.AUTOMATED_PANNING_MACHINE_FAIL_SOUND.playAt(b); + } + }); + + queue.execute(Slimefun.instance()); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java index c96f6a4bc..42136767b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java @@ -1,7 +1,9 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.Set; @@ -38,15 +40,17 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; * resources from Gravel. * * @author TheBusyBiscuit + * @author svr333 + * @author JustAHuman * * @see NetherGoldPan * @see AutomatedPanningMachine * @see ElectricGoldPan - * */ public class GoldPan extends SimpleSlimefunItem implements RecipeDisplayItem { private final RandomizedSet randomizer = new RandomizedSet<>(); + private final Set inputMaterials = new HashSet<>(Arrays.asList(Material.GRAVEL)); private final Set drops = new HashSet<>(); @ParametersAreNonnullByDefault @@ -59,12 +63,12 @@ public class GoldPan extends SimpleSlimefunItem implements Recip } /** - * This method returns the target {@link Material} for this {@link GoldPan}. + * This method returns the target {@link Material Materials} for this {@link GoldPan}. * - * @return The {@link Material} this {@link GoldPan} can be used on + * @return The {@link Set} of {@link Material Materials} this {@link GoldPan} can be used on */ - public @Nonnull Material getInputMaterial() { - return Material.GRAVEL; + public @Nonnull Set getInputMaterials() { + return Collections.unmodifiableSet(inputMaterials); } protected @Nonnull Set getGoldPanDrops() { @@ -86,7 +90,7 @@ public class GoldPan extends SimpleSlimefunItem implements Recip /** * Do not call this method directly. - * + *

* This method is for internal purposes only. * It will update and re-calculate all weights in our {@link RandomizedSet}. */ @@ -127,7 +131,7 @@ public class GoldPan extends SimpleSlimefunItem implements Recip Block b = block.get(); // Check the clicked block type and for protections - if (b.getType() == getInputMaterial() && Slimefun.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), Interaction.BREAK_BLOCK)) { + if (isValidInputMaterial(b.getType()) && Slimefun.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), Interaction.BREAK_BLOCK)) { ItemStack output = getRandomOutput(); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); @@ -160,11 +164,15 @@ public class GoldPan extends SimpleSlimefunItem implements Recip @Override public @Nonnull List getDisplayRecipes() { - List recipes = new LinkedList<>(); + List recipes = new ArrayList<>(); for (GoldPanDrop drop : drops) { - if (drop.getValue() > 0) { - recipes.add(new ItemStack(getInputMaterial())); + if (drop.getValue() <= 0) { + continue; + } + + for (Material inputMaterial : getInputMaterials()) { + recipes.add(new ItemStack(inputMaterial)); recipes.add(drop.getOutput()); } } @@ -172,4 +180,13 @@ public class GoldPan extends SimpleSlimefunItem implements Recip return recipes; } + public boolean isValidInput(ItemStack input) { + Material inputMaterial = input.getType(); + return isValidInputMaterial(inputMaterial) && SlimefunUtils.isItemSimilar(input, new ItemStack(inputMaterial), true, false); + } + + public boolean isValidInputMaterial(Material material) { + return getInputMaterials().contains(material); + } + } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/NetherGoldPan.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/NetherGoldPan.java index c4a815528..60de84cd9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/NetherGoldPan.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/NetherGoldPan.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -19,18 +20,21 @@ import io.github.thebusybiscuit.slimefun4.implementation.settings.GoldPanDrop; * which can be used on Soul Sand. * * @author TheBusyBiscuit - * + * @author svr333 + * @author JustAHuman */ public class NetherGoldPan extends GoldPan { + private final Set inputMaterials = new HashSet<>(Arrays.asList(Material.SOUL_SAND, Material.SOUL_SOIL)); + @ParametersAreNonnullByDefault public NetherGoldPan(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(itemGroup, item, recipeType, recipe); } @Override - public @Nonnull Material getInputMaterial() { - return Material.SOUL_SAND; + public @Nonnull Set getInputMaterials() { + return inputMaterials; } @Override