From 32c60ad5ac6387f4d4f959b388df3c8f95c4c1fb Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Wed, 31 Mar 2021 18:29:43 +0200 Subject: [PATCH] [CI skip] Refactoring --- .../machines/AutomatedCraftingChamber.java | 4 +-- .../items/electric/machines/FluidPump.java | 17 ++++++----- .../machines/entities/AnimalProduce.java | 2 +- .../machines/entities/ProduceCollector.java | 30 ++++++++++++------- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutomatedCraftingChamber.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutomatedCraftingChamber.java index 5e99f218b..2008e0871 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutomatedCraftingChamber.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutomatedCraftingChamber.java @@ -37,15 +37,13 @@ import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu; import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; /** - * This class needs to be rewritten VERY BADLY. - * But we should focus on rewriting the recipe system first. + * This machine is disabled and has been replaced by Auto Crafters. * * @deprecated This has been replaced by the {@link AbstractAutoCrafter}. * * @author TheBusyBiscuit * */ -@Deprecated public abstract class AutomatedCraftingChamber extends SlimefunItem implements InventoryBlock, EnergyNetComponent { private final int[] border = { 0, 1, 3, 4, 5, 7, 8, 13, 14, 15, 16, 17, 50, 51, 52, 53 }; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java index aa6f67e54..7d44e99e7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java @@ -186,13 +186,15 @@ public class FluidPump extends SimpleSlimefunItem implements Invent @Nonnull private ItemStack getFilledBucket(@Nonnull Block fluid) { - if (fluid.getType() == Material.LAVA) { - return new ItemStack(Material.LAVA_BUCKET); - } else if (fluid.getType() == Material.WATER || fluid.getType() == Material.BUBBLE_COLUMN) { - return new ItemStack(Material.WATER_BUCKET); - } else { - // Fallback for any new liquids - return new ItemStack(Material.BUCKET); + switch (fluid.getType()) { + case LAVA: + return new ItemStack(Material.LAVA_BUCKET); + case WATER: + case BUBBLE_COLUMN: + return new ItemStack(Material.WATER_BUCKET); + default: + // Fallback for any new liquids + return new ItemStack(Material.BUCKET); } } @@ -214,6 +216,7 @@ public class FluidPump extends SimpleSlimefunItem implements Invent return levelled.getLevel() == 0; } } + return false; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AnimalProduce.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AnimalProduce.java index 7160f6448..ed4e2c381 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AnimalProduce.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AnimalProduce.java @@ -24,7 +24,7 @@ public class AnimalProduce extends MachineRecipe implements Predicate predicate; @ParametersAreNonnullByDefault - public AnimalProduce(ItemStack input, Predicate predicate, ItemStack result) { + public AnimalProduce(ItemStack input, ItemStack result, Predicate predicate) { super(5, new ItemStack[] { input }, new ItemStack[] { result }); Validate.notNull(predicate, "The Predicate must not be null"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java index d31980ed8..82bf8d40a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java @@ -12,7 +12,6 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.entity.Ageable; import org.bukkit.entity.Cow; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -44,9 +43,8 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; */ public class ProduceCollector extends AContainer implements RecipeDisplayItem { - private final Set animalProduces = new HashSet<>(); - private final ItemSetting range = new IntRangeSetting(this, "range", 1, 2, 32); + private final Set animalProduces = new HashSet<>(); @ParametersAreNonnullByDefault public ProduceCollector(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { @@ -57,8 +55,23 @@ public class ProduceCollector extends AContainer implements RecipeDisplayItem { @Override protected void registerDefaultRecipes() { - addProduce(new AnimalProduce(new ItemStack(Material.BUCKET), Cow.class::isInstance, new ItemStack(Material.MILK_BUCKET))); - addProduce(new AnimalProduce(new ItemStack(Material.BOWL), MushroomCow.class::isInstance, new ItemStack(Material.MUSHROOM_STEW))); + // Milk from adult cows + addProduce(new AnimalProduce(new ItemStack(Material.BUCKET), new ItemStack(Material.MILK_BUCKET), n -> { + if (n instanceof Cow) { + return ((Cow) n).isAdult(); + } else { + return false; + } + })); + + // Mushroom Stew from Mooshrooms + addProduce(new AnimalProduce(new ItemStack(Material.BOWL), new ItemStack(Material.MUSHROOM_STEW), n -> { + if (n instanceof MushroomCow) { + return ((MushroomCow) n).isAdult(); + } else { + return false; + } + })); } /** @@ -132,12 +145,7 @@ public class ProduceCollector extends AContainer implements RecipeDisplayItem { @ParametersAreNonnullByDefault private boolean isValidAnimal(Entity n, Predicate predicate) { if (n instanceof LivingEntity) { - if (n instanceof Ageable && !((Ageable) n).isAdult()) { - // We only take adults into consideration - return false; - } else { - return predicate.test((LivingEntity) n); - } + return predicate.test((LivingEntity) n); } else { return false; }