From 0faaef9b25396473598b52f654836163aab6cf59 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 1 Jun 2020 14:10:22 +0200 Subject: [PATCH 01/18] Removed Digital Miners --- CHANGELOG.md | 2 + .../implementation/setup/ResearchSetup.java | 2 - .../setup/SlimefunItemSetup.java | 153 ------------------ .../Slimefun/Lists/SlimefunItems.java | 9 +- .../Slimefun/api/SlimefunItemStack.java | 2 +- 5 files changed, 4 insertions(+), 164 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c8f5940b..c2ef62b66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ #### Changes * Fixed a few memory leaks +* Removed Digital Miner +* Removed Advanced Digital Miner #### Fixes * Fixed Ore Washer recipes showing up twice 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 20da9c68e..76fa4ceaf 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 @@ -117,10 +117,8 @@ public final class ResearchSetup { register("table_saw", 92, "Table Saw", 4, SlimefunItems.TABLE_SAW); register("slime_steel_armor", 93, "Slimy Steel Armor", 27, SlimefunItems.SLIME_HELMET_STEEL, SlimefunItems.SLIME_CHESTPLATE_STEEL, SlimefunItems.SLIME_LEGGINGS_STEEL, SlimefunItems.SLIME_BOOTS_STEEL); register("blade_of_vampires", 94, "Blade of Vampires", 26, SlimefunItems.BLADE_OF_VAMPIRES); - register("digital_miner", 95, "Lazy Mining", 40, SlimefunItems.DIGITAL_MINER); register("water_staff", 96, "Water Staff", 8, SlimefunItems.STAFF_WATER); register("24k_gold_block", 97, "Golden City", 19, SlimefunItems.GOLD_24K_BLOCK); - register("advanced_digital_miner", 98, "Advanced Mining 101", 42, SlimefunItems.ADVANCED_DIGITAL_MINER); register("composter", 99, "Composting Dirt", 3, SlimefunItems.COMPOSTER); register("farmer_shoes", 100, "Farmer Shoes", 4, SlimefunItems.FARMER_SHOES); register("explosive_tools", 101, "Explosive Tools", 30, SlimefunItems.EXPLOSIVE_PICKAXE, SlimefunItems.EXPLOSIVE_SHOVEL); 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 dbb7e8eef..22a2021fa 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,28 +3,16 @@ package io.github.thebusybiscuit.slimefun4.implementation.setup; import java.util.ArrayList; import java.util.List; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Effect; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.Chest; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; -import io.github.thebusybiscuit.slimefun4.core.MultiBlock; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactivity; import io.github.thebusybiscuit.slimefun4.implementation.items.RadioactiveItem; import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; @@ -176,17 +164,12 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAx import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SwordOfBeheading; import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; -import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunMachine; -import me.mrCookieSlime.Slimefun.Objects.handlers.MultiBlockInteractionHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.RainbowTicker; -import me.mrCookieSlime.Slimefun.api.BlockStorage; -import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** @@ -1017,142 +1000,6 @@ public final class SlimefunItemSetup { new ItemStack[] {null, new ItemStack(Material.WITHER_SKELETON_SKULL), null, null, new ItemStack(Material.WITHER_SKELETON_SKULL), null, null, new ItemStack(Material.BLAZE_ROD), null}) .register(plugin); - SlimefunMachine miner = new SlimefunMachine(categories.basicMachines, SlimefunItems.DIGITAL_MINER, "DIGITAL_MINER", - new ItemStack[] {SlimefunItems.SOLAR_PANEL, new ItemStack(Material.CHEST), SlimefunItems.SOLAR_PANEL, new ItemStack(Material.IRON_BLOCK), new ItemStack(Material.DISPENSER), new ItemStack(Material.IRON_BLOCK), new ItemStack(Material.IRON_BLOCK), new ItemStack(Material.HOPPER), new ItemStack(Material.IRON_BLOCK)}, - BlockFace.SELF); - miner.addItemHandler(new MultiBlockInteractionHandler() { - - @Override - public boolean onInteract(Player p, MultiBlock mb, Block b) { - if (mb.equals(((SlimefunMachine) SlimefunItem.getByID("DIGITAL_MINER")).getMultiBlock())) { - p.sendMessage(ChatColor.DARK_RED + "THIS MACHINE WILL SOON BE REMOVED!"); - if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true) && Slimefun.hasUnlocked(p, SlimefunItems.DIGITAL_MINER, true)) { - Block chestBlock = b.getRelative(BlockFace.UP); - - if(!(BlockStorage.check(chestBlock.getRelative(BlockFace.WEST), "SOLAR_PANEL") && BlockStorage.check(chestBlock.getRelative(BlockFace.EAST), "SOLAR_PANEL")) && - !(BlockStorage.check(chestBlock.getRelative(BlockFace.NORTH), "SOLAR_PANEL") && BlockStorage.check(chestBlock.getRelative(BlockFace.SOUTH), "SOLAR_PANEL"))) { - return false; - } - - Chest chest = (Chest) chestBlock.getState(); - Inventory inv = chest.getInventory(); - List ores = new ArrayList<>(); - - for (int x = b.getX() - 4; x <= b.getX() + 4; x++) { - for (int z = b.getZ() - 4; z <= b.getZ() + 4; z++) { - for (int y = b.getY(); y > 0; y--) { - if (b.getWorld().getBlockAt(x, y, z).getType().toString().endsWith("_ORE")) { - ores.add(b.getWorld().getBlockAt(x, y, z).getLocation()); - } - } - } - } - if (!ores.isEmpty()) { - Material ore = ores.get(0).getBlock().getType(); - ItemStack adding = new ItemStack(ore); - ores.get(0).getBlock().setType(Material.AIR); - ores.clear(); - if (InvUtils.fits(inv, adding)) { - for (int i = 0; i < 4; i++) { - int j = i; - Bukkit.getScheduler().runTaskLater(SlimefunPlugin.instance, () -> { - if (j < 3) { - b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, ore); - } - else { - p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F); - inv.addItem(adding); - } - }, i*20L); - } - } - else SlimefunPlugin.getLocal().sendMessage(p, "machines.full-inventory", true); - } - else SlimefunPlugin.getLocal().sendMessage(p, "miner.no-ores", true); - } - return true; - } - else return false; - } - }); - miner.register(plugin); - - SlimefunMachine advancedMiner = new SlimefunMachine(categories.basicMachines, SlimefunItems.ADVANCED_DIGITAL_MINER, "ADVANCED_DIGITAL_MINER", - new ItemStack[] {SlimefunItems.SOLAR_PANEL, new ItemStack(Material.CHEST), SlimefunItems.SOLAR_PANEL, SlimefunItems.GOLD_24K_BLOCK, new ItemStack(Material.DISPENSER), SlimefunItems.GOLD_24K_BLOCK, SlimefunItems.GOLD_24K_BLOCK, new ItemStack(Material.HOPPER), SlimefunItems.GOLD_24K_BLOCK}, - BlockFace.SELF); - advancedMiner.addItemHandler(new MultiBlockInteractionHandler() { - // Determines the drops an Advanced Digital Miner will get - private final ItemStack effectivePickaxe = new ItemStack(Material.DIAMOND_PICKAXE); - - @Override - public boolean onInteract(Player p, MultiBlock mb, Block b) { - if (mb.equals(((SlimefunMachine) SlimefunItem.getByID("ADVANCED_DIGITAL_MINER")).getMultiBlock())) { - p.sendMessage(ChatColor.DARK_RED + "THIS MACHINE WILL SOON BE REMOVED!"); - if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true) && Slimefun.hasUnlocked(p, SlimefunItems.ADVANCED_DIGITAL_MINER, true)) { - Block chestBlock = b.getRelative(BlockFace.UP); - - if(!(BlockStorage.check(chestBlock.getRelative(BlockFace.WEST), "SOLAR_PANEL") && BlockStorage.check(chestBlock.getRelative(BlockFace.EAST), "SOLAR_PANEL")) && - !(BlockStorage.check(chestBlock.getRelative(BlockFace.NORTH), "SOLAR_PANEL") && BlockStorage.check(chestBlock.getRelative(BlockFace.SOUTH), "SOLAR_PANEL"))) { - return false; - } - - Chest chest = (Chest) chestBlock.getState(); - Inventory inv = chest.getInventory(); - List ores = new ArrayList<>(); - - for (int x = b.getX() - 6; x <= b.getX() + 6; x++) { - for (int z = b.getZ() - 6; z <= b.getZ() + 6; z++) { - for (int y = b.getY(); y > 0; y--) { - if (b.getWorld().getBlockAt(x, y, z).getType().toString().endsWith("_ORE")) { - ores.add(b.getWorld().getBlockAt(x, y, z).getLocation()); - } - } - } - } - if (!ores.isEmpty()) { - Material ore = ores.get(0).getBlock().getType(); - ItemStack drop = new ItemStack(ore); - - if (ore == Material.COAL_ORE) drop = new ItemStack(Material.COAL, 4); - else if (ore == Material.IRON_ORE) drop = new CustomItem(SlimefunItems.IRON_DUST, 2); - else if (ore == Material.GOLD_ORE) drop = new CustomItem(SlimefunItems.GOLD_DUST, 2); - else if (ore == Material.REDSTONE_ORE) drop = new ItemStack(Material.REDSTONE, 8); - else if (ore == Material.NETHER_QUARTZ_ORE) drop = new ItemStack(Material.QUARTZ, 4); - else if (ore == Material.LAPIS_ORE) drop = new ItemStack(Material.LAPIS_LAZULI, 12); - else { - for (ItemStack drops : ores.get(0).getBlock().getDrops(effectivePickaxe)) { - if (!drops.getType().isBlock()) drop = new CustomItem(drops, 2); - } - } - - final ItemStack adding = drop; - ores.get(0).getBlock().setType(Material.AIR); - ores.clear(); - if (InvUtils.fits(inv, adding)) { - for (int i = 0; i < 4; i++) { - int j = i; - Bukkit.getScheduler().runTaskLater(SlimefunPlugin.instance, () -> { - if (j < 3) { - b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, ore); - } - else { - p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F); - inv.addItem(adding); - } - }, i*20L); - } - } - else SlimefunPlugin.getLocal().sendMessage(p, "machines.full-inventory", true); - } - else SlimefunPlugin.getLocal().sendMessage(p, "miner.no-ores", true); - } - return true; - } - else return false; - } - }); - advancedMiner.register(plugin); - new SlimefunItem(categories.misc, (SlimefunItemStack) SlimefunItems.GOLD_24K_BLOCK, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {SlimefunItems.GOLD_24K, SlimefunItems.GOLD_24K, SlimefunItems.GOLD_24K, SlimefunItems.GOLD_24K, SlimefunItems.GOLD_24K, SlimefunItems.GOLD_24K, SlimefunItems.GOLD_24K, SlimefunItems.GOLD_24K, SlimefunItems.GOLD_24K}) .register(plugin); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index 88da9804c..444ea8059 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -11,7 +11,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.core.attributes.MachineTier; import io.github.thebusybiscuit.slimefun4.core.attributes.MachineType; @@ -531,13 +530,7 @@ public final class SlimefunItems { public static final SlimefunItemStack CRUCIBLE = new SlimefunItemStack("CRUCIBLE", Material.CAULDRON, "&cCrucible", "", "&a&oUsed to smelt Items into Liquids"); public static final SlimefunItemStack JUICER = new SlimefunItemStack("JUICER", Material.GLASS_BOTTLE, "&aJuicer", "", "&aAllows you to create delicious Juice"); - public static final ItemStack SOLAR_PANEL = new SlimefunItemStack("SOLAR_PANEL", Material.DAYLIGHT_DETECTOR, "&bSolar Panel", "", "&a&oTransforms Sunlight to Energy"); - - @Deprecated - public static final ItemStack DIGITAL_MINER = new CustomItem(Material.IRON_PICKAXE, "&bDigital Miner", "", "&4DEPRECATED", "&cThis machine will be removed at some point!", "&cWe don't know when."); - - @Deprecated - public static final ItemStack ADVANCED_DIGITAL_MINER = new CustomItem(Material.DIAMOND_PICKAXE, "&6Advanced Digital Miner", "", "&4DEPRECATED", "&cThis machine will be removed at some point!", "&cWe don't know when."); + public static final SlimefunItemStack SOLAR_PANEL = new SlimefunItemStack("SOLAR_PANEL", Material.DAYLIGHT_DETECTOR, "&bSolar Panel", "", "&a&oTransforms Sunlight to Energy"); public static final SlimefunItemStack AUTOMATED_PANNING_MACHINE = new SlimefunItemStack("AUTOMATED_PANNING_MACHINE", Material.BOWL, "&eAutomated Panning Machine", "", "&rA MultiBlock Version of the Gold Pan", "&rand Nether Gold Pan combined in one machine."); public static final SlimefunItemStack OUTPUT_CHEST = new SlimefunItemStack("OUTPUT_CHEST", Material.CHEST, "&4Output Chest", "", "&c&oA basic machine will try to put", "&c&oitems in this chest if it's placed", "&c&oadjacent to the dispenser."); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java b/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java index 904dd09a2..cbca8b9e0 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java @@ -200,7 +200,7 @@ public class SlimefunItemStack extends CustomItem { @Override public String toString() { - return "SlimefunItemStack (" + id + ')'; + return "SlimefunItemStack (" + id + (getAmount() > 1 ? (" x " + getAmount()) : "") + ')'; } public Optional getSkullTexture() { From 595767ad036861951840ba625b726492004e9d79 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Tue, 2 Jun 2020 13:50:29 +0200 Subject: [PATCH 02/18] Some cleanup --- CHANGELOG.md | 2 ++ .../slimefun4/core/commands/subcommands/GiveCommand.java | 4 +++- .../Objects/handlers/MultiBlockInteractionHandler.java | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2ef62b66..ea1046c1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ * Fixed Nuclear Reactors accepting Lava as coolant ## Release Candidate 12 (27 May 2020) +https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#12 #### Additions * Added Ukrainian translations @@ -81,6 +82,7 @@ * Fixed #1935 ## Release Candidate 11 (25 Apr 2020) +https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#11 #### Additions * Added GEOResourceGenerationEvent diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java index 2ba1bfd3f..25f742ed0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java @@ -10,6 +10,7 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.players.PlayerList; import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; +import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.multiblocks.MultiBlockMachine; @@ -44,6 +45,7 @@ class GiveCommand extends SubCommand { Player p = player.get(); SlimefunItem sfItem = SlimefunItem.getByID(args[2].toUpperCase(Locale.ROOT)); + if (sfItem != null) { if (sfItem instanceof MultiBlockMachine) { SlimefunPlugin.getLocal().sendMessage(sender, "guide.cheat.no-multiblocks"); @@ -74,7 +76,7 @@ class GiveCommand extends SubCommand { int amount = 1; if (args.length == 4) { - if (args[3].chars().allMatch(Character::isDigit)) { + if (PatternUtils.NUMERIC.matcher(args[3]).matches()) { amount = Integer.parseInt(args[3]); } else { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java index 3d3c71cd9..9b859ae25 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java @@ -8,7 +8,6 @@ import org.bukkit.entity.Player; import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException; import io.github.thebusybiscuit.slimefun4.core.MultiBlock; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunMachine; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.multiblocks.MultiBlockMachine; /** @@ -31,8 +30,7 @@ public interface MultiBlockInteractionHandler extends ItemHandler { @Override default Optional validate(SlimefunItem item) { - // Change this to "MultiBlockMachine" once SlimefunMachine was removed or deprecated - if (!(item instanceof SlimefunMachine)) { + if (!(item instanceof MultiBlockMachine)) { return Optional.of(new IncompatibleItemHandlerException("Only classes inheriting 'MultiBlockMachine' can have a MultiBlockInteractionHandler", item, this)); } From 31a9b69651337c2770c7546811ed3450a053411f Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Tue, 2 Jun 2020 13:58:03 +0200 Subject: [PATCH 03/18] Refactored Backpacks --- .../items/{food => backpacks}/Cooler.java | 11 +++- .../items/backpacks/SlimefunBackpack.java | 22 ++++++++ .../implementation/items/food/Juice.java | 1 + .../listeners/BackpackListener.java | 51 +++++++------------ .../listeners/CoolerListener.java | 2 +- .../setup/SlimefunItemSetup.java | 2 +- .../Slimefun/SlimefunPlugin.java | 2 +- 7 files changed, 54 insertions(+), 37 deletions(-) rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/{food => backpacks}/Cooler.java (72%) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Cooler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/Cooler.java similarity index 72% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Cooler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/Cooler.java index 298c5c136..40db894fe 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Cooler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/Cooler.java @@ -1,12 +1,13 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.food; +package io.github.thebusybiscuit.slimefun4.implementation.items.backpacks; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack; +import io.github.thebusybiscuit.slimefun4.implementation.items.food.Juice; import io.github.thebusybiscuit.slimefun4.implementation.listeners.CoolerListener; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** @@ -26,4 +27,10 @@ public class Cooler extends SlimefunBackpack { super(size, category, item, recipeType, recipe); } + @Override + public boolean isItemAllowed(ItemStack item, SlimefunItem itemAsSlimefunItem) { + // A Cooler only allows Juices + return itemAsSlimefunItem instanceof Juice; + } + } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java index 341915cbc..84989af45 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.backpacks; +import org.bukkit.Material; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -42,6 +43,27 @@ public class SlimefunBackpack extends SimpleSlimefunItem { return size; } + /** + * This method returns whether a given {@link ItemStack} is allowed to be stored + * in this {@link SlimefunBackpack}. + * + * @param item + * The {@link ItemStack} to check for + * + * @param itemAsSlimefunItem + * The same {@link ItemStack} as a {@link SlimefunItem}, might be null + * + * @return Whether the given {@link ItemStack} is allowed to be put into this {@link SlimefunBackpack} + */ + public boolean isItemAllowed(ItemStack item, SlimefunItem itemAsSlimefunItem) { + // Shulker Boxes are not allowed! + if (item.getType() == Material.SHULKER_BOX || item.getType().toString().endsWith("_SHULKER_BOX")) { + return false; + } + + return !(itemAsSlimefunItem instanceof SlimefunBackpack); + } + @Override public ItemUseHandler getItemHandler() { return e -> { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Juice.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Juice.java index 27454d15b..f4076401b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Juice.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/Juice.java @@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.food; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler; import io.github.thebusybiscuit.slimefun4.implementation.listeners.CoolerListener; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java index ae0752db5..0a1080315 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java @@ -23,9 +23,8 @@ import org.bukkit.inventory.meta.ItemMeta; import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack; -import io.github.thebusybiscuit.slimefun4.implementation.items.food.Cooler; -import io.github.thebusybiscuit.slimefun4.implementation.items.food.Juice; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.Slimefun; @@ -83,21 +82,31 @@ public class BackpackListener implements Listener { if (item != null) { SlimefunItem backpack = SlimefunItem.getByItem(item); - if (e.getClick() == ClickType.NUMBER_KEY) { - if (e.getClickedInventory().getType() != InventoryType.PLAYER) { - ItemStack hotbarItem = e.getWhoClicked().getInventory().getItem(e.getHotbarButton()); + if (backpack instanceof SlimefunBackpack) { + if (e.getClick() == ClickType.NUMBER_KEY) { + if (e.getClickedInventory().getType() != InventoryType.PLAYER) { + ItemStack hotbarItem = e.getWhoClicked().getInventory().getItem(e.getHotbarButton()); - if (!isItemAllowed(hotbarItem, backpack)) { - e.setCancelled(true); + if (!isAllowed((SlimefunBackpack) backpack, hotbarItem)) { + e.setCancelled(true); + } } } - } - else if (!isItemAllowed(e.getCurrentItem(), backpack)) { - e.setCancelled(true); + else if (!isAllowed((SlimefunBackpack) backpack, e.getCurrentItem())) { + e.setCancelled(true); + } } } } + private boolean isAllowed(SlimefunBackpack backpack, ItemStack item) { + if (item == null || item.getType() == Material.AIR) { + return true; + } + + return backpack.isItemAllowed(item, SlimefunItem.getByItem(item)); + } + public void openBackpack(Player p, ItemStack item, SlimefunBackpack backpack) { if (item.getAmount() == 1) { if (Slimefun.hasUnlocked(p, backpack, true) && !PlayerProfile.get(p, profile -> openBackpack(p, item, profile, backpack.getSize()))) { @@ -109,28 +118,6 @@ public class BackpackListener implements Listener { } } - private boolean isItemAllowed(ItemStack item, SlimefunItem backpack) { - if (item == null || item.getType() == Material.AIR) { - return true; - } - - if (item.getType() == Material.SHULKER_BOX || item.getType().toString().endsWith("_SHULKER_BOX")) { - return false; - } - - SlimefunItem slimefunItem = SlimefunItem.getByItem(item); - - if (slimefunItem instanceof SlimefunBackpack) { - return false; - } - - if (backpack instanceof Cooler) { - return slimefunItem instanceof Juice; - } - - return true; - } - private void openBackpack(Player p, ItemStack item, PlayerProfile profile, int size) { List lore = item.getItemMeta().getLore(); for (int line = 0; line < lore.size(); line++) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CoolerListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CoolerListener.java index 82a8c35d6..32b0f20ff 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CoolerListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CoolerListener.java @@ -13,7 +13,7 @@ import org.bukkit.potion.PotionEffect; import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; -import io.github.thebusybiscuit.slimefun4.implementation.items.food.Cooler; +import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler; import io.github.thebusybiscuit.slimefun4.implementation.items.food.Juice; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.api.Slimefun; 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 22a2021fa..cd010a72f 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 @@ -28,6 +28,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.androids.Programm import io.github.thebusybiscuit.slimefun4.implementation.items.androids.WoodcutterAndroid; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.Parachute; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; +import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.EnderBackpack; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.RestoredBackpack; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack; @@ -95,7 +96,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.NetherStarReactor; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.NuclearReactor; import io.github.thebusybiscuit.slimefun4.implementation.items.food.BirthdayCake; -import io.github.thebusybiscuit.slimefun4.implementation.items.food.Cooler; import io.github.thebusybiscuit.slimefun4.implementation.items.food.DietCookie; import io.github.thebusybiscuit.slimefun4.implementation.items.food.FortuneCookie; import io.github.thebusybiscuit.slimefun4.implementation.items.food.Juice; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java index e062b0ae0..b980de4da 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java @@ -44,7 +44,7 @@ import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService; import io.github.thebusybiscuit.slimefun4.core.services.metrics.MetricsService; import io.github.thebusybiscuit.slimefun4.core.services.plugins.ThirdPartyPluginService; import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar; -import io.github.thebusybiscuit.slimefun4.implementation.items.food.Cooler; +import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler; import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GrapplingHook; import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAxe; import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade; From 968b3df10a11c5a389f6fc6e70cc6b6c473eceaf Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Wed, 3 Jun 2020 09:51:51 +0200 Subject: [PATCH 04/18] Relocated Multiblock class --- .../slimefun4/api/events/MultiBlockInteractEvent.java | 2 +- .../thebusybiscuit/slimefun4/core/SlimefunRegistry.java | 1 + .../slimefun4/core/{ => multiblocks}/MultiBlock.java | 2 +- .../slimefun4/core/multiblocks/package-info.java | 5 +++++ .../slimefun4/implementation/guide/ChestSlimefunGuide.java | 2 +- .../implementation/listeners/MultiBlockListener.java | 2 +- .../slimefun4/implementation/package-info.java | 6 ++++++ .../java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java | 2 +- .../Slimefun/Objects/SlimefunItem/SlimefunMachine.java | 2 +- .../Objects/SlimefunItem/multiblocks/MultiBlockMachine.java | 2 +- .../Objects/handlers/MultiBlockInteractionHandler.java | 2 +- .../slimefun4/tests/listeners/TestMultiblockListener.java | 2 +- .../slimefun4/tests/multiblocks/TestMultiBlocks.java | 2 +- 13 files changed, 22 insertions(+), 10 deletions(-) rename src/main/java/io/github/thebusybiscuit/slimefun4/core/{ => multiblocks}/MultiBlock.java (98%) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/package-info.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/package-info.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MultiBlockInteractEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MultiBlockInteractEvent.java index d2876dbce..2d61f648a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MultiBlockInteractEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MultiBlockInteractEvent.java @@ -8,7 +8,7 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; -import io.github.thebusybiscuit.slimefun4.core.MultiBlock; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; /** * This {@link Event} is called when a {@link Player} interacts with a {@link MultiBlock}. diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java index de693fdf6..39fffb2c5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java @@ -24,6 +24,7 @@ import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.attributes.WitherProof; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide; import io.github.thebusybiscuit.slimefun4.implementation.guide.CheatSheetSlimefunGuide; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/MultiBlock.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java similarity index 98% rename from src/main/java/io/github/thebusybiscuit/slimefun4/core/MultiBlock.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java index c5e02985f..d7541c9a3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/MultiBlock.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.core; +package io.github.thebusybiscuit.slimefun4.core.multiblocks; import java.util.Arrays; import java.util.HashSet; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/package-info.java new file mode 100644 index 000000000..23867e7f6 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/package-info.java @@ -0,0 +1,5 @@ +/** + * This package holds all core mechanics related to a + * {@link io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock}, like that class itself. + */ +package io.github.thebusybiscuit.slimefun4.core.multiblocks; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java index 17760c1d7..96a360ee0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java @@ -25,7 +25,6 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.recipes.MinecraftRecipe; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; -import io.github.thebusybiscuit.slimefun4.core.MultiBlock; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory; import io.github.thebusybiscuit.slimefun4.core.categories.LockedCategory; @@ -34,6 +33,7 @@ import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; import io.github.thebusybiscuit.slimefun4.core.guide.options.SlimefunGuideSettings; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MultiBlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MultiBlockListener.java index b6bec9583..094e97855 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MultiBlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MultiBlockListener.java @@ -15,7 +15,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockInteractEvent; -import io.github.thebusybiscuit.slimefun4.core.MultiBlock; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.handlers.MultiBlockInteractionHandler; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/package-info.java new file mode 100644 index 000000000..7c6506481 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/package-info.java @@ -0,0 +1,6 @@ +/** + * This package holds all classes that are related to the actual implementation of this plugin. + * This includes implementations of {@link me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem} but also any + * {@link org.bukkit.event.Listener}. + */ +package io.github.thebusybiscuit.slimefun4.implementation; \ No newline at end of file diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index 444ea8059..00311e291 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -530,7 +530,7 @@ public final class SlimefunItems { public static final SlimefunItemStack CRUCIBLE = new SlimefunItemStack("CRUCIBLE", Material.CAULDRON, "&cCrucible", "", "&a&oUsed to smelt Items into Liquids"); public static final SlimefunItemStack JUICER = new SlimefunItemStack("JUICER", Material.GLASS_BOTTLE, "&aJuicer", "", "&aAllows you to create delicious Juice"); - public static final SlimefunItemStack SOLAR_PANEL = new SlimefunItemStack("SOLAR_PANEL", Material.DAYLIGHT_DETECTOR, "&bSolar Panel", "", "&a&oTransforms Sunlight to Energy"); + public static final ItemStack SOLAR_PANEL = new SlimefunItemStack("SOLAR_PANEL", Material.DAYLIGHT_DETECTOR, "&bSolar Panel", "", "&a&oTransforms Sunlight to Energy"); public static final SlimefunItemStack AUTOMATED_PANNING_MACHINE = new SlimefunItemStack("AUTOMATED_PANNING_MACHINE", Material.BOWL, "&eAutomated Panning Machine", "", "&rA MultiBlock Version of the Gold Pan", "&rand Nether Gold Pan combined in one machine."); public static final SlimefunItemStack OUTPUT_CHEST = new SlimefunItemStack("OUTPUT_CHEST", Material.CHEST, "&4Output Chest", "", "&c&oA basic machine will try to put", "&c&oitems in this chest if it's placed", "&c&oadjacent to the dispenser."); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java index aa6de7dcf..d7799026f 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java @@ -7,8 +7,8 @@ import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.inventory.ItemStack; -import io.github.thebusybiscuit.slimefun4.core.MultiBlock; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/multiblocks/MultiBlockMachine.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/multiblocks/MultiBlockMachine.java index d01c40f84..e7a43ceda 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/multiblocks/MultiBlockMachine.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/multiblocks/MultiBlockMachine.java @@ -18,9 +18,9 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; -import io.github.thebusybiscuit.slimefun4.core.MultiBlock; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java index 9b859ae25..31face950 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java @@ -6,7 +6,7 @@ import org.bukkit.block.Block; import org.bukkit.entity.Player; import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException; -import io.github.thebusybiscuit.slimefun4.core.MultiBlock; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.multiblocks.MultiBlockMachine; diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestMultiblockListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestMultiblockListener.java index df1216981..99977f110 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestMultiblockListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestMultiblockListener.java @@ -18,7 +18,7 @@ import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockInteractEvent; -import io.github.thebusybiscuit.slimefun4.core.MultiBlock; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import io.github.thebusybiscuit.slimefun4.implementation.listeners.MultiBlockListener; import io.github.thebusybiscuit.slimefun4.mocks.TestUtilities; import me.mrCookieSlime.Slimefun.SlimefunPlugin; diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/multiblocks/TestMultiBlocks.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/multiblocks/TestMultiBlocks.java index 171f1b451..2632e26da 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/multiblocks/TestMultiBlocks.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/multiblocks/TestMultiBlocks.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; -import io.github.thebusybiscuit.slimefun4.core.MultiBlock; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import io.github.thebusybiscuit.slimefun4.mocks.TestUtilities; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; From 7e8a63bff84690ab83328f29515cc6c5446bac8c Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 4 Jun 2020 15:26:35 +0200 Subject: [PATCH 05/18] Dried Kelp Blocks are now valid coal generator fuel --- CHANGELOG.md | 1 + .../implementation/items/electric/generators/CoalGenerator.java | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea1046c1c..3e39fa030 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ * Added Dried Kelp Blocks recipe to the Electric Press * Added Bone Blocks recipe to the Electric Press * Added thai translations +* Dried Kelp Blocks can now be used in the Coal Generator #### Changes * Fixed a few memory leaks diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/CoalGenerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/CoalGenerator.java index 84c24b93e..7d5fc590a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/CoalGenerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/CoalGenerator.java @@ -20,6 +20,7 @@ public abstract class CoalGenerator extends AGenerator { protected void registerDefaultFuelTypes() { registerFuel(new MachineFuel(80, new ItemStack(Material.COAL_BLOCK))); registerFuel(new MachineFuel(12, new ItemStack(Material.BLAZE_ROD))); + registerFuel(new MachineFuel(20, new ItemStack(Material.DRIED_KELP_BLOCK))); // Coal & Charcoal registerFuel(new MachineFuel(8, new ItemStack(Material.COAL))); From 618bbfff246ef97b7cb221e0f818a8cdaa98358e Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 4 Jun 2020 23:55:53 +0200 Subject: [PATCH 06/18] Optimized Fuel --- .../abstractItems/AGenerator.java | 8 ++--- .../SlimefunItem/abstractItems/AReactor.java | 8 ++--- .../abstractItems/MachineFuel.java | 34 +++++++++++++++---- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java index 0ca89236a..74f2e5573 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java @@ -204,11 +204,11 @@ public abstract class AGenerator extends AbstractEnergyGenerator { } private MachineFuel findRecipe(BlockMenu menu, Map found) { - for (MachineFuel recipe : fuelTypes) { + for (MachineFuel fuel : fuelTypes) { for (int slot : getInputSlots()) { - if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), recipe.getInput(), true)) { - found.put(slot, recipe.getInput().getAmount()); - return recipe; + if (fuel.test(menu.getItemInSlot(slot))) { + found.put(slot, fuel.getInput().getAmount()); + return fuel; } } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java index b2c731640..d5ce0f5af 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java @@ -421,11 +421,11 @@ public abstract class AReactor extends AbstractEnergyGenerator { } private MachineFuel findRecipe(BlockMenu menu, Map found) { - for (MachineFuel recipe : fuelTypes) { + for (MachineFuel fuel : fuelTypes) { for (int slot : getInputSlots()) { - if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), recipe.getInput(), true)) { - found.put(slot, recipe.getInput().getAmount()); - return recipe; + if (fuel.test(menu.getItemInSlot(slot))) { + found.put(slot, fuel.getInput().getAmount()); + return fuel; } } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/MachineFuel.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/MachineFuel.java index 88379c033..65aace18a 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/MachineFuel.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/MachineFuel.java @@ -1,35 +1,57 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems; +import java.util.function.Predicate; + +import org.apache.commons.lang.Validate; import org.bukkit.inventory.ItemStack; -public class MachineFuel { +import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; + +public class MachineFuel implements Predicate { private final int ticks; private final ItemStack fuel; private final ItemStack output; + // For performance optimizations + private final ItemStackWrapper wrapper; + public MachineFuel(int seconds, ItemStack fuel) { - this.ticks = seconds * 2; - this.fuel = fuel; - this.output = null; + this(seconds, fuel, null); } public MachineFuel(int seconds, ItemStack fuel, ItemStack output) { + Validate.notNull(fuel, "Fuel must never be null!"); + Validate.isTrue(seconds > 0, "Fuel must last at least one second!"); + this.ticks = seconds * 2; this.fuel = fuel; + this.wrapper = new ItemStackWrapper(fuel); this.output = output; } public ItemStack getInput() { - return this.fuel; + return fuel; } public ItemStack getOutput() { - return this.output; + return output; } + /** + * This method returns how long this {@link MachineFuel} lasts. + * The result represents Slimefun ticks. + * + * @return How many ticks this fuel type lasts + */ public int getTicks() { return ticks; } + @Override + public boolean test(ItemStack item) { + return SlimefunUtils.isItemSimilar(item, wrapper, true); + } + } From aebd03301d1c959a2a50f345819ae44590cc57ea Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 4 Jun 2020 23:56:08 +0200 Subject: [PATCH 07/18] Added new ItemStacks --- .../items/androids/ProgrammableAndroid.java | 6 +++--- .../Slimefun/Lists/SlimefunItems.java | 19 +++++++++++-------- src/main/resources/plugin.yml | 18 +++++++++--------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java index 0a07a2209..a9c520293 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java @@ -375,15 +375,15 @@ public abstract class ProgrammableAndroid extends Android implements InventoryBl ItemStack item = menu.getItemInSlot(43); if (item != null) { - for (MachineFuel recipe : recipes) { - if (SlimefunUtils.isItemSimilar(item, recipe.getInput(), true)) { + for (MachineFuel fuel : recipes) { + if (fuel.test(item)) { menu.consumeItem(43); if (getTier() == 2) { menu.pushItem(new ItemStack(Material.BUCKET), getOutputSlots()); } - BlockStorage.addBlockInfo(b, "fuel", String.valueOf((int) (recipe.getTicks() * this.getFuelEfficiency()))); + BlockStorage.addBlockInfo(b, "fuel", String.valueOf((int) (fuel.getTicks() * this.getFuelEfficiency()))); break; } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index 00311e291..8be585713 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -513,28 +513,31 @@ public final class SlimefunItems { STAFF_STORM.addUnsafeEnchantment(Enchantment.DURABILITY, 1); } - /* Machines */ + /* Multiblocks */ + public static final SlimefunItemStack ENHANCED_CRAFTING_TABLE = new SlimefunItemStack("ENHANCED_CRAFTING_TABLE", Material.CRAFTING_TABLE, "&eEnhanced Crafting Table", "", "&aA regular Crafting Table cannot", "&ahold this massive Amount of Power..."); public static final SlimefunItemStack GRIND_STONE = new SlimefunItemStack("GRIND_STONE", Material.DISPENSER, "&bGrind Stone", "", "&aGrinds items down into other items"); public static final SlimefunItemStack ARMOR_FORGE = new SlimefunItemStack("ARMOR_FORGE", Material.ANVIL, "&6Armor Forge", "", "&aGives you the ability to create powerful armor"); public static final SlimefunItemStack MAKESHIFT_SMELTERY; public static final SlimefunItemStack SMELTERY = new SlimefunItemStack("SMELTERY", Material.FURNACE, "&6Smeltery", "", "&rA high-temperature furnace", "&rthat allows you to smelt dusts", "&rinto ingots and create alloys."); - public static final SlimefunItemStack IGNITION_CHAMBER = new SlimefunItemStack("IGNITION_CHAMBER", Material.DROPPER, "&4Automatic Ignition Chamber", "", "&rPrevents the Smeltery from using up fire.", "&rJust fill it up with \"Flint and Steel\"", "&rand place it adjacent to the Smeltery's dispenser"); public static final SlimefunItemStack ORE_CRUSHER = new SlimefunItemStack("ORE_CRUSHER", Material.DISPENSER, "&bOre Crusher", "", "&aCrushes ores to double them"); public static final SlimefunItemStack COMPRESSOR = new SlimefunItemStack("COMPRESSOR", Material.PISTON, "&bCompressor", "", "&aCompresses Items"); public static final SlimefunItemStack PRESSURE_CHAMBER = new SlimefunItemStack("PRESSURE_CHAMBER", Material.GLASS, "&bPressure Chamber", "", "&aCompresses Items even further"); public static final SlimefunItemStack MAGIC_WORKBENCH = new SlimefunItemStack("MAGIC_WORKBENCH", Material.CRAFTING_TABLE, "&6Magic Workbench", "", "&dInfuses Items with magical Energy"); public static final SlimefunItemStack ORE_WASHER = new SlimefunItemStack("ORE_WASHER", Material.CAULDRON, "&6Ore Washer", "", "&aWashes Sifted Ore to filter Ores", "&aand gives you small Stone Chunks"); public static final SlimefunItemStack TABLE_SAW; - public static final SlimefunItemStack COMPOSTER = new SlimefunItemStack("COMPOSTER", Material.CAULDRON, "&aComposter", "", "&a&oCan convert various Materials over Time..."); - public static final SlimefunItemStack ENHANCED_CRAFTING_TABLE = new SlimefunItemStack("ENHANCED_CRAFTING_TABLE", Material.CRAFTING_TABLE, "&eEnhanced Crafting Table", "", "&aA regular Crafting Table cannot", "&ahold this massive Amount of Power..."); - public static final SlimefunItemStack CRUCIBLE = new SlimefunItemStack("CRUCIBLE", Material.CAULDRON, "&cCrucible", "", "&a&oUsed to smelt Items into Liquids"); public static final SlimefunItemStack JUICER = new SlimefunItemStack("JUICER", Material.GLASS_BOTTLE, "&aJuicer", "", "&aAllows you to create delicious Juice"); - - public static final ItemStack SOLAR_PANEL = new SlimefunItemStack("SOLAR_PANEL", Material.DAYLIGHT_DETECTOR, "&bSolar Panel", "", "&a&oTransforms Sunlight to Energy"); - public static final SlimefunItemStack AUTOMATED_PANNING_MACHINE = new SlimefunItemStack("AUTOMATED_PANNING_MACHINE", Material.BOWL, "&eAutomated Panning Machine", "", "&rA MultiBlock Version of the Gold Pan", "&rand Nether Gold Pan combined in one machine."); + + public static final SlimefunItemStack INDUSTRIAL_MINER = new SlimefunItemStack("INDUSTRIAL_MINER", Material.GOLDEN_PICKAXE, "&bIndustrial Miner", "", "&rThis Multiblock will mine any Ores", "&rin a 7x7 area underneath it.", "&rPlace coal or similar in its chest", "&rto fuel this machine."); + public static final SlimefunItemStack ADVANCED_INDUSTRIAL_MINER = new SlimefunItemStack("ADVANCED_INDUSTRIAL_MINER", Material.DIAMOND_PICKAXE, "&cAdvanced Industrial Miner", "", "&rThis Multiblock will mine any Ores", "&rin a 11x11 area underneath it.", "&rPlace a bucket of fuel or lava in", "&r its chest to fuel this machine."); + + /* Machines */ + public static final SlimefunItemStack COMPOSTER = new SlimefunItemStack("COMPOSTER", Material.CAULDRON, "&aComposter", "", "&a&oCan convert various Materials over Time..."); + public static final SlimefunItemStack CRUCIBLE = new SlimefunItemStack("CRUCIBLE", Material.CAULDRON, "&cCrucible", "", "&a&oUsed to smelt Items into Liquids"); public static final SlimefunItemStack OUTPUT_CHEST = new SlimefunItemStack("OUTPUT_CHEST", Material.CHEST, "&4Output Chest", "", "&c&oA basic machine will try to put", "&c&oitems in this chest if it's placed", "&c&oadjacent to the dispenser."); + public static final SlimefunItemStack IGNITION_CHAMBER = new SlimefunItemStack("IGNITION_CHAMBER", Material.DROPPER, "&4Automatic Ignition Chamber", "", "&rPrevents the Smeltery from using up fire.", "&rJust fill it up with \"Flint and Steel\"", "&rand place it adjacent to the Smeltery's dispenser"); public static final SlimefunItemStack HOLOGRAM_PROJECTOR = new SlimefunItemStack("HOLOGRAM_PROJECTOR", Material.QUARTZ_SLAB, "&bHologram Projector", "", "&rProjects an Editable Hologram"); + public static final ItemStack SOLAR_PANEL = new SlimefunItemStack("SOLAR_PANEL", Material.DAYLIGHT_DETECTOR, "&bSolar Panel", "", "&a&oTransforms Sunlight to Energy"); /* Enhanced Furnaces */ public static final SlimefunItemStack ENHANCED_FURNACE = new SlimefunItemStack("ENHANCED_FURNACE", Material.FURNACE, "&7Enhanced Furnace - &eI", "", "&7Processing Speed: &e1x", "&7Fuel Efficiency: &e1x", "&7Luck Multiplier: &e1x"); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d0e96ab08..69327096a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -16,6 +16,15 @@ commands: usage: You either forgot to install CS-CoreLib or you installed an unsupported version. permissions: + slimefun.command.guide: + description: Allows you to obtain the Slimefun guide book + default: true + slimefun.command.search: + description: Allows you to do /sf search + default: true + slimefun.command.open_guide: + description: Allows you to open the SF guide without the book + default: op slimefun.cheat.items: description: Allows you to cheat Items default: op @@ -40,15 +49,6 @@ permissions: slimefun.command.backpack: description: Allows you to do /sf backpack default: op - slimefun.command.guide: - description: Allows you to obtain the Slimefun guide book - default: true - slimefun.command.search: - description: Allows you to do /sf search - default: true - slimefun.command.open_guide: - description: Allows you to open the SF guide without the book - default: op slimefun.android.bypass: description: Allows you to edit other Players Androids default: op From 4664fb00feeef2bbec3d079be43f7d38418efc29 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 4 Jun 2020 23:59:58 +0200 Subject: [PATCH 08/18] Added back researches --- .../slimefun4/implementation/setup/ResearchSetup.java | 2 ++ 1 file changed, 2 insertions(+) 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 76fa4ceaf..700a14e63 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 @@ -263,6 +263,8 @@ public final class ResearchSetup { register("kelp_cookie", 254, "Tasty Kelp", 4, SlimefunItems.KELP_COOKIE); register("makeshift_smeltery", 255, "Improvised Smeltery", 6, SlimefunItems.MAKESHIFT_SMELTERY); 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); } private static void register(String key, int id, String name, int defaultCost, ItemStack... items) { From c8f78379a17ed18cf52b3d3d2abeff2d9a75f077 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 5 Jun 2020 00:00:07 +0200 Subject: [PATCH 09/18] Added Industrial Miner --- CHANGELOG.md | 1 + .../core/multiblocks/MultiBlock.java | 10 + .../items/multiblocks/IndustrialMiner.java | 198 +++++++++++ .../multiblocks/IndustrialMinerInstance.java | 333 ++++++++++++++++++ .../setup/SlimefunItemSetup.java | 3 + src/main/resources/languages/messages_en.yml | 25 +- .../resources/languages/researches_en.yml | 2 + 7 files changed, 563 insertions(+), 9 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e39fa030..06c8429a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ * Added Bone Blocks recipe to the Electric Press * Added thai translations * Dried Kelp Blocks can now be used in the Coal Generator +* Added Industrial Miner #### Changes * Fixed a few memory leaks diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java index d7541c9a3..5a360cd17 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java @@ -122,6 +122,16 @@ public class MultiBlock { } } + // This ensures that the Industrial Miner is still recognized while operating + if (a == Material.PISTON) { + return a == b || b == Material.MOVING_PISTON; + } + + // This ensures that the Industrial Miner is still recognized while operating + if (b == Material.PISTON) { + return a == b || a == Material.MOVING_PISTON; + } + if (b != a) { return false; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java new file mode 100644 index 000000000..0da967977 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java @@ -0,0 +1,198 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +import org.apache.commons.lang.Validate; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Tag; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; +import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.multiblocks.MultiBlockMachine; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; + +/** + * The {@link IndustrialMiner} is a {@link MultiBlockMachine} that can mine any + * ores it finds in a given range underneath where it was placed. + * + * And for those of you who are wondering... yes this is the replacement for the + * long-time deprecated Digital Miner. + * + * @author TheBusyBiscuit + * + */ +public class IndustrialMiner extends MultiBlockMachine { + + protected final Map activeMiners = new HashMap<>(); + protected final List fuelTypes = new ArrayList<>(); + + private final int range; + private final boolean silkTouch; + + public IndustrialMiner(Category category, SlimefunItemStack item, Material baseMaterial, boolean silkTouch, int range) { + super(category, item, new ItemStack[] { null, null, null, new CustomItem(Material.PISTON, "Piston (facing up)"), new ItemStack(Material.CHEST), new CustomItem(Material.PISTON, "Piston (facing up)"), new ItemStack(baseMaterial), new ItemStack(SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14) ? Material.BLAST_FURNACE : Material.FURNACE), new ItemStack(baseMaterial) }, new ItemStack[0], BlockFace.UP); + + this.range = range; + this.silkTouch = silkTouch; + + registerDefaultFuelTypes(); + } + + /** + * This returns whether this {@link IndustrialMiner} will output ores as they are. + * Similar to the Silk Touch {@link Enchantment}. + * + * @return Whether to treat ores with Silk Touch + */ + public boolean hasSilkTouch() { + return silkTouch; + } + + /** + * This method returns the range of the {@link IndustrialMiner}. + * The total area will be determined by the range multiplied by 2 plus the actual center + * of the machine. + * + * So a range of 3 will make the {@link IndustrialMiner} affect an area of 7x7 blocks. + * 3 on all axis, plus the center of the machine itself. + * + * @return The range of this {@link IndustrialMiner} + */ + public int getRange() { + return range; + } + + /** + * This registers the various types of fuel that can be used in the + * {@link IndustrialMiner}. + */ + protected void registerDefaultFuelTypes() { + // Coal & Charcoal + fuelTypes.add(new MachineFuel(4, new ItemStack(Material.COAL))); + fuelTypes.add(new MachineFuel(4, new ItemStack(Material.CHARCOAL))); + + fuelTypes.add(new MachineFuel(40, new ItemStack(Material.COAL_BLOCK))); + fuelTypes.add(new MachineFuel(10, new ItemStack(Material.DRIED_KELP_BLOCK))); + fuelTypes.add(new MachineFuel(4, new ItemStack(Material.BLAZE_ROD))); + + // Logs + for (Material mat : Tag.LOGS.getValues()) { + fuelTypes.add(new MachineFuel(1, new ItemStack(mat))); + } + } + + /** + * This method returns the outcome that mining certain ores yields. + * + * @param ore + * The {@link Material} of the ore that was mined + * + * @return The outcome when mining this ore + */ + public ItemStack getOutcome(Material ore) { + if (hasSilkTouch()) { + return new ItemStack(ore); + } + + Random random = ThreadLocalRandom.current(); + + switch (ore) { + case COAL_ORE: + return new ItemStack(Material.COAL); + case DIAMOND_ORE: + return new ItemStack(Material.DIAMOND); + case EMERALD_ORE: + return new ItemStack(Material.EMERALD); + case NETHER_QUARTZ_ORE: + return new ItemStack(Material.QUARTZ); + case REDSTONE_ORE: + return new ItemStack(Material.REDSTONE, 4 + random.nextInt(2)); + case LAPIS_ORE: + return new ItemStack(Material.LAPIS_LAZULI, 4 + random.nextInt(4)); + default: + // This includes Iron and Gold ore + return new ItemStack(ore); + } + } + + /** + * This registers a new fuel type for this {@link IndustrialMiner}. + * + * @param ores + * The amount of ores this allows you to mine + * @param item + * The item that shall be consumed + */ + public void addFuelType(int ores, ItemStack item) { + Validate.isTrue(ores > 1 && ores % 2 == 0, "The amount of ores must be at least 2 and a multiple of 2."); + fuelTypes.add(new MachineFuel(ores / 2, item)); + } + + @Override + public String getLabelLocalPath() { + return "guide.tooltips.recipes.generator"; + } + + @Override + public List getDisplayRecipes() { + List list = new ArrayList<>(); + + for (MachineFuel fuel : fuelTypes) { + ItemStack item = fuel.getInput().clone(); + ItemMeta im = item.getItemMeta(); + List lore = new ArrayList<>(); + lore.add(ChatColors.color("&8\u21E8 &7Lasts for max. " + fuel.getTicks() + " Ores")); + im.setLore(lore); + item.setItemMeta(im); + list.add(item); + } + + return list; + } + + @Override + public void onInteract(Player p, Block b) { + if (activeMiners.containsKey(b.getLocation())) { + SlimefunPlugin.getLocal().sendMessage(p, "machines.INDUSTRIAL_MINER.already-running"); + return; + } + + Block chest = b.getRelative(BlockFace.UP); + Block[] pistons = findPistons(chest); + + int mod = getRange(); + Location start = b.getLocation().clone().add(-mod, -1, -mod); + Location end = b.getLocation().clone().add(mod, -1, mod); + + IndustrialMinerInstance instance = new IndustrialMinerInstance(this, p.getUniqueId(), chest, pistons, start, end); + instance.start(b); + } + + private Block[] findPistons(Block chest) { + Block northern = chest.getRelative(BlockFace.NORTH); + + if (northern.getType() == Material.PISTON) { + return new Block[] { northern, chest.getRelative(BlockFace.SOUTH) }; + } + else { + return new Block[] { chest.getRelative(BlockFace.WEST), chest.getRelative(BlockFace.EAST) }; + } + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java new file mode 100644 index 000000000..6b5a3f556 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java @@ -0,0 +1,333 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks; + +import java.util.UUID; +import java.util.logging.Level; + +import org.bukkit.Bukkit; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Chest; +import org.bukkit.block.data.type.Piston; +import org.bukkit.block.data.type.PistonHead; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; +import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; +import io.github.thebusybiscuit.cscorelib2.scheduling.TaskQueue; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; +import me.mrCookieSlime.Slimefun.api.Slimefun; + +class IndustrialMinerInstance implements Runnable { + + private final IndustrialMiner miner; + private final UUID owner; + + private int fuel = 0; + private int ores = 0; + private boolean running = false; + + private final Block chest; + private final Block[] pistons; + + private final Location start; + private final Location end; + private final int height; + + private int x; + private int z; + + public IndustrialMinerInstance(IndustrialMiner miner, UUID owner, Block chest, Block[] pistons, Location start, Location end) { + this.miner = miner; + this.owner = owner; + + this.chest = chest; + this.pistons = pistons; + + this.start = start; + this.end = end; + + this.height = start.getBlockY(); + this.x = start.getBlockX(); + this.z = start.getBlockZ(); + } + + /** + * This starts the {@link IndustrialMiner} at the given {@link Block}. + * + * @param b + * The {@link Block} which marks the center of this {@link IndustrialMiner} + */ + public void start(Block b) { + miner.activeMiners.put(b.getLocation(), this); + running = true; + + warmUp(); + } + + /** + * This method stops the {@link IndustrialMiner}. + */ + public void stop() { + running = false; + miner.activeMiners.remove(chest.getRelative(BlockFace.DOWN).getLocation()); + } + + /** + * This method stops the {@link IndustrialMiner} with an error message. + * The error message is a path to the location in Slimefun's localization files. + * + * @param error + * The error message to send + */ + public void stop(String error) { + Player p = Bukkit.getPlayer(owner); + + if (p != null) { + SlimefunPlugin.getLocal().sendMessage(p, error); + } + + stop(); + } + + /** + * This method starts the warm-up animation for the {@link IndustrialMiner}. + */ + private void warmUp() { + fuel = consumeFuel(); + + if (fuel <= 0) { + // This Miner has not enough fuel. + stop("machines.INDUSTRIAL_MINER.no-fuel"); + return; + } + + TaskQueue queue = new TaskQueue(); + + queue.thenRun(4, () -> setPistonState(pistons[0], true)); + queue.thenRun(10, () -> setPistonState(pistons[0], false)); + + queue.thenRun(8, () -> setPistonState(pistons[1], true)); + queue.thenRun(10, () -> setPistonState(pistons[1], false)); + + queue.thenRun(6, () -> setPistonState(pistons[0], true)); + queue.thenRun(9, () -> setPistonState(pistons[0], false)); + + queue.thenRun(4, () -> setPistonState(pistons[1], true)); + queue.thenRun(7, () -> setPistonState(pistons[1], false)); + + queue.thenRun(3, () -> setPistonState(pistons[0], true)); + queue.thenRun(4, () -> setPistonState(pistons[0], false)); + + queue.thenRun(2, () -> setPistonState(pistons[1], true)); + queue.thenRun(3, () -> setPistonState(pistons[1], false)); + + queue.thenRun(1, () -> setPistonState(pistons[0], true)); + queue.thenRun(3, () -> setPistonState(pistons[0], false)); + + queue.thenRun(1, () -> setPistonState(pistons[1], true)); + queue.thenRun(3, () -> setPistonState(pistons[1], false)); + + queue.thenRun(1, this); + queue.execute(SlimefunPlugin.instance); + } + + @Override + public void run() { + if (!running) { + return; + } + + try { + TaskQueue queue = new TaskQueue(); + + queue.thenRun(1, () -> setPistonState(pistons[0], true)); + queue.thenRun(3, () -> setPistonState(pistons[0], false)); + + queue.thenRun(1, () -> setPistonState(pistons[1], true)); + queue.thenRun(3, () -> setPistonState(pistons[1], false)); + + queue.thenRun(() -> { + Block furnace = chest.getRelative(BlockFace.DOWN); + furnace.getWorld().playEffect(furnace.getLocation(), Effect.STEP_SOUND, Material.STONE); + + for (int y = height; y > 0; y--) { + Block b = start.getWorld().getBlockAt(x, y, z); + + if (!SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(owner), b, ProtectableAction.BREAK_BLOCK)) { + stop("machines.INDUSTRIAL_MINER.no-permission"); + return; + } + + if (b.getType().name().endsWith("_ORE") && push(miner.getOutcome(b.getType()))) { + furnace.getWorld().playEffect(furnace.getLocation(), Effect.STEP_SOUND, b.getType()); + furnace.getWorld().playSound(furnace.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.2F, 1F); + + b.setType(Material.AIR); + fuel--; + ores++; + + // Repeat the same column when we hit an ore. + Slimefun.runSync(this, 5); + return; + } + } + + nextColumn(); + }); + + queue.execute(SlimefunPlugin.instance); + } + catch (Exception e) { + Slimefun.getLogger().log(Level.SEVERE, "An Error occured while running an Industrial Miner", e); + stop(); + } + } + + /** + * This advanced the {@link IndustrialMiner} to the next column + */ + private void nextColumn() { + if (x < end.getBlockX()) { + x++; + } + else if (z < end.getBlockZ()) { + x = start.getBlockX(); + z++; + } + else { + stop(); + + Player p = Bukkit.getPlayer(owner); + + if (p != null) { + p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.4F, 1F); + SlimefunPlugin.getLocal().sendMessage(p, "machines.INDUSTRIAL_MINER.finished", msg -> msg.replace("%ores%", String.valueOf(ores))); + } + + return; + } + + Slimefun.runSync(this, 5); + } + + private boolean push(ItemStack outcome) { + if (fuel < 1) { + fuel = consumeFuel(); + } + + if (fuel > 0) { + if (chest.getType() == Material.CHEST) { + Inventory inv = ((Chest) chest.getState()).getBlockInventory(); + + if (InvUtils.fits(inv, outcome)) { + inv.addItem(outcome); + return true; + } + else { + stop("machines.INDUSTRIAL_MINER.chest-full"); + } + } + else { + // The chest has been destroyed + stop("machines.INDUSTRIAL_MINER.destroyed"); + } + } + else { + stop("machines.INDUSTRIAL_MINER.no-fuel"); + } + + return false; + } + + /** + * This consumes fuel from the given {@link Chest}. + * + * @return The gained fuel value + */ + private int consumeFuel() { + if (chest.getType() == Material.CHEST) { + Inventory inv = ((Chest) chest.getState()).getBlockInventory(); + + for (int i = 0; i < inv.getSize(); i++) { + for (MachineFuel fuelType : miner.fuelTypes) { + ItemStack item = inv.getContents()[i]; + + if (fuelType.test(item)) { + ItemUtils.consumeItem(item, false); + return fuelType.getTicks(); + } + } + } + } + + return 0; + } + + private void setPistonState(Block block, boolean extended) { + if (!running) { + return; + } + + try { + // Smoke Particles around the Chest for dramatic effect + Location particleLoc = chest.getLocation().clone().add(0, -1, 0); + block.getWorld().spawnParticle(Particle.SMOKE_NORMAL, particleLoc, 16, 1, 1, 1, 0); + + if (block.getType() == Material.MOVING_PISTON) { + // Yeah it isn't really cool when this happens + block.getRelative(BlockFace.UP).setType(Material.AIR); + } + else if (block.getType() == Material.PISTON) { + Block above = block.getRelative(BlockFace.UP); + + if (above.isEmpty() || above.getType() == Material.PISTON_HEAD) { + Piston piston = (Piston) block.getBlockData(); + + if (piston.getFacing() == BlockFace.UP) { + piston.setExtended(extended); + block.setBlockData(piston, false); + + // Updating the Piston Head + if (extended) { + PistonHead head = (PistonHead) Material.PISTON_HEAD.createBlockData(); + head.setFacing(BlockFace.UP); + + block.getRelative(BlockFace.UP).setBlockData(head, false); + } + else { + block.getRelative(BlockFace.UP).setType(Material.AIR); + } + + block.getWorld().playSound(block.getLocation(), extended ? Sound.BLOCK_PISTON_EXTEND : Sound.BLOCK_PISTON_CONTRACT, 0.2F, 1F); + } + else { + // The pistons must be facing upwards + stop("machines.INDUSTRIAL_MINER.piston-facing"); + } + } + else { + // The pistons must be facing upwards + stop("machines.INDUSTRIAL_MINER.piston-space"); + } + } + else { + // The piston has been destroyed + stop("machines.INDUSTRIAL_MINER.destroyed"); + } + } + catch (Exception e) { + Slimefun.getLogger().log(Level.SEVERE, "An Error occured while moving a Piston for an Industrial Miner", e); + stop(); + } + } + +} 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 cd010a72f..ec70c458a 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 @@ -135,6 +135,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Autom import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Compressor; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.EnhancedCraftingTable; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.GrindStone; +import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.IndustrialMiner; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Juicer; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MagicWorkbench; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MakeshiftSmeltery; @@ -1021,6 +1022,8 @@ public final class SlimefunItemSetup { .register(plugin); new AutomatedPanningMachine(categories.basicMachines).register(plugin); + + new IndustrialMiner(categories.basicMachines, SlimefunItems.INDUSTRIAL_MINER, Material.IRON_BLOCK, false, 3).register(plugin); new SlimefunItem(categories.magicalArmor, SlimefunItems.BOOTS_OF_THE_STOMPER, RecipeType.ARMOR_FORGE, new ItemStack[] {null, null, null, new ItemStack(Material.YELLOW_WOOL), null, new ItemStack(Material.YELLOW_WOOL), new ItemStack(Material.PISTON), null, new ItemStack(Material.PISTON)}) diff --git a/src/main/resources/languages/messages_en.yml b/src/main/resources/languages/messages_en.yml index d13fdf0ee..397bb69bb 100644 --- a/src/main/resources/languages/messages_en.yml +++ b/src/main/resources/languages/messages_en.yml @@ -16,11 +16,11 @@ commands: reset-target: '&cYour Knowledge has been reset' backpack: - description: Retrieve an existing backpack - invalid-id: '&4The backpack id must be a non-negative number!' - player-never-joined: '&4No player with that name has ever joined the server!' - backpack-does-not-exist: '&4That backpack does not exist!' - restored-backpack-given: '&bBackpack restored successfully! Added to your inventory!' + description: Retrieve a copy of an existing backpack + invalid-id: '&4The id must be a non-negative number!' + player-never-joined: '&4No player with that name could be found!' + backpack-does-not-exist: '&4The specified backpack does not exist!' + restored-backpack-given: '&aYour backpack has been restored and was added to your inventory!' guide: locked: 'LOCKED' @@ -202,7 +202,17 @@ machines: CARGO_NODES: must-be-placed: '&4Must be placed onto a chest or machine!' - + + INDUSTRIAL_MINER: + no-fuel: '&cYour Industrial Miner ran out of fuel! Put your fuel into the chest above.' + piston-facing: '&cYour Industrial Miner requires pistons to face upwards!' + piston-space: '&cThe two pistons need to have an empty block above them!' + destroyed: '&cYour Industrial Miner seems to have been destroyed.' + already-running: '&cThis Industrial Miner is already running!' + full-chest: '&cThe Chest of your Industrial Miner is full!' + no-permission: '&4You do not seem to have permission to operate an Industrial Miner here!' + finished: '&eYour Industrial Miner has finished! It obtained a total of %ores% ore(s)!' + anvil: not-working: '&4You cannot use Slimefun Items in an anvil!' @@ -210,9 +220,6 @@ backpack: already-open: '&cSorry, this Backpack is open somewhere else!' no-stack: '&cYou cannot stack Backpacks' -miner: - no-ores: '&eSorry, I could not find any Ores nearby!' - workbench: not-enhanced: '&4You cannot use Slimefun Items in a normal workbench' diff --git a/src/main/resources/languages/researches_en.yml b/src/main/resources/languages/researches_en.yml index 47c20ddcf..3160e811f 100644 --- a/src/main/resources/languages/researches_en.yml +++ b/src/main/resources/languages/researches_en.yml @@ -231,3 +231,5 @@ slimefun: kelp_cookie: Tasty Kelp makeshift_smeltery: Improvised Smeltery tree_growth_accelerator: Faster Trees + industrial_miner: Industrial Mining + advanced_industrial_miner: Better Mining From 4f21fd03bc124298bafe3903c1c3a3c6fa8c2b30 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 5 Jun 2020 00:21:45 +0200 Subject: [PATCH 10/18] Finished Industrial Miner --- .../items/multiblocks/IndustrialMiner.java | 2 ++ .../multiblocks/IndustrialMinerInstance.java | 24 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java index 0da967977..8498f9f3d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java @@ -35,6 +35,8 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; * long-time deprecated Digital Miner. * * @author TheBusyBiscuit + * + * @see IndustrialMinerInstance * */ public class IndustrialMiner extends MultiBlockMachine { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java index 6b5a3f556..e7aa71d30 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java @@ -26,6 +26,14 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; import me.mrCookieSlime.Slimefun.api.Slimefun; +/** + * This represents a running instance of an {@link IndustrialMiner}. + * + * @author TheBusyBiscuit + * + * @see IndustrialMiner + * + */ class IndustrialMinerInstance implements Runnable { private final IndustrialMiner miner; @@ -125,16 +133,16 @@ class IndustrialMinerInstance implements Runnable { queue.thenRun(7, () -> setPistonState(pistons[1], false)); queue.thenRun(3, () -> setPistonState(pistons[0], true)); - queue.thenRun(4, () -> setPistonState(pistons[0], false)); + queue.thenRun(5, () -> setPistonState(pistons[0], false)); queue.thenRun(2, () -> setPistonState(pistons[1], true)); - queue.thenRun(3, () -> setPistonState(pistons[1], false)); + queue.thenRun(4, () -> setPistonState(pistons[1], false)); queue.thenRun(1, () -> setPistonState(pistons[0], true)); queue.thenRun(3, () -> setPistonState(pistons[0], false)); queue.thenRun(1, () -> setPistonState(pistons[1], true)); - queue.thenRun(3, () -> setPistonState(pistons[1], false)); + queue.thenRun(2, () -> setPistonState(pistons[1], false)); queue.thenRun(1, this); queue.execute(SlimefunPlugin.instance); @@ -158,7 +166,7 @@ class IndustrialMinerInstance implements Runnable { queue.thenRun(() -> { Block furnace = chest.getRelative(BlockFace.DOWN); furnace.getWorld().playEffect(furnace.getLocation(), Effect.STEP_SOUND, Material.STONE); - + for (int y = height; y > 0; y--) { Block b = start.getWorld().getBlockAt(x, y, z); @@ -176,7 +184,7 @@ class IndustrialMinerInstance implements Runnable { ores++; // Repeat the same column when we hit an ore. - Slimefun.runSync(this, 5); + Slimefun.runSync(this, 3); return; } } @@ -216,7 +224,7 @@ class IndustrialMinerInstance implements Runnable { return; } - Slimefun.runSync(this, 5); + Slimefun.runSync(this, 4); } private boolean push(ItemStack outcome) { @@ -280,7 +288,7 @@ class IndustrialMinerInstance implements Runnable { try { // Smoke Particles around the Chest for dramatic effect Location particleLoc = chest.getLocation().clone().add(0, -1, 0); - block.getWorld().spawnParticle(Particle.SMOKE_NORMAL, particleLoc, 16, 1, 1, 1, 0); + block.getWorld().spawnParticle(Particle.SMOKE_NORMAL, particleLoc, 20, 0.7, 0.7, 0.7, 0); if (block.getType() == Material.MOVING_PISTON) { // Yeah it isn't really cool when this happens @@ -307,7 +315,7 @@ class IndustrialMinerInstance implements Runnable { block.getRelative(BlockFace.UP).setType(Material.AIR); } - block.getWorld().playSound(block.getLocation(), extended ? Sound.BLOCK_PISTON_EXTEND : Sound.BLOCK_PISTON_CONTRACT, 0.2F, 1F); + block.getWorld().playSound(block.getLocation(), extended ? Sound.BLOCK_PISTON_EXTEND : Sound.BLOCK_PISTON_CONTRACT, 0.1F, 1F); } else { // The pistons must be facing upwards From 15aabd6a63ebaf868faf3024c7d732597f4a690e Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 5 Jun 2020 00:37:21 +0200 Subject: [PATCH 11/18] Attributes are now hidden --- .../mrCookieSlime/Slimefun/Lists/SlimefunItems.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index 8be585713..a070a6337 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -6,6 +6,7 @@ import java.util.Map; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; @@ -531,6 +532,16 @@ public final class SlimefunItems { public static final SlimefunItemStack INDUSTRIAL_MINER = new SlimefunItemStack("INDUSTRIAL_MINER", Material.GOLDEN_PICKAXE, "&bIndustrial Miner", "", "&rThis Multiblock will mine any Ores", "&rin a 7x7 area underneath it.", "&rPlace coal or similar in its chest", "&rto fuel this machine."); public static final SlimefunItemStack ADVANCED_INDUSTRIAL_MINER = new SlimefunItemStack("ADVANCED_INDUSTRIAL_MINER", Material.DIAMOND_PICKAXE, "&cAdvanced Industrial Miner", "", "&rThis Multiblock will mine any Ores", "&rin a 11x11 area underneath it.", "&rPlace a bucket of fuel or lava in", "&r its chest to fuel this machine."); + static { + ItemMeta meta = INDUSTRIAL_MINER.getItemMeta(); + meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + INDUSTRIAL_MINER.setItemMeta(meta); + + ItemMeta meta2 = ADVANCED_INDUSTRIAL_MINER.getItemMeta(); + meta2.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + ADVANCED_INDUSTRIAL_MINER.setItemMeta(meta2); + } + /* Machines */ public static final SlimefunItemStack COMPOSTER = new SlimefunItemStack("COMPOSTER", Material.CAULDRON, "&aComposter", "", "&a&oCan convert various Materials over Time..."); public static final SlimefunItemStack CRUCIBLE = new SlimefunItemStack("CRUCIBLE", Material.CAULDRON, "&cCrucible", "", "&a&oUsed to smelt Items into Liquids"); From e41eca9caa68ad65793196d5c6bc059506ec9775 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 5 Jun 2020 14:09:32 +0200 Subject: [PATCH 12/18] Refactoring --- .../ActiveMiner.java} | 33 ++++++++++++++----- .../{ => miner}/IndustrialMiner.java | 20 ++++++++--- .../items/multiblocks/miner/package-info.java | 5 +++ .../setup/SlimefunItemSetup.java | 2 +- 4 files changed, 46 insertions(+), 14 deletions(-) rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/{IndustrialMinerInstance.java => miner/ActiveMiner.java} (90%) rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/{ => miner}/IndustrialMiner.java (92%) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/package-info.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java similarity index 90% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java index e7aa71d30..958e43578 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMinerInstance.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks; +package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner; import java.util.UUID; import java.util.logging.Level; @@ -34,7 +34,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun; * @see IndustrialMiner * */ -class IndustrialMinerInstance implements Runnable { +class ActiveMiner implements Runnable { private final IndustrialMiner miner; private final UUID owner; @@ -53,7 +53,7 @@ class IndustrialMinerInstance implements Runnable { private int x; private int z; - public IndustrialMinerInstance(IndustrialMiner miner, UUID owner, Block chest, Block[] pistons, Location start, Location end) { + public ActiveMiner(IndustrialMiner miner, UUID owner, Block chest, Block[] pistons, Location start, Location end) { this.miner = miner; this.owner = owner; @@ -118,6 +118,8 @@ class IndustrialMinerInstance implements Runnable { return; } + // This is our warm up animation + // The pistons will push after another in decreasing intervals TaskQueue queue = new TaskQueue(); queue.thenRun(4, () -> setPistonState(pistons[0], true)); @@ -151,6 +153,7 @@ class IndustrialMinerInstance implements Runnable { @Override public void run() { if (!running) { + // Don't continue if the machine has stopped return; } @@ -175,7 +178,7 @@ class IndustrialMinerInstance implements Runnable { return; } - if (b.getType().name().endsWith("_ORE") && push(miner.getOutcome(b.getType()))) { + if (miner.canMine(b.getType()) && push(miner.getOutcome(b.getType()))) { furnace.getWorld().playEffect(furnace.getLocation(), Effect.STEP_SOUND, b.getType()); furnace.getWorld().playSound(furnace.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.2F, 1F); @@ -184,7 +187,7 @@ class IndustrialMinerInstance implements Runnable { ores++; // Repeat the same column when we hit an ore. - Slimefun.runSync(this, 3); + Slimefun.runSync(this, 4); return; } } @@ -212,6 +215,7 @@ class IndustrialMinerInstance implements Runnable { z++; } else { + // The Miner has finished stop(); Player p = Bukkit.getPlayer(owner); @@ -224,20 +228,31 @@ class IndustrialMinerInstance implements Runnable { return; } - Slimefun.runSync(this, 4); + Slimefun.runSync(this, 5); } - private boolean push(ItemStack outcome) { + /** + * This refuels the {@link IndustrialMiner} and pushes the given {@link ItemStack} to + * its {@link Chest}. + * + * @param item + * The {@link ItemStack} to push to the {@link Chest}. + * + * @return Whether the operation was successful + */ + private boolean push(ItemStack item) { if (fuel < 1) { + // Restock fuel fuel = consumeFuel(); } + // Check if there is enough fuel to run if (fuel > 0) { if (chest.getType() == Material.CHEST) { Inventory inv = ((Chest) chest.getState()).getBlockInventory(); - if (InvUtils.fits(inv, outcome)) { - inv.addItem(outcome); + if (InvUtils.fits(inv, item)) { + inv.addItem(item); return true; } else { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java similarity index 92% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java index 8498f9f3d..40d8bade7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/IndustrialMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks; +package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner; import java.util.ArrayList; import java.util.HashMap; @@ -36,12 +36,12 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; * * @author TheBusyBiscuit * - * @see IndustrialMinerInstance + * @see ActiveMiner * */ public class IndustrialMiner extends MultiBlockMachine { - protected final Map activeMiners = new HashMap<>(); + protected final Map activeMiners = new HashMap<>(); protected final List fuelTypes = new ArrayList<>(); private final int range; @@ -182,7 +182,7 @@ public class IndustrialMiner extends MultiBlockMachine { Location start = b.getLocation().clone().add(-mod, -1, -mod); Location end = b.getLocation().clone().add(mod, -1, mod); - IndustrialMinerInstance instance = new IndustrialMinerInstance(this, p.getUniqueId(), chest, pistons, start, end); + ActiveMiner instance = new ActiveMiner(this, p.getUniqueId(), chest, pistons, start, end); instance.start(b); } @@ -197,4 +197,16 @@ public class IndustrialMiner extends MultiBlockMachine { } } + /** + * This returns whether this {@link IndustrialMiner} can mine the given {@link Material}. + * + * @param type + * The {@link Material} to check + * + * @return Whether this {@link IndustrialMiner} is capable of mining this {@link Material} + */ + public boolean canMine(Material type) { + return type.name().endsWith("_ORE"); + } + } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/package-info.java new file mode 100644 index 000000000..862e08748 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/package-info.java @@ -0,0 +1,5 @@ +/** + * This package holds classes associated with the + * {@link io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.IndustrialMiner}. + */ +package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner; \ No newline at end of file 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 ec70c458a..23e2bb2b2 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 @@ -135,7 +135,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Autom import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Compressor; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.EnhancedCraftingTable; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.GrindStone; -import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.IndustrialMiner; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Juicer; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MagicWorkbench; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MakeshiftSmeltery; @@ -144,6 +143,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreWa import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.PressureChamber; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Smeltery; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.TableSaw; +import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner.IndustrialMiner; import io.github.thebusybiscuit.slimefun4.implementation.items.seasonal.ChristmasPresent; import io.github.thebusybiscuit.slimefun4.implementation.items.seasonal.EasterEgg; import io.github.thebusybiscuit.slimefun4.implementation.items.tools.ExplosivePickaxe; From cd79775402d63170ad4f4c9734d180bf049ab85e Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 5 Jun 2020 14:13:53 +0200 Subject: [PATCH 13/18] Added Advanced Industrial Miner --- .../items/multiblocks/miner/ActiveMiner.java | 1 + .../miner/AdvancedIndustrialMiner.java | 34 +++++++++++++++++++ .../multiblocks/miner/IndustrialMiner.java | 1 + .../setup/SlimefunItemSetup.java | 2 ++ 4 files changed, 38 insertions(+) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/AdvancedIndustrialMiner.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java index 958e43578..a74fb86de 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java @@ -32,6 +32,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun; * @author TheBusyBiscuit * * @see IndustrialMiner + * @see AdvancedIndustrialMiner * */ class ActiveMiner implements Runnable { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/AdvancedIndustrialMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/AdvancedIndustrialMiner.java new file mode 100644 index 000000000..ee5cc9416 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/AdvancedIndustrialMiner.java @@ -0,0 +1,34 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; + +/** + * The {@link AdvancedIndustrialMiner} is a more advanced version of the {@link IndustrialMiner}. + * It uses Silk Touch and has a bigger range. + * + * @author TheBusyBiscuit + * + * @see IndustrialMiner + * @see ActiveMiner + * + */ +public class AdvancedIndustrialMiner extends IndustrialMiner { + + public AdvancedIndustrialMiner(Category category, SlimefunItemStack item) { + super(category, item, Material.DIAMOND_BLOCK, true, 5); + } + + @Override + protected void registerDefaultFuelTypes() { + fuelTypes.add(new MachineFuel(32, new ItemStack(Material.LAVA_BUCKET))); + fuelTypes.add(new MachineFuel(48, SlimefunItems.BUCKET_OF_OIL)); + fuelTypes.add(new MachineFuel(96, SlimefunItems.BUCKET_OF_FUEL)); + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java index 40d8bade7..eb0687738 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java @@ -36,6 +36,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; * * @author TheBusyBiscuit * + * @see AdvancedIndustrialMiner * @see ActiveMiner * */ 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 23e2bb2b2..224dd4977 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 @@ -143,6 +143,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreWa import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.PressureChamber; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Smeltery; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.TableSaw; +import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner.AdvancedIndustrialMiner; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner.IndustrialMiner; import io.github.thebusybiscuit.slimefun4.implementation.items.seasonal.ChristmasPresent; import io.github.thebusybiscuit.slimefun4.implementation.items.seasonal.EasterEgg; @@ -1024,6 +1025,7 @@ public final class SlimefunItemSetup { new AutomatedPanningMachine(categories.basicMachines).register(plugin); new IndustrialMiner(categories.basicMachines, SlimefunItems.INDUSTRIAL_MINER, Material.IRON_BLOCK, false, 3).register(plugin); + new AdvancedIndustrialMiner(categories.basicMachines, SlimefunItems.ADVANCED_INDUSTRIAL_MINER).register(plugin); new SlimefunItem(categories.magicalArmor, SlimefunItems.BOOTS_OF_THE_STOMPER, RecipeType.ARMOR_FORGE, new ItemStack[] {null, null, null, new ItemStack(Material.YELLOW_WOOL), null, new ItemStack(Material.YELLOW_WOOL), new ItemStack(Material.PISTON), null, new ItemStack(Material.PISTON)}) From fb58b5cf33b2550039acf75c85e0cfdd7aba7a82 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 5 Jun 2020 14:14:13 +0200 Subject: [PATCH 14/18] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c8429a2..f9a2c5e76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ * Added thai translations * Dried Kelp Blocks can now be used in the Coal Generator * Added Industrial Miner +* Added Advanced Industrial Miner #### Changes * Fixed a few memory leaks From ae0b04788f2f6057d2a9812b6b90ce98ecd327d2 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 5 Jun 2020 14:25:47 +0200 Subject: [PATCH 15/18] Fixed Unit Tests --- .../tests/listeners/TestBackpackListener.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestBackpackListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestBackpackListener.java index 715503635..399d62c03 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestBackpackListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestBackpackListener.java @@ -6,6 +6,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -28,13 +29,15 @@ import org.mockito.Mockito; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; -import io.github.thebusybiscuit.slimefun4.api.items.ItemState; import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack; import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListener; import io.github.thebusybiscuit.slimefun4.mocks.TestUtilities; import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class TestBackpackListener { @@ -70,19 +73,16 @@ public class TestBackpackListener { return ref.get(); } - private PlayerBackpack openMockBackpack(Player player, int size) throws InterruptedException { - ItemStack item = new CustomItem(Material.CHEST, "&4Mock Backpack", "", "&7Size: &e" + BACKPACK_SIZE, "&7ID: ", "", "&7&eRight Click&7 to open"); + private PlayerBackpack openMockBackpack(Player player, String id, int size) throws InterruptedException { + SlimefunItemStack item = new SlimefunItemStack(id, Material.CHEST, "&4Mock Backpack", "", "&7Size: &e" + BACKPACK_SIZE, "&7ID: ", "", "&7&eRight Click&7 to open"); PlayerProfile profile = TestUtilities.awaitProfile(player); PlayerBackpack backpack = profile.createBackpack(size); listener.setBackpackId(player, item, 2, backpack.getId()); - SlimefunBackpack slimefunBackpack = Mockito.mock(SlimefunBackpack.class); - Mockito.when(slimefunBackpack.getSize()).thenReturn(size); - - // This will make hasUnlocked() immediately pass - Mockito.when(slimefunBackpack.getState()).thenReturn(ItemState.VANILLA_FALLBACK); - SlimefunPlugin.getRegistry().getEnabledSlimefunItems().add(slimefunBackpack); + Category category = new Category(new NamespacedKey(plugin, "test_backpacks"), new CustomItem(Material.CHEST, "&4Test Backpacks")); + SlimefunBackpack slimefunBackpack = new SlimefunBackpack(size, category, item, RecipeType.NULL, new ItemStack[9]); + slimefunBackpack.register(plugin); listener.openBackpack(player, item, slimefunBackpack); return backpack; @@ -118,7 +118,7 @@ public class TestBackpackListener { @Test public void testOpenBackpack() throws InterruptedException { Player player = server.addPlayer(); - PlayerBackpack backpack = openMockBackpack(player, 27); + PlayerBackpack backpack = openMockBackpack(player, "TEST_OPEN_BACKPACK", 27); InventoryView view = player.getOpenInventory(); Assertions.assertEquals(backpack.getInventory(), view.getTopInventory()); } @@ -126,7 +126,7 @@ public class TestBackpackListener { @Test public void testCloseBackpack() throws InterruptedException { Player player = server.addPlayer(); - PlayerBackpack backpack = openMockBackpack(player, 27); + PlayerBackpack backpack = openMockBackpack(player, "TEST_CLOSE_BACKPACK", 27); listener.onClose(new InventoryCloseEvent(player.getOpenInventory())); Assertions.assertTrue(backpack.getOwner().isDirty()); @@ -135,7 +135,7 @@ public class TestBackpackListener { @Test public void testBackpackDropNormalItem() throws InterruptedException { Player player = server.addPlayer(); - openMockBackpack(player, 27); + openMockBackpack(player, "DROP_NORMAL_ITEM_BACKPACK_TEST", 27); Item item = Mockito.mock(Item.class); Mockito.when(item.getItemStack()).thenReturn(new ItemStack(Material.SUGAR_CANE)); @@ -145,9 +145,9 @@ public class TestBackpackListener { Assertions.assertFalse(event.isCancelled()); } - private boolean isAllowed(ItemStack item) throws InterruptedException { + private boolean isAllowed(String id, ItemStack item) throws InterruptedException { Player player = server.addPlayer(); - Inventory inv = openMockBackpack(player, 9).getInventory(); + Inventory inv = openMockBackpack(player, id, 9).getInventory(); int slot = 7; inv.setItem(slot, item); @@ -159,20 +159,20 @@ public class TestBackpackListener { @ParameterizedTest @EnumSource(value = Material.class, names = { "AIR", "DIAMOND", "STONE" }) public void areItemsAllowed(Material type) throws InterruptedException { - Assertions.assertTrue(isAllowed(new ItemStack(type))); + Assertions.assertTrue(isAllowed("BACKPACK_ALLOWANCE_" + type.name(), new ItemStack(type))); } @ParameterizedTest @EnumSource(value = Material.class, names = { "SHULKER_BOX", "RED_SHULKER_BOX", "BLUE_SHULKER_BOX", "BLACK_SHULKER_BOX" }) public void areShulkerBoxesAllowed(Material type) throws InterruptedException { - Assertions.assertFalse(isAllowed(new ItemStack(type))); + Assertions.assertFalse(isAllowed("BACKPACK_ALLOWANCE_" + type.name(), new ItemStack(type))); } @ParameterizedTest @EnumSource(value = Material.class, names = { "AIR", "SHULKER_BOX" }) public void testHotbarKey(Material type) throws InterruptedException { Player player = server.addPlayer(); - openMockBackpack(player, 9); + openMockBackpack(player, "BACKPACK_HOTBAR_" + type.name(), 9); int slot = 7; player.getInventory().setItem(slot, new ItemStack(type)); From 8bde659daf9cd5ccc67c26e988d75e682cc84b4e Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 5 Jun 2020 14:34:24 +0200 Subject: [PATCH 16/18] The Advanced Miner now preserves buckets --- .../implementation/items/multiblocks/miner/ActiveMiner.java | 5 +++++ .../items/multiblocks/miner/AdvancedIndustrialMiner.java | 6 +++--- .../java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java index a74fb86de..432bcfadc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java @@ -287,6 +287,11 @@ class ActiveMiner implements Runnable { if (fuelType.test(item)) { ItemUtils.consumeItem(item, false); + + if (miner instanceof AdvancedIndustrialMiner) { + inv.addItem(new ItemStack(Material.BUCKET)); + } + return fuelType.getTicks(); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/AdvancedIndustrialMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/AdvancedIndustrialMiner.java index ee5cc9416..33ae57580 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/AdvancedIndustrialMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/AdvancedIndustrialMiner.java @@ -26,9 +26,9 @@ public class AdvancedIndustrialMiner extends IndustrialMiner { @Override protected void registerDefaultFuelTypes() { - fuelTypes.add(new MachineFuel(32, new ItemStack(Material.LAVA_BUCKET))); - fuelTypes.add(new MachineFuel(48, SlimefunItems.BUCKET_OF_OIL)); - fuelTypes.add(new MachineFuel(96, SlimefunItems.BUCKET_OF_FUEL)); + fuelTypes.add(new MachineFuel(48, new ItemStack(Material.LAVA_BUCKET))); + fuelTypes.add(new MachineFuel(64, SlimefunItems.BUCKET_OF_OIL)); + fuelTypes.add(new MachineFuel(128, SlimefunItems.BUCKET_OF_FUEL)); } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index a070a6337..e83704354 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -530,7 +530,7 @@ public final class SlimefunItems { public static final SlimefunItemStack AUTOMATED_PANNING_MACHINE = new SlimefunItemStack("AUTOMATED_PANNING_MACHINE", Material.BOWL, "&eAutomated Panning Machine", "", "&rA MultiBlock Version of the Gold Pan", "&rand Nether Gold Pan combined in one machine."); public static final SlimefunItemStack INDUSTRIAL_MINER = new SlimefunItemStack("INDUSTRIAL_MINER", Material.GOLDEN_PICKAXE, "&bIndustrial Miner", "", "&rThis Multiblock will mine any Ores", "&rin a 7x7 area underneath it.", "&rPlace coal or similar in its chest", "&rto fuel this machine."); - public static final SlimefunItemStack ADVANCED_INDUSTRIAL_MINER = new SlimefunItemStack("ADVANCED_INDUSTRIAL_MINER", Material.DIAMOND_PICKAXE, "&cAdvanced Industrial Miner", "", "&rThis Multiblock will mine any Ores", "&rin a 11x11 area underneath it.", "&rPlace a bucket of fuel or lava in", "&r its chest to fuel this machine."); + public static final SlimefunItemStack ADVANCED_INDUSTRIAL_MINER = new SlimefunItemStack("ADVANCED_INDUSTRIAL_MINER", Material.DIAMOND_PICKAXE, "&cAdvanced Industrial Miner", "", "&rThis Multiblock will mine any Ores", "&rin a 11x11 area underneath it.", "&rPlace a bucket of fuel or lava in", "&rits chest to fuel this machine."); static { ItemMeta meta = INDUSTRIAL_MINER.getItemMeta(); From fcd17d3a5a2b4ed8a1b6599fa724450df03fa7e4 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 5 Jun 2020 14:37:31 +0200 Subject: [PATCH 17/18] Updated lore for advanced industrial miner --- .../java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index e83704354..d752901d2 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -530,7 +530,7 @@ public final class SlimefunItems { public static final SlimefunItemStack AUTOMATED_PANNING_MACHINE = new SlimefunItemStack("AUTOMATED_PANNING_MACHINE", Material.BOWL, "&eAutomated Panning Machine", "", "&rA MultiBlock Version of the Gold Pan", "&rand Nether Gold Pan combined in one machine."); public static final SlimefunItemStack INDUSTRIAL_MINER = new SlimefunItemStack("INDUSTRIAL_MINER", Material.GOLDEN_PICKAXE, "&bIndustrial Miner", "", "&rThis Multiblock will mine any Ores", "&rin a 7x7 area underneath it.", "&rPlace coal or similar in its chest", "&rto fuel this machine."); - public static final SlimefunItemStack ADVANCED_INDUSTRIAL_MINER = new SlimefunItemStack("ADVANCED_INDUSTRIAL_MINER", Material.DIAMOND_PICKAXE, "&cAdvanced Industrial Miner", "", "&rThis Multiblock will mine any Ores", "&rin a 11x11 area underneath it.", "&rPlace a bucket of fuel or lava in", "&rits chest to fuel this machine."); + public static final SlimefunItemStack ADVANCED_INDUSTRIAL_MINER = new SlimefunItemStack("ADVANCED_INDUSTRIAL_MINER", Material.DIAMOND_PICKAXE, "&cAdvanced Industrial Miner", "", "&rThis Multiblock will mine any Ores", "&rin a 11x11 area underneath it.", "&rPlace a bucket of fuel or lava in", "", "&a+ Silk Touch", "&rits chest to fuel this machine."); static { ItemMeta meta = INDUSTRIAL_MINER.getItemMeta(); From 615e0c07a2e963fbfc461d0bdf1a6b12f5bc134d Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 7 Jun 2020 17:48:10 +0200 Subject: [PATCH 18/18] Minor changes --- pom.xml | 2 +- .../items/multiblocks/miner/ActiveMiner.java | 53 ++++++++++--------- .../multiblocks/miner/IndustrialMiner.java | 4 +- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index b66b50fd4..849ecf9ed 100644 --- a/pom.xml +++ b/pom.xml @@ -302,7 +302,7 @@ com.github.thebusybiscuit CS-CoreLib2 - 0.20.4 + 0.21 compile diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java index 432bcfadc..70f5dce8d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java @@ -18,6 +18,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition; import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; @@ -47,26 +48,26 @@ class ActiveMiner implements Runnable { private final Block chest; private final Block[] pistons; - private final Location start; - private final Location end; + private final BlockPosition start; + private final BlockPosition end; private final int height; private int x; private int z; - public ActiveMiner(IndustrialMiner miner, UUID owner, Block chest, Block[] pistons, Location start, Location end) { + public ActiveMiner(IndustrialMiner miner, UUID owner, Block chest, Block[] pistons, Block start, Block end) { this.miner = miner; this.owner = owner; this.chest = chest; this.pistons = pistons; - this.start = start; - this.end = end; + this.start = new BlockPosition(start); + this.end = new BlockPosition(end); - this.height = start.getBlockY(); - this.x = start.getBlockX(); - this.z = start.getBlockZ(); + this.height = start.getY(); + this.x = start.getX(); + this.z = start.getZ(); } /** @@ -158,16 +159,16 @@ class ActiveMiner implements Runnable { return; } - try { - TaskQueue queue = new TaskQueue(); + TaskQueue queue = new TaskQueue(); - queue.thenRun(1, () -> setPistonState(pistons[0], true)); - queue.thenRun(3, () -> setPistonState(pistons[0], false)); + queue.thenRun(1, () -> setPistonState(pistons[0], true)); + queue.thenRun(3, () -> setPistonState(pistons[0], false)); - queue.thenRun(1, () -> setPistonState(pistons[1], true)); - queue.thenRun(3, () -> setPistonState(pistons[1], false)); + queue.thenRun(1, () -> setPistonState(pistons[1], true)); + queue.thenRun(3, () -> setPistonState(pistons[1], false)); - queue.thenRun(() -> { + queue.thenRun(() -> { + try { Block furnace = chest.getRelative(BlockFace.DOWN); furnace.getWorld().playEffect(furnace.getLocation(), Effect.STEP_SOUND, Material.STONE); @@ -194,25 +195,25 @@ class ActiveMiner implements Runnable { } nextColumn(); - }); + } + catch (Exception e) { + Slimefun.getLogger().log(Level.SEVERE, e, () -> "An Error occured while running an Industrial Miner at " + new BlockPosition(chest)); + stop(); + } + }); - queue.execute(SlimefunPlugin.instance); - } - catch (Exception e) { - Slimefun.getLogger().log(Level.SEVERE, "An Error occured while running an Industrial Miner", e); - stop(); - } + queue.execute(SlimefunPlugin.instance); } /** * This advanced the {@link IndustrialMiner} to the next column */ private void nextColumn() { - if (x < end.getBlockX()) { + if (x < end.getX()) { x++; } - else if (z < end.getBlockZ()) { - x = start.getBlockX(); + else if (z < end.getZ()) { + x = start.getX(); z++; } else { @@ -354,7 +355,7 @@ class ActiveMiner implements Runnable { } } catch (Exception e) { - Slimefun.getLogger().log(Level.SEVERE, "An Error occured while moving a Piston for an Industrial Miner", e); + Slimefun.getLogger().log(Level.SEVERE, e, () -> "An Error occured while moving a Piston for an Industrial Miner at " + new BlockPosition(block)); stop(); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java index eb0687738..87d789e5f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java @@ -180,8 +180,8 @@ public class IndustrialMiner extends MultiBlockMachine { Block[] pistons = findPistons(chest); int mod = getRange(); - Location start = b.getLocation().clone().add(-mod, -1, -mod); - Location end = b.getLocation().clone().add(mod, -1, mod); + Block start = b.getRelative(-mod, -1, -mod); + Block end = b.getRelative(mod, -1, mod); ActiveMiner instance = new ActiveMiner(this, p.getUniqueId(), chest, pistons, start, end); instance.start(b);