From 60064a0fe1b5b09eec2e40a6fa6d20aaecdc7475 Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Thu, 1 Aug 2019 11:01:43 +0200 Subject: [PATCH 1/5] Added OUTPUT_CHEST functionality S --- src/config.yml | 1 + .../Slimefun/Lists/SlimefunItems.java | 2 +- .../Objects/SlimefunItem/SlimefunMachine.java | 49 +++++- .../Slimefun/Setup/ResearchSetup.java | 1 + .../Slimefun/Setup/SlimefunSetup.java | 157 +++++++++++------- 5 files changed, 152 insertions(+), 58 deletions(-) diff --git a/src/config.yml b/src/config.yml index 7b2c23711..6440172a4 100644 --- a/src/config.yml +++ b/src/config.yml @@ -14,6 +14,7 @@ options: research-give-fireworks: true legacy-ore-washer: false legacy-dust-washer: false + legacy-machine-output: false guide: default-view-book: false URID: diff --git a/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index 5bbe51480..8812f8977 100644 --- a/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -376,7 +376,7 @@ public class SlimefunItems { public static ItemStack DIGITAL_MINER = new CustomItem(Material.IRON_PICKAXE, "&bDigital Miner", "", "&a&oDigs out everything!"); public static ItemStack ADVANCED_DIGITAL_MINER = new CustomItem(Material.DIAMOND_PICKAXE, "&6Advanced Digital Miner", "", "&a&oDigs out everything!", "&a&oAutomatically crushes your Ores"); public static ItemStack AUTOMATED_PANNING_MACHINE = new CustomItem(Material.BOWL, "&aAutomated Panning Machine", "", "&a&oA MultiBlock Version of the Gold Pan"); - + public static ItemStack OUTPUT_CHEST = new CustomItem(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 ItemStack HOLOGRAM_PROJECTOR = new CustomItem(Material.QUARTZ_SLAB, "&bHologram Projector", "", "&rProjects an Editable Hologram"); /* Enhanced Furnaces */ diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java index 212fd3dcb..d61e14bfa 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java @@ -2,11 +2,17 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem; import java.util.*; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.InvUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.MultiBlock; +import me.mrCookieSlime.Slimefun.api.BlockStorage; import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Chest; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; public class SlimefunMachine extends SlimefunItem { @@ -14,6 +20,15 @@ public class SlimefunMachine extends SlimefunItem { private List recipes; private List shownRecipes; private Material trigger; + //Adjacent blockfaces for iterative output chest checks + private static final BlockFace[] faces = { + BlockFace.DOWN, + BlockFace.UP, + BlockFace.NORTH, + BlockFace.EAST, + BlockFace.SOUTH, + BlockFace.WEST + }; public SlimefunMachine(Category category, ItemStack item, String id, ItemStack[] recipe, ItemStack[] machineRecipes, Material trigger) { super(category, item, id, RecipeType.MULTIBLOCK, recipe); @@ -47,6 +62,10 @@ public class SlimefunMachine extends SlimefunItem { return this.shownRecipes; } + public static BlockFace[] getFaces() { + return faces; + } + public void addRecipe(ItemStack[] input, ItemStack output) { this.recipes.add(input); this.recipes.add(new ItemStack[] {output}); @@ -80,5 +99,33 @@ public class SlimefunMachine extends SlimefunItem { public Iterator recipeIterator() { return this.recipes.iterator(); } - + + // Overloaded method for finding a potential output chest. Fallbacks to the old system of putting the adding back into the dispenser. + // Optional last argument Inventory placeCheckerInv is for multiblock machines that create a dummy inventory to check if there's a space for the adding, + // i.e. Enhanced crafting table + public static Inventory findValidOutputInv(ItemStack adding, Block dispBlock, Inventory dispInv) { + return findValidOutputInv(adding, dispBlock, dispInv, dispInv); + } + + public static Inventory findValidOutputInv(ItemStack product, Block dispBlock, Inventory dispInv, Inventory placeCheckerInv) { + Inventory outputInv = null; + for (BlockFace face : faces) { + Block potentialOutput = dispBlock.getRelative(face); + if (BlockStorage.hasBlockInfo(potentialOutput) && BlockStorage.checkID(potentialOutput).equals("OUTPUT_CHEST")) { + // Found the output chest! Now, let's check if we can fit the adding in it. + Inventory chestInv = ((Chest) potentialOutput.getState()).getInventory(); + if (InvUtils.fits(chestInv, product)) { + // It fits! Let's set the inventory to that now. + outputInv = chestInv; + } + } + } + // This if-clause will trigger if no suitable output chest was found. It's functionally the same as the old fit check for the dispenser, only refactored. + if (outputInv == null && InvUtils.fits(placeCheckerInv, product)) outputInv = dispInv; + + return outputInv; + + + } + } diff --git a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java index b66b4277c..88542f87f 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java @@ -235,5 +235,6 @@ public class ResearchSetup { Slimefun.registerResearch(new Research(236, "Nether Star Reactor", 60), SlimefunItems.NETHERSTAR_REACTOR); Slimefun.registerResearch(new Research(237, "Blistering Radioactivity", 38), SlimefunItems.BLISTERING_INGOT, SlimefunItems.BLISTERING_INGOT_2, SlimefunItems.BLISTERING_INGOT_3); Slimefun.registerResearch(new Research(239, "Automatic Ignition Chamber", 12), SlimefunItems.IGNITION_CHAMBER); + Slimefun.registerResearch(new Research(240, "Basic machinery output chest", 20), SlimefunItems.OUTPUT_CHEST); } } diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index dceb3071a..f590400a6 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -21,6 +21,7 @@ import org.bukkit.block.CreatureSpawner; import org.bukkit.block.Dispenser; import org.bukkit.block.Hopper; import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Levelled; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.ArmorStand; @@ -189,6 +190,10 @@ public class SlimefunSetup { new ItemStack[] {new ItemStack(Material.COOKIE), new ItemStack(Material.PAPER), null, null, null, null, null, null, null}) .register(true); + new SlimefunItem(Categories.MACHINES_1, SlimefunItems.OUTPUT_CHEST, "OUTPUT_CHEST", RecipeType.ENHANCED_CRAFTING_TABLE, + new ItemStack[] {SlimefunItems.LEAD_INGOT, new ItemStack(Material.HOPPER), SlimefunItems.LEAD_INGOT, SlimefunItems.LEAD_INGOT, new ItemStack(Material.CHEST), SlimefunItems.LEAD_INGOT, null, SlimefunItems.LEAD_INGOT, null}) + .register(true); + new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.ENHANCED_CRAFTING_TABLE, "ENHANCED_CRAFTING_TABLE", new ItemStack[] {null, null, null, null, new ItemStack(Material.CRAFTING_TABLE), null, null, new ItemStack(Material.DISPENSER), null}, new ItemStack[0], Material.CRAFTING_TABLE) @@ -202,9 +207,13 @@ public class SlimefunSetup { if (mb.isMultiBlock(machine)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { - Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); - - final Inventory inv = disp.getInventory(); + // Objects dispBlock and disp have been split up, in order to add the output chest functionallity, which is the only functionallity + // that is dependant on the dispenser's block methods. + // the Dispenser disp still remains the same though, and as such doesn't break any existing code which involves said object. + Block dispBlock = b.getRelative(BlockFace.DOWN); + Dispenser disp = (Dispenser) dispBlock.getState(); + Inventory inv = disp.getInventory(); + List inputs = RecipeType.getRecipeInputList(machine); for (int i = 0; i < inputs.size(); i++) { @@ -231,9 +240,11 @@ public class SlimefunSetup { for (int j = 0; j < inv.getContents().length; j++) { inv2.setItem(j, inv.getContents()[j] != null ? (inv.getContents()[j].getAmount() > 1 ? new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1): null): null); } - if (InvUtils.fits(inv2, adding)) { + + Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv, inv2); + + if (outputInv != null) { SlimefunItem sfItem = SlimefunItem.getByItem(adding); - if (sfItem instanceof SlimefunBackpack) { ItemStack backpack = null; @@ -300,7 +311,8 @@ public class SlimefunSetup { } p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1); - inv.addItem(adding); + outputInv.addItem(adding); + } else Messages.local.sendTranslation(p, "machines.full-inventory", true); } @@ -350,17 +362,19 @@ public class SlimefunSetup { if (mb.isMultiBlock(machine)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { - Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); + Block dispBlock = b.getRelative(BlockFace.DOWN); + Dispenser disp = (Dispenser) dispBlock.getState(); Inventory inv = disp.getInventory(); for (ItemStack current: inv.getContents()) { for (ItemStack convert: RecipeType.getRecipeInputs(machine)) { if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) { ItemStack output = RecipeType.getRecipeOutput(machine, convert); - if (InvUtils.fits(inv, output)) { + Inventory outputInv = SlimefunMachine.findValidOutputInv(output, dispBlock, inv); + if (outputInv != null) { ItemStack removing = current.clone(); removing.setAmount(1); inv.removeItem(removing); - inv.addItem(output); + outputInv.addItem(output); p.getWorld().playSound(p.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1); } else Messages.local.sendTranslation(p, "machines.full-inventory", true); @@ -391,8 +405,9 @@ public class SlimefunSetup { if (mb.isMultiBlock(machine)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { - Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); - final Inventory inv = disp.getInventory(); + Block dispBlock = b.getRelative(BlockFace.DOWN); + Dispenser disp = (Dispenser) dispBlock.getState(); + Inventory inv = disp.getInventory(); List inputs = RecipeType.getRecipeInputList(machine); for (int i = 0; i < inputs.size(); i++) { @@ -407,7 +422,8 @@ public class SlimefunSetup { if (craft) { final ItemStack adding = RecipeType.getRecipeOutputList(machine, inputs.get(i)).clone(); if (Slimefun.hasUnlocked(p, adding, true)) { - if (InvUtils.fits(inv, adding)) { + Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv); + if (outputInv != null) { for (ItemStack removing: inputs.get(i)) { if (removing != null) inv.removeItem(removing); } @@ -418,7 +434,7 @@ public class SlimefunSetup { p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ANVIL_USE, 1F, 2F); } else { p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F); - inv.addItem(adding); + outputInv.addItem(adding); } }, j*20L); } @@ -451,17 +467,19 @@ public class SlimefunSetup { if (mb.isMultiBlock(machine)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { - Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); + Block dispBlock = b.getRelative(BlockFace.DOWN); + Dispenser disp = (Dispenser) dispBlock.getState(); Inventory inv = disp.getInventory(); for (ItemStack current: inv.getContents()) { for (ItemStack convert: RecipeType.getRecipeInputs(machine)) { if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) { ItemStack adding = RecipeType.getRecipeOutput(machine, convert); - if (InvUtils.fits(inv, adding)) { + Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv); + if (outputInv != null) { ItemStack removing = current.clone(); removing.setAmount(convert.getAmount()); inv.removeItem(removing); - inv.addItem(adding); + outputInv.addItem(adding); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, 1); } else Messages.local.sendTranslation(p, "machines.full-inventory", true); @@ -492,13 +510,15 @@ public class SlimefunSetup { if (mb.isMultiBlock(machine)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { - Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); - final Inventory inv = disp.getInventory(); + Block dispBlock = b.getRelative(BlockFace.DOWN); + Dispenser disp = (Dispenser) dispBlock.getState(); + Inventory inv = disp.getInventory(); for (ItemStack current: inv.getContents()) { for (ItemStack convert: RecipeType.getRecipeInputs(machine)) { if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) { final ItemStack adding = RecipeType.getRecipeOutput(machine, convert); - if (InvUtils.fits(inv, adding)) { + Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv); + if (outputInv != null) { ItemStack removing = current.clone(); removing.setAmount(convert.getAmount()); inv.removeItem(removing); @@ -509,7 +529,7 @@ public class SlimefunSetup { p.getWorld().playSound(p.getLocation(), j == 1 ? Sound.BLOCK_PISTON_CONTRACT : Sound.BLOCK_PISTON_EXTEND, 1F, j == 0 ? 1F : 2F); } else { p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F); - inv.addItem(adding); + outputInv.addItem(adding); } }, i*20L); } @@ -709,7 +729,8 @@ public class SlimefunSetup { if (mb.isMultiBlock(machine)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { - Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); + Block dispBlock = b.getRelative(BlockFace.DOWN); + Dispenser disp = (Dispenser) dispBlock.getState(); Inventory inv = disp.getInventory(); List inputs = RecipeType.getRecipeInputList(machine); @@ -730,23 +751,27 @@ public class SlimefunSetup { if (craft) { ItemStack adding = RecipeType.getRecipeOutputList(machine, inputs.get(i)).clone(); if (Slimefun.hasUnlocked(p, adding, true)) { - if (InvUtils.fits(inv, adding)) { + Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv); + if (outputInv != null) { for (ItemStack removing: inputs.get(i)) { if (removing != null) inv.removeItem(removing); } - inv.addItem(adding); + outputInv.addItem(adding); p.getWorld().playSound(p.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); p.getWorld().playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1); - Block raw_disp = b.getRelative(BlockFace.DOWN); + // Block raw_disp = b.getRelative(BlockFace.DOWN); + // raw_disp has been removed since the outputInv functionality already uses such an object which is declared above as dispBlock. + // The chamber methods have been updated to reflect this change. + // Maybe this code snippet should be turned into a loop? Hopper chamber = null; - if (BlockStorage.check(raw_disp.getRelative(BlockFace.EAST).getState().getBlock(), "IGNITION_CHAMBER")) { - chamber = (Hopper) raw_disp.getRelative(BlockFace.EAST).getState(); - } else if (BlockStorage.check(raw_disp.getRelative(BlockFace.WEST).getState().getBlock(), "IGNITION_CHAMBER")) { - chamber = (Hopper) raw_disp.getRelative(BlockFace.WEST).getState(); - } else if (BlockStorage.check(raw_disp.getRelative(BlockFace.NORTH).getState().getBlock(), "IGNITION_CHAMBER")) { - chamber = (Hopper) raw_disp.getRelative(BlockFace.NORTH).getState(); - } else if (BlockStorage.check(raw_disp.getRelative(BlockFace.SOUTH).getState().getBlock(), "IGNITION_CHAMBER")){ - chamber = (Hopper) raw_disp.getRelative(BlockFace.SOUTH).getState(); + if (BlockStorage.check(dispBlock.getRelative(BlockFace.EAST).getState().getBlock(), "IGNITION_CHAMBER")) { + chamber = (Hopper) dispBlock.getRelative(BlockFace.EAST).getState(); + } else if (BlockStorage.check(dispBlock.getRelative(BlockFace.WEST).getState().getBlock(), "IGNITION_CHAMBER")) { + chamber = (Hopper) dispBlock.getRelative(BlockFace.WEST).getState(); + } else if (BlockStorage.check(dispBlock.getRelative(BlockFace.NORTH).getState().getBlock(), "IGNITION_CHAMBER")) { + chamber = (Hopper) dispBlock.getRelative(BlockFace.NORTH).getState(); + } else if (BlockStorage.check(dispBlock.getRelative(BlockFace.SOUTH).getState().getBlock(), "IGNITION_CHAMBER")){ + chamber = (Hopper) dispBlock.getRelative(BlockFace.SOUTH).getState(); } if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("SMELTERY", "chance.fireBreak"))) { @@ -810,13 +835,15 @@ public class SlimefunSetup { if (mb.isMultiBlock(machine)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { - Dispenser disp = (Dispenser) b.getRelative(BlockFace.UP).getRelative(BlockFace.UP).getState(); + Block dispBlock = b.getRelative(BlockFace.UP).getRelative(BlockFace.UP); + Dispenser disp = (Dispenser) dispBlock.getState(); final Inventory inv = disp.getInventory(); for (ItemStack current: inv.getContents()) { for (ItemStack convert: RecipeType.getRecipeInputs(machine)) { if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) { final ItemStack adding = RecipeType.getRecipeOutput(machine, convert); - if (InvUtils.fits(inv, adding)) { + Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv); + if (outputInv != null) { ItemStack removing = current.clone(); removing.setAmount(convert.getAmount()); inv.removeItem(removing); @@ -831,7 +858,7 @@ public class SlimefunSetup { p.getWorld().playSound(b.getLocation(), Sound.ENTITY_TNT_PRIMED, 1F, 1F); } else { p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F); - inv.addItem(adding); + outputInv.addItem(adding); } }, i*20L); } @@ -1130,13 +1157,14 @@ public class SlimefunSetup { if (mb.isMultiBlock(machine)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { - Dispenser disp = null; - - if (b.getRelative(1, 0, 0).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(1, 0, 0).getState(); - else if (b.getRelative(0, 0, 1).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(0, 0, 1).getState(); - else if (b.getRelative(-1, 0, 0).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(-1, 0, 0).getState(); - else if (b.getRelative(0, 0, -1).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(0, 0, -1).getState(); - + Block dispBlock = null; + // Maybe this could be implemented by instead looping over a BlockFace<> array? + if (b.getRelative(1, 0, 0).getType() == Material.DISPENSER) dispBlock = b.getRelative(1, 0, 0); + else if (b.getRelative(0, 0, 1).getType() == Material.DISPENSER) dispBlock = b.getRelative(0, 0, 1); + else if (b.getRelative(-1, 0, 0).getType() == Material.DISPENSER) dispBlock = b.getRelative(-1, 0, 0); + else if (b.getRelative(0, 0, -1).getType() == Material.DISPENSER) dispBlock = b.getRelative(0, 0, -1); + + Dispenser disp = (Dispenser) dispBlock.getState(); final Inventory inv = disp.getInventory(); List inputs = RecipeType.getRecipeInputList(machine); @@ -1164,7 +1192,8 @@ public class SlimefunSetup { for (int j = 0; j < inv.getContents().length; j++) { inv2.setItem(j, inv.getContents()[j] != null ? (inv.getContents()[j].getAmount() > 1 ? new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1): null): null); } - if (InvUtils.fits(inv2, adding)) { + Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv, inv2); + if (outputInv != null) { SlimefunItem sfItem = SlimefunItem.getByItem(adding); if (sfItem instanceof SlimefunBackpack) { @@ -1238,7 +1267,7 @@ public class SlimefunSetup { p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1F, 1F); } else { p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F); - inv.addItem(adding); + outputInv.addItem(adding); } }, j*20L); } @@ -1352,7 +1381,8 @@ public class SlimefunSetup { if (mb.isMultiBlock(machine)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { - Dispenser disp = (Dispenser) b.getRelative(BlockFace.UP).getState(); + Block dispBlock = b.getRelative(BlockFace.UP); + Dispenser disp = (Dispenser) dispBlock.getState(); Inventory inv = disp.getInventory(); for (ItemStack current: inv.getContents()) { if (current != null) { @@ -1366,26 +1396,38 @@ public class SlimefunSetup { else if (SlimefunStartup.chance(100, 25)) adding = SlimefunItems.MAGNESIUM_DUST; else if (SlimefunStartup.chance(100, 25)) adding = SlimefunItems.LEAD_DUST; else if (SlimefunStartup.chance(100, 25)) adding = SlimefunItems.SILVER_DUST; - - if (inv.firstEmpty() != -1 || (legacy_ore_washer && InvUtils.fits(inv, adding))) { + + Inventory outputInv = null; + + if (!legacy_ore_washer) { + // This is a fancy way of checking if there is empty space in the inv; by checking if an unobtainable item could fit in it. + // However, due to the way the method findValidOutputInv() functions, the dummyAdding will never actually be added to the real inventory, + // so it really doesn't matter what item the ItemStack is made by. SlimefunItems.DEBUG_FISH however, signals that it's + // not supposed to be given to the player. + ItemStack dummyAdding = SlimefunItems.DEBUG_FISH; + outputInv = SlimefunMachine.findValidOutputInv(dummyAdding, dispBlock, inv); + } else outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv); + + if (outputInv != null) { ItemStack removing = current.clone(); removing.setAmount(1); inv.removeItem(removing); - inv.addItem(adding); + outputInv.addItem(adding); p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER); - if (InvUtils.fits(inv, SlimefunItems.STONE_CHUNK)) inv.addItem(SlimefunItems.STONE_CHUNK); + if (InvUtils.fits(outputInv, SlimefunItems.STONE_CHUNK)) outputInv.addItem(SlimefunItems.STONE_CHUNK); } else Messages.local.sendTranslation(p, "machines.full-inventory", true); return true; } else if (SlimefunManager.isItemSimiliar(current, new ItemStack(Material.SAND, 4), false)) { ItemStack adding = SlimefunItems.SALT; - if (InvUtils.fits(inv, adding)) { + Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv); + if (outputInv != null) { ItemStack removing = current.clone(); removing.setAmount(4); inv.removeItem(removing); - inv.addItem(adding); + outputInv.addItem(adding); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER); p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1); } @@ -1394,11 +1436,12 @@ public class SlimefunSetup { } else if (SlimefunManager.isItemSimiliar(current, SlimefunItems.PULVERIZED_ORE, true)) { ItemStack adding = SlimefunItems.PURE_ORE_CLUSTER; - if (InvUtils.fits(inv, adding)) { + Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv); + if (outputInv != null) { ItemStack removing = current.clone(); removing.setAmount(1); inv.removeItem(removing); - inv.addItem(adding); + outputInv.addItem(adding); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER); p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1); } @@ -2535,17 +2578,19 @@ public class SlimefunSetup { if (mb.isMultiBlock(machine)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (Slimefun.hasUnlocked(p, SlimefunItems.JUICER, true)) { - Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); + Block dispBlock = b.getRelative(BlockFace.DOWN); + Dispenser disp = (Dispenser) dispBlock.getState(); Inventory inv = disp.getInventory(); for (ItemStack current: inv.getContents()) { for (ItemStack convert: RecipeType.getRecipeInputs(machine)) { if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) { ItemStack adding = RecipeType.getRecipeOutput(machine, convert); - if (InvUtils.fits(inv, adding)) { + Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv); + if (outputInv != null) { ItemStack removing = current.clone(); removing.setAmount(1); inv.removeItem(removing); - inv.addItem(adding); + outputInv.addItem(adding); p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.HAY_BLOCK); } From b9d8e8f5dd7606c85cefa6dde08f9a4a3cc1ac22 Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Thu, 1 Aug 2019 11:17:47 +0200 Subject: [PATCH 2/5] Update config.yml --- src/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/config.yml b/src/config.yml index 6440172a4..7b2c23711 100644 --- a/src/config.yml +++ b/src/config.yml @@ -14,7 +14,6 @@ options: research-give-fireworks: true legacy-ore-washer: false legacy-dust-washer: false - legacy-machine-output: false guide: default-view-book: false URID: From 00d376e213437e956d3e74d82534ddab5d9577a0 Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Thu, 1 Aug 2019 12:03:08 +0200 Subject: [PATCH 3/5] Update SlimefunMachine.java --- .../Slimefun/Objects/SlimefunItem/SlimefunMachine.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java index d61e14bfa..7e4002897 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java @@ -117,6 +117,7 @@ public class SlimefunMachine extends SlimefunItem { if (InvUtils.fits(chestInv, product)) { // It fits! Let's set the inventory to that now. outputInv = chestInv; + break; } } } From 8c8996368b9776face283c4e8b4e76ebd7cc6eba Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Sat, 3 Aug 2019 17:39:41 +0200 Subject: [PATCH 4/5] fix PR --- .../Objects/SlimefunItem/SlimefunMachine.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java index 7e4002897..7320703ae 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java @@ -11,7 +11,7 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.Chest; +import org.bukkit.block.Container; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -21,8 +21,7 @@ public class SlimefunMachine extends SlimefunItem { private List shownRecipes; private Material trigger; //Adjacent blockfaces for iterative output chest checks - private static final BlockFace[] faces = { - BlockFace.DOWN, + private static final BlockFace[] outputFaces = { BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, @@ -62,8 +61,8 @@ public class SlimefunMachine extends SlimefunItem { return this.shownRecipes; } - public static BlockFace[] getFaces() { - return faces; + public static BlockFace[] getOutputFaces() { + return outputFaces; } public void addRecipe(ItemStack[] input, ItemStack output) { @@ -109,14 +108,15 @@ public class SlimefunMachine extends SlimefunItem { public static Inventory findValidOutputInv(ItemStack product, Block dispBlock, Inventory dispInv, Inventory placeCheckerInv) { Inventory outputInv = null; - for (BlockFace face : faces) { + for (BlockFace face : outputFaces) { Block potentialOutput = dispBlock.getRelative(face); - if (BlockStorage.hasBlockInfo(potentialOutput) && BlockStorage.checkID(potentialOutput).equals("OUTPUT_CHEST")) { - // Found the output chest! Now, let's check if we can fit the adding in it. - Inventory chestInv = ((Chest) potentialOutput.getState()).getInventory(); - if (InvUtils.fits(chestInv, product)) { + String id = BlockStorage.checkID(potentialOutput); + if (id != null && id.equals("OUTPUT_CHEST")) { + // Found the output chest! Now, let's check if we can fit the product in it. + Inventory inv = ((Container) potentialOutput.getState()).getInventory(); + if (InvUtils.fits(inv, product)) { // It fits! Let's set the inventory to that now. - outputInv = chestInv; + outputInv = inv; break; } } From 50d74ced109579147b0e402f29db05b5f5b1427c Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Sat, 3 Aug 2019 17:52:10 +0200 Subject: [PATCH 5/5] Fixed indents --- .../Slimefun/Objects/SlimefunItem/SlimefunMachine.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java index 7320703ae..62a388806 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunMachine.java @@ -110,8 +110,8 @@ public class SlimefunMachine extends SlimefunItem { Inventory outputInv = null; for (BlockFace face : outputFaces) { Block potentialOutput = dispBlock.getRelative(face); - String id = BlockStorage.checkID(potentialOutput); - if (id != null && id.equals("OUTPUT_CHEST")) { + String id = BlockStorage.checkID(potentialOutput); + if (id != null && id.equals("OUTPUT_CHEST")) { // Found the output chest! Now, let's check if we can fit the product in it. Inventory inv = ((Container) potentialOutput.getState()).getInventory(); if (InvUtils.fits(inv, product)) {