From 4f6bbafdfc6dfa19ce617ff1f95273e9d1c8b543 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Wed, 24 Jun 2020 21:24:16 +0300 Subject: [PATCH 1/5] Added Auto Brewer. A new medium machine that can create potions automatically. --- .../implementation/SlimefunItems.java | 3 + .../items/electric/machines/AutoBrewer.java | 192 ++++++++++++++++++ .../implementation/setup/ResearchSetup.java | 1 + .../setup/SlimefunItemSetup.java | 5 + .../resources/languages/researches_en.yml | 3 +- 5 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java index 6131fd18a..7b7bd18c1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java @@ -624,6 +624,7 @@ public final class SlimefunItems { public static final SlimefunItemStack AUTO_DISENCHANTER = new SlimefunItemStack("AUTO_DISENCHANTER", Material.ENCHANTING_TABLE, "&5Auto Disenchanter", "", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(18)); public static final SlimefunItemStack AUTO_ANVIL = new SlimefunItemStack("AUTO_ANVIL", Material.IRON_BLOCK, "&7Auto Anvil", "", LoreBuilder.machine(MachineTier.ADVANCED, MachineType.MACHINE), "&8\u21E8 &7Repair Factor: 10%", LoreBuilder.powerPerSecond(24)); public static final SlimefunItemStack AUTO_ANVIL_2 = new SlimefunItemStack("AUTO_ANVIL_2", Material.IRON_BLOCK, "&7Auto Anvil Mk.II", "", LoreBuilder.machine(MachineTier.END_GAME, MachineType.MACHINE), "&8\u21E8 &7Repair Factor: 25%", LoreBuilder.powerPerSecond(32)); + public static final SlimefunItemStack AUTO_BREWER; public static final SlimefunItemStack BIO_REACTOR = new SlimefunItemStack("BIO_REACTOR", Material.LIME_TERRACOTTA, "&2Bio Reactor", "", LoreBuilder.machine(MachineTier.AVERAGE, MachineType.GENERATOR), LoreBuilder.powerBuffer(128), LoreBuilder.powerPerSecond(8)); public static final SlimefunItemStack MULTIMETER = new SlimefunItemStack("MULTIMETER", Material.CLOCK, "&eMultimeter", "", "&rMeasures the Amount of stored", "&rEnergy in a Block"); @@ -799,11 +800,13 @@ public final class SlimefunItems { TABLE_SAW = new SlimefunItemStack("TABLE_SAW", Material.STONECUTTER, "&6Table Saw", "", "&aAllows you to get 8 planks from 1 Log", "&a(Works with all log types)"); MAKESHIFT_SMELTERY = new SlimefunItemStack("MAKESHIFT_SMELTERY", Material.BLAST_FURNACE, "&eMakeshift Smeltery", "", "&rImprovised version of the Smeltery", "&rthat only allows you to", "&rsmelt dusts into ingots"); AUTO_DRIER = new SlimefunItemStack("AUTO_DRIER", Material.SMOKER, "&eAuto Drier", "", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(10)); + AUTO_BREWER = new SlimefunItemStack("AUTO_BREWER", Material.SMOKER, "&eAuto Brewer", "", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(12)); } else { TABLE_SAW = null; MAKESHIFT_SMELTERY = new SlimefunItemStack("MAKESHIFT_SMELTERY", Material.FURNACE, "&eMakeshift Smeltery", "", "&rImprovised version of the Smeltery", "&rthat only allows you to", "&rsmelt dusts into ingots"); AUTO_DRIER = null; + AUTO_BREWER = new SlimefunItemStack("AUTO_BREWER", Material.BREWING_STAND, "&eAuto Brewer", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(12)); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java new file mode 100644 index 000000000..343c5306f --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java @@ -0,0 +1,192 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; + +import java.util.HashMap; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.PotionData; +import org.bukkit.potion.PotionType; + +import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; +import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; +import me.mrCookieSlime.Slimefun.api.BlockStorage; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; + +public class AutoBrewer extends AContainer { + + private static final HashMap potionRecipes = new HashMap<>(); + private static final HashMap fermSpiderEye = new HashMap<>(); + + static { + potionRecipes.put(Material.SUGAR, PotionType.SPEED); + potionRecipes.put(Material.RABBIT_FOOT, PotionType.JUMP); + potionRecipes.put(Material.BLAZE_POWDER, PotionType.STRENGTH); + potionRecipes.put(Material.GLISTERING_MELON_SLICE, PotionType.INSTANT_HEAL); + potionRecipes.put(Material.SPIDER_EYE, PotionType.POISON); + potionRecipes.put(Material.GHAST_TEAR, PotionType.REGEN); + potionRecipes.put(Material.MAGMA_CREAM, PotionType.FIRE_RESISTANCE); + potionRecipes.put(Material.PUFFERFISH, PotionType.WATER_BREATHING); + potionRecipes.put(Material.GOLDEN_CARROT, PotionType.NIGHT_VISION); + potionRecipes.put(Material.TURTLE_HELMET, PotionType.TURTLE_MASTER); + potionRecipes.put(Material.PHANTOM_MEMBRANE, PotionType.SLOW_FALLING); + + fermSpiderEye.put(PotionType.SPEED, PotionType.SLOWNESS); + fermSpiderEye.put(PotionType.JUMP, PotionType.SLOWNESS); + fermSpiderEye.put(PotionType.INSTANT_HEAL, PotionType.INSTANT_DAMAGE); + fermSpiderEye.put(PotionType.POISON, PotionType.INSTANT_DAMAGE); + fermSpiderEye.put(PotionType.NIGHT_VISION, PotionType.INVISIBILITY); + } + + public AutoBrewer(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + super(category, item, recipeType, recipe); + } + + @Override + protected void tick(Block b) { + BlockMenu menu = BlockStorage.getInventory(b.getLocation()); + + if (isProcessing(b)) { + int timeleft = progress.get(b); + + if (timeleft > 0) { + ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); + + if (ChargableBlock.isChargable(b)) { + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; + } + + ChargableBlock.addCharge(b, -getEnergyConsumption()); + progress.put(b, timeleft - 1); + } + else { + progress.put(b, timeleft - 1); + } + } + else { + menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + + for (ItemStack item : processing.get(b).getOutput()) { + menu.pushItem(item, getOutputSlots()); + } + + progress.remove(b); + processing.remove(b); + } + } + else { + MachineRecipe recipe = findRecipe(menu); + + if (recipe != null) { + if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) { + return; + } + + for (int slot : getInputSlots()) { + menu.consumeItem(slot); + } + + processing.put(b, recipe); + progress.put(b, recipe.getTicks()); + } + } + } + + private MachineRecipe findRecipe(BlockMenu menu) { + ItemStack input1 = menu.getItemInSlot(getInputSlots()[0]); + ItemStack input2 = menu.getItemInSlot(getInputSlots()[1]); + + if (input1 == null || input2 == null) return null; + + if (input1.getType().name().endsWith("POTION") || input2.getType().name().endsWith("POTION")) { + boolean slot = input1.getType().name().endsWith("POTION"); + ItemStack pItem = slot ? input1 : input2; + ItemStack iItem = slot ? input2 : input1; + + PotionMeta potion = (PotionMeta) pItem.getItemMeta(); + if (potion == null) return null; + PotionData potionData = potion.getBasePotionData(); + + ItemStack output; + if (potionData.getType() == PotionType.WATER) { + if (iItem.getType() == Material.FERMENTED_SPIDER_EYE) { + potion.setBasePotionData(new PotionData(PotionType.WEAKNESS, false, false)); + output = new ItemStack(pItem.getType()); + + } else if (iItem.getType() == Material.NETHER_WART) { + potion.setBasePotionData(new PotionData(PotionType.AWKWARD, false, false)); + output = new ItemStack(pItem.getType()); + + } else if (pItem.getType() == Material.POTION && iItem.getType() == Material.GUNPOWDER) { + output = new ItemStack(Material.SPLASH_POTION); + + } else if (pItem.getType() == Material.SPLASH_POTION && iItem.getType() == Material.DRAGON_BREATH) { + output = new ItemStack(Material.LINGERING_POTION); + + } else return null; + + } else { + if (iItem.getType() == Material.FERMENTED_SPIDER_EYE) { + potion.setBasePotionData(new PotionData(fermSpiderEye.get(potionData.getType()), false, false)); + output = new ItemStack(pItem.getType()); + + } else if (iItem.getType() == Material.REDSTONE) { + potion.setBasePotionData(new PotionData(potionData.getType(), true, potionData.isUpgraded())); + output = new ItemStack(pItem.getType()); + + } else if (iItem.getType() == Material.GLOWSTONE_DUST) { + potion.setBasePotionData(new PotionData(potionData.getType(), potionData.isExtended(), true)); + output = new ItemStack(pItem.getType()); + + } else if (potionData.getType() == PotionType.AWKWARD && potionRecipes.containsKey(iItem.getType())) { + potion.setBasePotionData(new PotionData(potionRecipes.get(iItem.getType()), false, false)); + output = new ItemStack(pItem.getType()); + + } else return null; + } + + output.setItemMeta(potion); + + return new MachineRecipe(30, new ItemStack[]{input1, input2}, new ItemStack[]{output}); + } else return null; + } + + @Override + public String getInventoryTitle() { + return "&6Auto-Brewer"; + } + + @Override + public ItemStack getProgressBar() { + return new ItemStack(Material.CARROT_ON_A_STICK); + } + + @Override + public int getEnergyConsumption() { + return 6; + } + + @Override + public int getSpeed() { + return 1; + } + + @Override + public String getMachineIdentifier() { + return "AUTO_BREWER"; + } + + @Override + public int getCapacity() { + return 128; + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java index a35f46fdb..acdf63880 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java @@ -266,6 +266,7 @@ public final class ResearchSetup { register("industrial_miner", 95, "Industrial Mining", 28, SlimefunItems.INDUSTRIAL_MINER); register("advanced_industrial_miner", 98, "Better Mining", 36, SlimefunItems.ADVANCED_INDUSTRIAL_MINER); register("magic_pills", 257, "De-Zombification", 22, SlimefunItems.MAGIC_PILLS); + register("auto_brewer", 258, "Industrial Brewery", 30, SlimefunItems.AUTO_BREWER); } private static void register(String key, int id, String name, int defaultCost, ItemStack... items) { 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 1579b5dc5..fe0f5c774 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 @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.setup; import java.util.ArrayList; import java.util.List; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoBrewer; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -1972,6 +1973,10 @@ public final class SlimefunItemSetup { .register(plugin); } + new AutoBrewer(categories.electricity, SlimefunItems.AUTO_BREWER, RecipeType.ENHANCED_CRAFTING_TABLE, + new ItemStack[] {null, SlimefunItems.HEATING_COIL, null, SlimefunItems.REINFORCED_PLATE, new ItemStack(Material.BREWING_STAND), SlimefunItems.REINFORCED_PLATE, null, SlimefunItems.ELECTRIC_MOTOR, null}) + .register(plugin); + new ElectricPress(categories.electricity, SlimefunItems.ELECTRIC_PRESS, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {new ItemStack(Material.PISTON), SlimefunItems.ELECTRIC_MOTOR, new ItemStack(Material.PISTON), null, SlimefunItems.MEDIUM_CAPACITOR, null, SlimefunItems.DAMASCUS_STEEL_INGOT, SlimefunItems.DAMASCUS_STEEL_INGOT, SlimefunItems.DAMASCUS_STEEL_INGOT}) { diff --git a/src/main/resources/languages/researches_en.yml b/src/main/resources/languages/researches_en.yml index 744c95ffd..26ea77c7f 100644 --- a/src/main/resources/languages/researches_en.yml +++ b/src/main/resources/languages/researches_en.yml @@ -233,4 +233,5 @@ slimefun: tree_growth_accelerator: Faster Trees industrial_miner: Industrial Mining advanced_industrial_miner: Better Mining - magic_pills: De-Zombification \ No newline at end of file + magic_pills: De-Zombification + auto_brewer: Industrial Brewery \ No newline at end of file From daadabd535cd03edf21435f39b5cf3a6d88ca623 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Wed, 24 Jun 2020 21:25:42 +0300 Subject: [PATCH 2/5] Fixed an import dis-organisation. --- .../slimefun4/implementation/setup/SlimefunItemSetup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fe0f5c774..245307a44 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 @@ -3,7 +3,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.setup; import java.util.ArrayList; import java.util.List; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoBrewer; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -72,6 +71,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.electric.generato import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AnimalGrowthAccelerator; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoAnvil; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoBreeder; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoBrewer; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoDisenchanter; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoDrier; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoEnchanter; From 776dc2a302c2d6c7608e3ed4e98edb58158e0515 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Wed, 24 Jun 2020 22:17:01 +0300 Subject: [PATCH 3/5] Added some documentation. --- .../items/electric/machines/AutoBrewer.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java index 343c5306f..6d9ec31e3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java @@ -21,6 +21,15 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; +/** + * + * The Auto Brewer machine with most if not all potion recipes. + * + * @author Linox + * + * @see AContainer + * + */ public class AutoBrewer extends AContainer { private static final HashMap potionRecipes = new HashMap<>(); From 4249a2b85bcdcd1ad3d2368a84cfb037bae2a65f Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Wed, 24 Jun 2020 22:33:55 +0300 Subject: [PATCH 4/5] Did the requested changes. --- .../items/electric/machines/AutoBrewer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java index 6d9ec31e3..6ba3f4379 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java @@ -116,8 +116,8 @@ public class AutoBrewer extends AContainer { if (input1 == null || input2 == null) return null; - if (input1.getType().name().endsWith("POTION") || input2.getType().name().endsWith("POTION")) { - boolean slot = input1.getType().name().endsWith("POTION"); + if (isPotion(input1.getType()) || isPotion(input2.getType())) { + boolean slot = isPotion(input1.getType()); ItemStack pItem = slot ? input1 : input2; ItemStack iItem = slot ? input2 : input1; @@ -169,6 +169,10 @@ public class AutoBrewer extends AContainer { } else return null; } + private boolean isPotion(Material mat) { + return mat == Material.POTION || mat == Material.SPLASH_POTION || mat == Material.LINGERING_POTION; + } + @Override public String getInventoryTitle() { return "&6Auto-Brewer"; From 3cba1f71fcfedb8d60185268cfdbf1e8442ac4f3 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Wed, 24 Jun 2020 22:46:02 +0300 Subject: [PATCH 5/5] Fixed an issue created by another pr. --- .../slimefun4/implementation/setup/ResearchSetup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java index ac5d451a2..93e44701d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java @@ -265,7 +265,7 @@ public final class ResearchSetup { register("tree_growth_accelerator", 256, "Faster Trees", 18, SlimefunItems.TREE_GROWTH_ACCELERATOR); register("industrial_miner", 95, "Industrial Mining", 28, SlimefunItems.INDUSTRIAL_MINER); register("advanced_industrial_miner", 98, "Better Mining", 36, SlimefunItems.ADVANCED_INDUSTRIAL_MINER); - register("magical_zombie_pills", 257, "De-Zombification", 22, SlimefunItems.MAGIC_PILLS); + register("magical_zombie_pills", 257, "De-Zombification", 22, SlimefunItems.MAGICAL_ZOMBIE_PILLS); register("auto_brewer", 258, "Industrial Brewery", 30, SlimefunItems.AUTO_BREWER); }