From 839c263955c68fc480899ed3554ff2eb86d453b2 Mon Sep 17 00:00:00 2001 From: SoSeDiK Date: Sun, 23 Jun 2019 23:03:20 +0300 Subject: [PATCH 01/27] Replace SimpleJSON with Gson --- .../Slimefun/CSCoreLibSetup/CSCoreLibLoader.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/CSCoreLibSetup/CSCoreLibLoader.java b/src/me/mrCookieSlime/Slimefun/CSCoreLibSetup/CSCoreLibLoader.java index a5c8a1672..ce5cce8e4 100644 --- a/src/me/mrCookieSlime/Slimefun/CSCoreLibSetup/CSCoreLibLoader.java +++ b/src/me/mrCookieSlime/Slimefun/CSCoreLibSetup/CSCoreLibLoader.java @@ -12,9 +12,10 @@ import java.net.URL; import java.net.URLConnection; import org.bukkit.plugin.Plugin; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; public class CSCoreLibLoader { @@ -62,9 +63,11 @@ public class CSCoreLibLoader { connection.setDoOutput(true); final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - final JSONArray array = (JSONArray) JSONValue.parse(reader.readLine()); - download = traceURL(((String) ((JSONObject) array.get(array.size() - 1)).get("downloadUrl")).replace("https:", "http:")); - file = new File("plugins/" + (String) ((JSONObject) array.get(array.size() - 1)).get("name") + ".jar"); + final JsonArray array = new JsonParser().parse(reader).getAsJsonArray(); + final JsonObject json = array.get(array.size() - 1).getAsJsonObject(); + + download = traceURL(json.get("downloadUrl").getAsString().replace("https:", "http:")); + file = new File("plugins/" + json.get("name").getAsString() + ".jar"); return true; } catch (IOException e) { From 5bd6d614e4b9a5e7b54581bac6d79cef6bed4355 Mon Sep 17 00:00:00 2001 From: Omer Oreg Date: Thu, 27 Jun 2019 13:19:32 +0300 Subject: [PATCH 02/27] Added maven source plugin * This allows the viewing of the sources from within an IDE when building against Slimefun. --- pom.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pom.xml b/pom.xml index c101a3788..986f4308c 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,20 @@ ${project.name} v${project.version} + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + ${basedir}/src From e1190a5d1e4b545cbe4b0ed1dfa1a37926a2f8da Mon Sep 17 00:00:00 2001 From: Nathan Adhitya Date: Mon, 8 Jul 2019 17:07:38 +0700 Subject: [PATCH 03/27] Update ItemListener.java --- .../Slimefun/listeners/ItemListener.java | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/listeners/ItemListener.java b/src/me/mrCookieSlime/Slimefun/listeners/ItemListener.java index c0c632326..451133fb8 100644 --- a/src/me/mrCookieSlime/Slimefun/listeners/ItemListener.java +++ b/src/me/mrCookieSlime/Slimefun/listeners/ItemListener.java @@ -75,6 +75,29 @@ public class ItemListener implements Listener { } } + @EventHandler + public void onGrindstone(InventoryClickEvent e){ + if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.GRINDSTONE) { + ItemStack slot0 = e.getInventory().getContents()[0]; + ItemStack slot1 = e.getInventory().getContents()[1]; + if (SlimefunItem.getByItem(slot0) != null && !SlimefunItem.isDisabled(slot0)) + e.setCancelled(true); + else if (SlimefunItem.getByItem(slot1) != null && !SlimefunItem.isDisabled(slot1)) + e.setCancelled(true); + + + if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.BOOK), true)) + e.setCancelled(true); + else if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.CHEST), true)) + e.setCancelled(true); + + if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.BOOK), true)) + e.setCancelled(true); + else if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.CHEST), true)) + e.setCancelled(true); + } + } + @EventHandler public void debug(PlayerInteractEvent e) { if (e.getAction().equals(Action.PHYSICAL) || !e.getHand().equals(EquipmentSlot.HAND)) return; @@ -388,8 +411,30 @@ public class ItemListener implements Listener { @EventHandler public void onAnvil(InventoryClickEvent e) { if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.ANVIL) { - if (SlimefunManager.isItemSimiliar(e.getInventory().getContents()[0], SlimefunItems.ELYTRA, true)) return; - if (SlimefunItem.getByItem(e.getInventory().getContents()[0]) != null && !SlimefunItem.isDisabled(e.getInventory().getContents()[0])) { + ItemStack slot0 = e.getInventory().getContents()[0]; + ItemStack slot1 = e.getInventory().getContents()[1]; + if (SlimefunManager.isItemSimiliar(slot0, SlimefunItems.ELYTRA, true)) return; + if (SlimefunItem.getByItem(slot0) != null && !SlimefunItem.isDisabled(slot0)) { + e.setCancelled(true); + Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true); + } else if (SlimefunItem.getByItem(slot1) != null && !SlimefunItem.isDisabled(slot1)) { + e.setCancelled(true); + Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true); + } + + + if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.BOOK), true)) { + e.setCancelled(true); + Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true); + } else if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.CHEST), true)) { + e.setCancelled(true); + Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true); + } + + if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.BOOK), true)) { + e.setCancelled(true); + Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true); + } else if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.CHEST), true)) { e.setCancelled(true); Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true); } From bf61b4a42f379357fb48b30b802399d952f7406c Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Wed, 17 Jul 2019 14:57:52 +0200 Subject: [PATCH 04/27] Added GitHubBuilds-Updater for development-builds --- pom.xml | 112 +++++++++++------- .../Slimefun/Android/ProgrammableAndroid.java | 4 +- .../Slimefun/Android/ScriptPart.java | 4 +- .../Slimefun/SlimefunStartup.java | 27 ++++- 4 files changed, 93 insertions(+), 54 deletions(-) diff --git a/pom.xml b/pom.xml index 986f4308c..f72d6634b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 me.mrCookieSlime Slimefun - 4.1.17 + DEV - 100 (git null) 1.8 1.8 @@ -30,15 +30,14 @@ jitpack.io https://jitpack.io + + CodeMC + https://repo.codemc.org/repository/maven-public + + ${project.basedir}/src - ${project.basedir}/tests/java - - - ${project.basedir}/tests/resources - - ${project.name} v${project.version} @@ -53,7 +52,45 @@ + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + + + com.github.thebusybiscuit:CS-CoreLib2 + + **/cscorelib2/updater/** + + + + + + + org.bstats + me.mrCookieSlime.Slimefun.bstats + + + + io.github.thebusybiscuit.cscorelib2 + me.mrCookieSlime.Slimefun.cscorelib2 + + + + + + + package + + shade + + + + + ${basedir}/src @@ -69,76 +106,59 @@ org.bukkit bukkit + 1.14.2-R0.1-SNAPSHOT provided com.sk89q.worldedit worldedit-bukkit + 7.0.0 + provided com.github.TheBusyBiscuit CS-CoreLib + v1.6.1 + provided + + com.github.thebusybiscuit + CS-CoreLib2 + 0.3.6 + compile + + + org.bstats + bstats-bukkit + 1.5 + compile + me.minebuilders clearlag-core + 2.9.7 system ${project.basedir}/lib/Clearlag.jar net.coreprotect coreprotect + 2.16.3 + provided me.mrCookieSlime EmeraldEnchants + 2.0 system ${project.basedir}/lib/EmeraldEnchants v2.0.jar me.mrCookieSlime ExoticGarden + 1.2.0 system ${project.basedir}/lib/ExoticGarden v1.2.0.jar - - - - org.bukkit - bukkit - 1.14.2-R0.1-SNAPSHOT - - - com.sk89q.worldedit - worldedit-bukkit - 7.0.0 - - - com.github.TheBusyBiscuit - CS-CoreLib - v1.6.1 - - - me.minebuilders - clearlag-core - 2.9.7 - - - net.coreprotect - coreprotect - 2.16.3 - - - me.mrCookieSlime - EmeraldEnchants - 2.0 - - - me.mrCookieSlime - ExoticGarden - 1.2.0 - - - diff --git a/src/me/mrCookieSlime/Slimefun/Android/ProgrammableAndroid.java b/src/me/mrCookieSlime/Slimefun/Android/ProgrammableAndroid.java index 3aef8cc12..c2431eea2 100644 --- a/src/me/mrCookieSlime/Slimefun/Android/ProgrammableAndroid.java +++ b/src/me/mrCookieSlime/Slimefun/Android/ProgrammableAndroid.java @@ -20,10 +20,10 @@ import org.bukkit.OfflinePlayer; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.data.Ageable; -import org.bukkit.block.data.Rotatable; import org.bukkit.block.Dispenser; import org.bukkit.block.Skull; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.Rotatable; import org.bukkit.entity.Animals; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; diff --git a/src/me/mrCookieSlime/Slimefun/Android/ScriptPart.java b/src/me/mrCookieSlime/Slimefun/Android/ScriptPart.java index f1d521c4c..f311e7364 100644 --- a/src/me/mrCookieSlime/Slimefun/Android/ScriptPart.java +++ b/src/me/mrCookieSlime/Slimefun/Android/ScriptPart.java @@ -1,10 +1,10 @@ package me.mrCookieSlime.Slimefun.Android; +import org.bukkit.inventory.ItemStack; + import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; -import org.bukkit.inventory.ItemStack; - public enum ScriptPart { // Start and End Parts diff --git a/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java b/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java index 58d61014c..bad0fa403 100644 --- a/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java +++ b/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java @@ -2,6 +2,7 @@ package me.mrCookieSlime.Slimefun; import java.io.File; +import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -10,6 +11,9 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import io.github.thebusybiscuit.cscorelib2.updater.BukkitUpdater; +import io.github.thebusybiscuit.cscorelib2.updater.GitHubBuildsUpdater; +import io.github.thebusybiscuit.cscorelib2.updater.Updater; import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; import me.mrCookieSlime.CSCoreLibPlugin.PluginUtils; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; @@ -151,14 +155,29 @@ public class SlimefunStartup extends JavaPlugin { researches = new Config(Files.RESEARCHES); items = new Config(Files.ITEMS); whitelist = new Config(Files.WHITELIST); - - // Init Config, Updater, Metrics and messages.yml - utils.setupUpdater(53485, getFile()); - utils.setupMetrics(); + + // Setup Config and messages.yml utils.setupLocalization(); config = utils.getConfig(); Messages.local = utils.getLocalization(); Messages.setup(); + + // Setting up bStats + new Metrics(this); + + // Setting up the Auto-Updater + Updater updater; + + if (!getDescription().getVersion().startsWith("DEV - ")) { + // We are using an official build, use the BukkitDev Updater + updater = new BukkitUpdater(this, getFile(), 53485); + } + else { + // If we are using a development build, we want to switch to our custom + updater = new GitHubBuildsUpdater(this, getFile(), "TheBusyBiscuit/Slimefun4/master"); + } + + if (config.getBoolean("options.auto-update")) updater.start(); // Creating all necessary Folders String[] storage = {"blocks", "stored-blocks", "stored-inventories", "stored-chunks", "universal-inventories", "waypoints", "block-backups"}; From d0fa9a53fdff0b4396b8d9ad11708780720c1c4c Mon Sep 17 00:00:00 2001 From: dniym Date: Tue, 30 Jul 2019 12:43:17 -0400 Subject: [PATCH 05/27] Added a new basic machine to replace the Saw Mill Sawmill was obsolete and could not be easily reworked to allow for new minecraft logs. --- .../Slimefun/Setup/SlimefunSetup.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index dceb3071a..f2b269b1c 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -14,6 +14,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Chest; @@ -1831,7 +1832,37 @@ public class SlimefunSetup { else return false; } }); + + new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.TABLE_SAW, "TABLE_SAW", + new ItemStack[] {null, null, null, new ItemStack(Material.BIRCH_SLAB), new ItemStack(Material.STONECUTTER), new ItemStack(Material.BIRCH_SLAB), null, new ItemStack(Material.IRON_BLOCK), null}, + new ItemStack[] {}, Material.STONECUTTER) + .register(true, new MultiBlockInteractionHandler() { + @Override + public boolean onInteract(Player p, MultiBlock mb, Block b) { + if (mb.isMultiBlock(SlimefunItem.getByID("TABLE_SAW"))) { + if (CSCoreLib.getLib().getProtectionManager().canBuild(p.getUniqueId(), b.getRelative(BlockFace.UP), true)) { + if (Slimefun.hasUnlocked(p, SlimefunItems.TABLE_SAW, true)) { + if(p.getInventory().getItemInMainHand() != null && Tag.LOGS.getValues().contains(p.getInventory().getItemInMainHand().getType())) { + ItemStack log = p.getInventory().getItemInMainHand(); + + ItemStack item = new ItemStack(MaterialHelper.getWoodFromLog(log.getType()), 8); + b.getWorld().dropItemNaturally(b.getLocation(), item); + b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, log.getType()); + log.setAmount(log.getAmount() -1); + if(log.getAmount() <= 0) + p.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); + + + } + } + } + return true; + } + else return false; + } + }); + new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.SAW_MILL, "SAW_MILL", new ItemStack[] {null, null, null, new ItemStack(Material.IRON_BARS), new ItemStack(Material.OAK_LOG), new ItemStack(Material.IRON_BARS), new ItemStack(Material.OAK_LOG), new ItemStack(Material.CRAFTING_TABLE), new ItemStack(Material.OAK_LOG)}, new ItemStack[] {}, Material.CRAFTING_TABLE) From bd4732281b63b6465efe22530e1e6a734a9f3219 Mon Sep 17 00:00:00 2001 From: dniym Date: Tue, 30 Jul 2019 12:49:04 -0400 Subject: [PATCH 06/27] Set SAW_MILL to be hidden in the slimefun guide --- src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index f2b269b1c..25f68485d 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -1863,9 +1863,17 @@ public class SlimefunSetup { } }); + /* + * dNiym 7/30/2019 added the Table_Saw machine to replace the Saw_mill, as the sawmill's design does not work with + * the new types of log's in minecraft. Now that there are multiple types with their own object ID the existing + * way of detecting multi blocks limits us to using specific material types in a build, therefore having a block that + * needs to change like for the sawmill is not possible to do without major overhauling of multiblocks. The Saw_Mill + * machine has been left in as to not break machines on existing servers however it should no longer show up in the + * slimefun guide. + */ new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.SAW_MILL, "SAW_MILL", new ItemStack[] {null, null, null, new ItemStack(Material.IRON_BARS), new ItemStack(Material.OAK_LOG), new ItemStack(Material.IRON_BARS), new ItemStack(Material.OAK_LOG), new ItemStack(Material.CRAFTING_TABLE), new ItemStack(Material.OAK_LOG)}, - new ItemStack[] {}, Material.CRAFTING_TABLE) + new ItemStack[] {}, Material.CRAFTING_TABLE,true) .register(true, new MultiBlockInteractionHandler() { @Override From 6db2e48e648c8140a1c23e04cad57dfcf1d57931 Mon Sep 17 00:00:00 2001 From: dniym Date: Tue, 30 Jul 2019 12:50:36 -0400 Subject: [PATCH 07/27] Add Table_Saw to the SlimeFunItems List --- src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index 5bbe51480..0ffff211d 100644 --- a/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -365,7 +365,8 @@ public class SlimefunItems { public static ItemStack PRESSURE_CHAMBER = new CustomItem(Material.GLASS, "&bPressure Chamber", "", "&a&oCompresses Items even more"); public static ItemStack MAGIC_WORKBENCH = new CustomItem(Material.CRAFTING_TABLE, "&6Magic Workbench", "Infuses Items with magical Energy"); public static ItemStack ORE_WASHER = new CustomItem(Material.CAULDRON, "&6Ore Washer", "", "&a&oWashes Sifted Ore to filter Ores", "&a&oand gives you small Stone Chunks"); - public static ItemStack SAW_MILL = new CustomItem(Material.IRON_BARS, "&6Saw Mill", "", "&a&oAllows you to get 8 planks from 1 Log"); + public static ItemStack TABLE_SAW = new CustomItem(Material.STONECUTTER, "&6Table Saw", "", "&a&oAllows you get 8 planks from 1 Log", "&a&o(Works with all log types)"); + public static ItemStack SAW_MILL = new CustomItem(Material.BARRIER, "&6Saw Mill", "", "&a&oObsolete Use Table Saw Instead"); public static ItemStack COMPOSTER = new CustomItem(Material.CAULDRON, "&aComposter", "", "&a&oCan convert various Materials over Time..."); public static ItemStack ENHANCED_CRAFTING_TABLE = new CustomItem(Material.CRAFTING_TABLE, "&eEnhanced Crafting Table", "", "&a&oA regular Crafting Table cannot", "&a&ohold this massive Amount of Power..."); public static ItemStack CRUCIBLE = new CustomItem(Material.CAULDRON, "&cCrucible", "", "&a&oUsed to smelt Items into Liquids"); From 1386849d7de0abe7f55fe9a649c4834fa4b6ba7d Mon Sep 17 00:00:00 2001 From: dniym Date: Tue, 30 Jul 2019 12:53:03 -0400 Subject: [PATCH 08/27] Replace Saw_Mill with Table_Saw machine Replaced saw_mill machine with new table_saw machine in the research, to allow players who previously unlocked the saw_mill to craft it's replacement. --- src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java index b66b4277c..847d02a43 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java @@ -94,7 +94,7 @@ public class ResearchSetup { Slimefun.registerResearch(new Research(89, "Night Vision Goggles", 10), SlimefunItems.NIGHT_VISION_GOGGLES); Slimefun.registerResearch(new Research(90, "Pickaxe of Containment", 14), SlimefunItems.PICKAXE_OF_CONTAINMENT, SlimefunItems.BROKEN_SPAWNER); Slimefun.registerResearch(new Research(91, "Hercules Pickaxe", 28), SlimefunItems.HERCULES_PICKAXE); - Slimefun.registerResearch(new Research(92, "Saw Mill", 2), SlimefunItems.SAW_MILL); + Slimefun.registerResearch(new Research(92, "Table Saw", 2), SlimefunItems.TABLE_SAW); Slimefun.registerResearch(new Research(93, "Slimy Steel Armor", 27), SlimefunItems.SLIME_HELMET_STEEL, SlimefunItems.SLIME_CHESTPLATE_STEEL, SlimefunItems.SLIME_LEGGINGS_STEEL, SlimefunItems.SLIME_BOOTS_STEEL); Slimefun.registerResearch(new Research(94, "Blade of Vampires", 26), SlimefunItems.BLADE_OF_VAMPIRES); Slimefun.registerResearch(new Research(95, "Lazy Mining", 40), SlimefunItems.DIGITAL_MINER); From 60064a0fe1b5b09eec2e40a6fa6d20aaecdc7475 Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Thu, 1 Aug 2019 11:01:43 +0200 Subject: [PATCH 09/27] 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 10/27] 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 11/27] 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 78cea97fff723229e2af028c6397dca4daaeba7d Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Fri, 2 Aug 2019 13:20:28 +0200 Subject: [PATCH 12/27] Add copper wires --- src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java | 2 ++ src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java | 3 ++- src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java | 9 +++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index 5bbe51480..fcc0906fe 100644 --- a/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -234,6 +234,8 @@ public class SlimefunItems { public static ItemStack ANCIENT_PEDESTAL = new CustomItem(Material.DISPENSER, "&dAncient Pedestal", "", "&5Part of the Ancient Altar"); public static ItemStack ANCIENT_ALTAR = new CustomItem(Material.ENCHANTING_TABLE, "&dAncient Altar", "", "&5Multi-Block Altar for", "&5magical Crafting Processes"); public static ItemStack DUCT_TAPE = null; + public static ItemStack COPPER_WIRE = new CustomItem(Material.STRING, "&6Copper Wire", "", "&6Crucial component in electric modules"); + public static ItemStack RAINBOW_WOOL = new CustomItem(Material.WHITE_WOOL, "&5Rainbow Wool", "", "&dCycles through all Colors of the Rainbow!"); public static ItemStack RAINBOW_GLASS = new CustomItem(Material.WHITE_STAINED_GLASS, "&5Rainbow Glass", "", "&dCycles through all Colors of the Rainbow!"); diff --git a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java index b66b4277c..fcbf0bd92 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java @@ -234,6 +234,7 @@ public class ResearchSetup { Slimefun.registerResearch(new Research(235, "Nether Ice Coolant", 45), SlimefunItems.NETHER_ICE, SlimefunItems.ENRICHED_NETHER_ICE, SlimefunItems.NETHER_ICE_COOLANT_CELL, SlimefunItems.NETHER_DRILL); 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(239, "Automatic Ignition Chamber", 12), SlimefunItems.IGNITION_CHAMBER); + Slimefun.registerResearch(new Research(241, "Thinned-down Conductivity", 15), SlimefunItems.COPPER_WIRE); // Skips 1 to make room for eventual output_chest (see pull request) } } diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index dceb3071a..acff06ce2 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -2679,13 +2679,18 @@ public class SlimefunSetup { .register(true); new SlimefunItem(Categories.TECH_MISC, SlimefunItems.ELECTRIC_MOTOR, "ELECTRIC_MOTOR", RecipeType.ENHANCED_CRAFTING_TABLE, - new ItemStack[] {SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, null, SlimefunItems.ELECTRO_MAGNET, null, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT}) + new ItemStack[] {SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, null, SlimefunItems.ELECTRO_MAGNET, null, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE}) .register(true); new SlimefunItem(Categories.TECH_MISC, SlimefunItems.HEATING_COIL, "HEATING_COIL", RecipeType.ENHANCED_CRAFTING_TABLE, - new ItemStack[] {SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT}) + new ItemStack[] {SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE}) .register(true); + new SlimefunItem(Categories.TECH_MISC, SlimefunItems.COPPER_WIRE, "COPPER_WIRE", RecipeType.ENHANCED_CRAFTING_TABLE, + new ItemStack[] {null, null, null, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, null, null, null}, new CustomItem(SlimefunItems.COPPER_WIRE, 8)) + .register(true); + + @SuppressWarnings("unchecked") final String[] blockPlacerBlacklist = Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks") != null ? ((List) Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks")).toArray(new String[((List) Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks")).size()]) : new String[] {"STRUCTURE_BLOCK"}; From 09b961ad1ded7c3dbca0cddd9dc0c75d82870c60 Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Fri, 2 Aug 2019 14:55:07 +0200 Subject: [PATCH 13/27] Added sandstone to grind stone --- src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index dceb3071a..daf026740 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -338,7 +338,7 @@ public class SlimefunSetup { new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.GRIND_STONE, "GRIND_STONE", new ItemStack[] {null, null, null, null, new ItemStack(Material.OAK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null}, - new ItemStack[] {new ItemStack(Material.BLAZE_ROD), new ItemStack(Material.BLAZE_POWDER, 4), new ItemStack(Material.BONE), new ItemStack(Material.BONE_MEAL, 4), new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT), new ItemStack(Material.NETHER_WART), new CustomItem(SlimefunItems.MAGIC_LUMP_1, 2), new ItemStack(Material.ENDER_EYE), new CustomItem(SlimefunItems.ENDER_LUMP_1, 2), new ItemStack(Material.COBBLESTONE), new ItemStack(Material.GRAVEL), new ItemStack(Material.WHEAT), SlimefunItems.WHEAT_FLOUR, new ItemStack(Material.DIRT), SlimefunItems.STONE_CHUNK}, + new ItemStack[] {new ItemStack(Material.BLAZE_ROD), new ItemStack(Material.BLAZE_POWDER, 4), new ItemStack(Material.BONE), new ItemStack(Material.BONE_MEAL, 4), new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT), new ItemStack(Material.NETHER_WART), new CustomItem(SlimefunItems.MAGIC_LUMP_1, 2), new ItemStack(Material.ENDER_EYE), new CustomItem(SlimefunItems.ENDER_LUMP_1, 2), new ItemStack(Material.COBBLESTONE), new ItemStack(Material.GRAVEL), new ItemStack(Material.WHEAT), SlimefunItems.WHEAT_FLOUR, new ItemStack(Material.DIRT), SlimefunItems.STONE_CHUNK, new ItemStack(Material.SANDSTONE), new ItemStack(Material.SAND, 4), new ItemStack(Material.RED_SANDSTONE), new ItemStack(Material.RED_SAND, 4)}, Material.OAK_FENCE) .register(true, new MultiBlockInteractionHandler() { @@ -4217,7 +4217,7 @@ public class SlimefunSetup { .register(true); new SlimefunItem(Categories.MAGIC, SlimefunItems.INFERNAL_BONEMEAL, "INFERNAL_BONEMEAL", RecipeType.ANCIENT_ALTAR, - new ItemStack[] {new ItemStack(Material.NETHER_WART), SlimefunItems.RUNE_EARTH, new ItemStack(Material.NETHER_WART), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.BONE_MEAL), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.NETHER_WART), new ItemStack(Material.BLAZE_POWDER), new ItemStack(Material.NETHER_WART)}, new CustomItem(SlimefunItems.INFERNAL_BONEMEAL, 8)) + new ItemStack[] {new ItemStack(Material.NETHER_WART), SlimefunItems.RUNE_EARTH, new ItemStack(Material.NETHER_WART), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.BONE_MEAL), new CustomItem(SlimefunItems.MAGIC_LUMP_2), new ItemStack(Material.NETHER_WART), new ItemStack(Material.BLAZE_POWDER), new ItemStack(Material.NETHER_WART)}, new CustomItem(SlimefunItems.INFERNAL_BONEMEAL, 8)) .register(true, new ItemInteractionHandler() { @Override From 6af9307fe18ab5c9836788c66ed0c94faf365475 Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Fri, 2 Aug 2019 15:04:22 +0200 Subject: [PATCH 14/27] Accidentally edited a LOC --- src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index daf026740..ece2fc50f 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -4217,7 +4217,7 @@ public class SlimefunSetup { .register(true); new SlimefunItem(Categories.MAGIC, SlimefunItems.INFERNAL_BONEMEAL, "INFERNAL_BONEMEAL", RecipeType.ANCIENT_ALTAR, - new ItemStack[] {new ItemStack(Material.NETHER_WART), SlimefunItems.RUNE_EARTH, new ItemStack(Material.NETHER_WART), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.BONE_MEAL), new CustomItem(SlimefunItems.MAGIC_LUMP_2), new ItemStack(Material.NETHER_WART), new ItemStack(Material.BLAZE_POWDER), new ItemStack(Material.NETHER_WART)}, new CustomItem(SlimefunItems.INFERNAL_BONEMEAL, 8)) + new ItemStack[] {new ItemStack(Material.NETHER_WART), SlimefunItems.RUNE_EARTH, new ItemStack(Material.NETHER_WART), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.BONE_MEAL), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.NETHER_WART), new ItemStack(Material.BLAZE_POWDER), new ItemStack(Material.NETHER_WART)}, new CustomItem(SlimefunItems.INFERNAL_BONEMEAL, 8)) .register(true, new ItemInteractionHandler() { @Override From 5eaf3949b7c4da4a49835f7db01c0aede95c9070 Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Sat, 3 Aug 2019 17:02:32 +0200 Subject: [PATCH 15/27] Fixed research indent --- src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java index fcbf0bd92..18deca9a3 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java @@ -234,7 +234,7 @@ public class ResearchSetup { Slimefun.registerResearch(new Research(235, "Nether Ice Coolant", 45), SlimefunItems.NETHER_ICE, SlimefunItems.ENRICHED_NETHER_ICE, SlimefunItems.NETHER_ICE_COOLANT_CELL, SlimefunItems.NETHER_DRILL); 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(241, "Thinned-down Conductivity", 15), SlimefunItems.COPPER_WIRE); // Skips 1 to make room for eventual output_chest (see pull request) + Slimefun.registerResearch(new Research(239, "Automatic Ignition Chamber", 12), SlimefunItems.IGNITION_CHAMBER); + Slimefun.registerResearch(new Research(241, "Thinned-down Conductivity", 15), SlimefunItems.COPPER_WIRE); // Skips 1 to make room for eventual output_chest (see pull request) } } From 460c082a51f99afd8e805d902390865a3b051ac8 Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Sat, 3 Aug 2019 17:03:54 +0200 Subject: [PATCH 16/27] Fixed research indent #2 --- src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java index 18deca9a3..9a30dedc1 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java @@ -10,7 +10,7 @@ import org.bukkit.inventory.ItemStack; public class ResearchSetup { public static void setupResearches() { - Slimefun.registerResearch(new Research(0, "Walking Sticks", 1), SlimefunItems.GRANDMAS_WALKING_STICK, SlimefunItems.GRANDPAS_WALKING_STICK); + Slimefun.registerResearch(new Research(0, "Walking Sticks", 1), SlimefunItems.GRANDMAS_WALKING_STICK, SlimefunItems.GRANDPAS_WALKING_STICK); Slimefun.registerResearch(new Research(1, "Portable Crafter", 1), SlimefunItems.PORTABLE_CRAFTER); Slimefun.registerResearch(new Research(2, "Fortune Cookie", 1), SlimefunItems.FORTUNE_COOKIE); Slimefun.registerResearch(new Research(4, "Portable Dustbin", 2), SlimefunItems.PORTABLE_DUSTBIN); From 8c8996368b9776face283c4e8b4e76ebd7cc6eba Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Sat, 3 Aug 2019 17:39:41 +0200 Subject: [PATCH 17/27] 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 18/27] 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)) { From 1f3f2c635de6eadc18a08c039a1dba7f718d2266 Mon Sep 17 00:00:00 2001 From: dNiym Date: Sat, 3 Aug 2019 12:54:45 -0400 Subject: [PATCH 19/27] Fix Altar Item Swap Exploit --- .../AncientAltar/RitualAnimation.java | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/AncientAltar/RitualAnimation.java b/src/me/mrCookieSlime/Slimefun/AncientAltar/RitualAnimation.java index 112e9e177..27593c7c2 100644 --- a/src/me/mrCookieSlime/Slimefun/AncientAltar/RitualAnimation.java +++ b/src/me/mrCookieSlime/Slimefun/AncientAltar/RitualAnimation.java @@ -1,13 +1,19 @@ package me.mrCookieSlime.Slimefun.AncientAltar; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import me.mrCookieSlime.Slimefun.SlimefunStartup; import me.mrCookieSlime.Slimefun.listeners.AncientAltarListener; import me.mrCookieSlime.Slimefun.Variables; -import org.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.entity.Item; import org.bukkit.inventory.ItemStack; @@ -23,6 +29,7 @@ public class RitualAnimation implements Runnable { List items; List particles; + Map itemLock = new HashMap<>(); boolean running; int stage; @@ -38,11 +45,17 @@ public class RitualAnimation implements Runnable { this.running = true; this.stage = 0; + for(Block ped:this.pedestals) { + Item itm = AncientAltarListener.findItem(ped); + this.itemLock.put(itm, itm.getLocation().clone()); + } } @Override public void run() { idle(); + if(!checkLockedItems()) + abort(); if(this.stage == 36) { finish(); return; @@ -54,6 +67,15 @@ public class RitualAnimation implements Runnable { SlimefunStartup.instance.getServer().getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, this, 8); } + private boolean checkLockedItems() { + + for(Item itm:this.itemLock.keySet()) + if(itm.getLocation().distance(this.itemLock.get(itm)) > 0.3) + return false; + + return true; + } + private void idle() { try { l.getWorld().spawnParticle(Particle.SPELL_WITCH, l,16, 1.2F, 0F, 1.2F); @@ -69,7 +91,12 @@ public class RitualAnimation implements Runnable { private void checkPedestal(Block pedestal) { Item item = AncientAltarListener.findItem(pedestal); - if (item == null) abort(); + + + if(item == null || itemLock.remove(item) == null) { + abort(); + } + else { particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5)); items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName())); @@ -81,8 +108,10 @@ public class RitualAnimation implements Runnable { } catch (Exception e) { e.printStackTrace(); } - + + itemLock.remove(item); item.remove(); + pedestal.removeMetadata("item_placed", SlimefunStartup.instance); } } @@ -96,6 +125,7 @@ public class RitualAnimation implements Runnable { Variables.altarinuse.remove(altar.getLocation()); // should re-enable altar blocks on craft failure. l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 5F, 1F); + itemLock.clear(); altars.remove(altar); } @@ -115,4 +145,4 @@ public class RitualAnimation implements Runnable { l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 1F); } } -} \ No newline at end of file +} From 8af503acebd75a90385c926d106efa6900ce04d1 Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Sat, 3 Aug 2019 18:59:47 +0200 Subject: [PATCH 20/27] Fix spawner dupe and objectified e.getBock() --- src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index e41e7fbb8..23a4d0338 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -1837,17 +1837,19 @@ public class SlimefunSetup { @Override public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List drops) { if (SlimefunManager.isItemSimiliar(item, SlimefunItems.PICKAXE_OF_CONTAINMENT, true)) { - if (e.getBlock().getType() != Material.SPAWNER) return true; - BlockStorage.clearBlockInfo(e.getBlock()); + Block b = e.getBlock(); // Refactored it into this so we don't need to call e.getBlock() all the time. + if (b.getType() != Material.SPAWNER || BlockStorage.hasBlockInfo(b)) return true; + // If the spawner's BlockStorage has BlockInfo, then it's not a vanilla spawner and shouldn't give a broken spawner. + BlockStorage.clearBlockInfo(b); ItemStack spawner = SlimefunItems.BROKEN_SPAWNER.clone(); ItemMeta im = spawner.getItemMeta(); List lore = im.getLore(); for (int i = 0; i < lore.size(); i++) { - if (lore.get(i).contains("")) lore.set(i, lore.get(i).replace("", StringUtils.format(((CreatureSpawner) e.getBlock().getState()).getSpawnedType().toString()))); + if (lore.get(i).contains("")) lore.set(i, lore.get(i).replace("", StringUtils.format(((CreatureSpawner) b.getState()).getSpawnedType().toString()))); } im.setLore(lore); spawner.setItemMeta(im); - e.getBlock().getLocation().getWorld().dropItemNaturally(e.getBlock().getLocation(), spawner); + b.getLocation().getWorld().dropItemNaturally(b.getLocation(), spawner); e.setExpToDrop(0); return true; } From bcbeafba53acce1dd31327a748d53503ec4c95a9 Mon Sep 17 00:00:00 2001 From: dNiym Date: Sat, 3 Aug 2019 13:05:23 -0400 Subject: [PATCH 21/27] made requested changes --- src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java | 2 +- src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index 0ffff211d..f77162b38 100644 --- a/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -366,7 +366,7 @@ public class SlimefunItems { public static ItemStack MAGIC_WORKBENCH = new CustomItem(Material.CRAFTING_TABLE, "&6Magic Workbench", "Infuses Items with magical Energy"); public static ItemStack ORE_WASHER = new CustomItem(Material.CAULDRON, "&6Ore Washer", "", "&a&oWashes Sifted Ore to filter Ores", "&a&oand gives you small Stone Chunks"); public static ItemStack TABLE_SAW = new CustomItem(Material.STONECUTTER, "&6Table Saw", "", "&a&oAllows you get 8 planks from 1 Log", "&a&o(Works with all log types)"); - public static ItemStack SAW_MILL = new CustomItem(Material.BARRIER, "&6Saw Mill", "", "&a&oObsolete Use Table Saw Instead"); + public static ItemStack SAW_MILL = new CustomItem(Material.BARRIER, "&6Saw Mill", "", "&cObsolete! Use the Table Saw instead"); public static ItemStack COMPOSTER = new CustomItem(Material.CAULDRON, "&aComposter", "", "&a&oCan convert various Materials over Time..."); public static ItemStack ENHANCED_CRAFTING_TABLE = new CustomItem(Material.CRAFTING_TABLE, "&eEnhanced Crafting Table", "", "&a&oA regular Crafting Table cannot", "&a&ohold this massive Amount of Power..."); public static ItemStack CRUCIBLE = new CustomItem(Material.CAULDRON, "&cCrucible", "", "&a&oUsed to smelt Items into Liquids"); diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index 25f68485d..72d0ef886 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -1834,7 +1834,7 @@ public class SlimefunSetup { }); new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.TABLE_SAW, "TABLE_SAW", - new ItemStack[] {null, null, null, new ItemStack(Material.BIRCH_SLAB), new ItemStack(Material.STONECUTTER), new ItemStack(Material.BIRCH_SLAB), null, new ItemStack(Material.IRON_BLOCK), null}, + new ItemStack[] {null, null, null, new ItemStack(Material.STONE_SLAB), new ItemStack(Material.STONECUTTER), new ItemStack(Material.STONE_SLAB), null, new ItemStack(Material.IRON_BLOCK), null}, new ItemStack[] {}, Material.STONECUTTER) .register(true, new MultiBlockInteractionHandler() { @@ -1873,7 +1873,7 @@ public class SlimefunSetup { */ new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.SAW_MILL, "SAW_MILL", new ItemStack[] {null, null, null, new ItemStack(Material.IRON_BARS), new ItemStack(Material.OAK_LOG), new ItemStack(Material.IRON_BARS), new ItemStack(Material.OAK_LOG), new ItemStack(Material.CRAFTING_TABLE), new ItemStack(Material.OAK_LOG)}, - new ItemStack[] {}, Material.CRAFTING_TABLE,true) + new ItemStack[] {}, Material.CRAFTING_TABLE) .register(true, new MultiBlockInteractionHandler() { @Override From 4d326f5228e8f1f8cc65eee7421b5c37c6073d76 Mon Sep 17 00:00:00 2001 From: dNiym Date: Sat, 3 Aug 2019 13:19:10 -0400 Subject: [PATCH 22/27] Fixing revert, no idea how that happened. --- .../Slimefun/Setup/SlimefunSetup.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index dceb3071a..e97b8df94 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -14,6 +14,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Chest; @@ -3611,30 +3612,30 @@ public class SlimefunSetup { registerFuel(new MachineFuel(3, new ItemStack(Material.POTATO))); registerFuel(new MachineFuel(3, new ItemStack(Material.SUGAR_CANE))); registerFuel(new MachineFuel(3, new ItemStack(Material.NETHER_WART))); - registerFuel(new MachineFuel(2, new ItemStack(Material.DANDELION))); - registerFuel(new MachineFuel(2, new ItemStack(Material.POPPY))); registerFuel(new MachineFuel(2, new ItemStack(Material.RED_MUSHROOM))); registerFuel(new MachineFuel(2, new ItemStack(Material.BROWN_MUSHROOM))); registerFuel(new MachineFuel(2, new ItemStack(Material.VINE))); registerFuel(new MachineFuel(2, new ItemStack(Material.CACTUS))); registerFuel(new MachineFuel(2, new ItemStack(Material.LILY_PAD))); registerFuel(new MachineFuel(8, new ItemStack(Material.CHORUS_FRUIT))); + registerFuel(new MachineFuel(1, new ItemStack(Material.BAMBOO))); + registerFuel(new MachineFuel(1, new ItemStack(Material.KELP))); + registerFuel(new MachineFuel(2, new ItemStack(Material.DRIED_KELP))); + registerFuel(new MachineFuel(20, new ItemStack(Material.DRIED_KELP_BLOCK))); + registerFuel(new MachineFuel(1, new ItemStack(Material.SEAGRASS))); + registerFuel(new MachineFuel(2, new ItemStack(Material.SEA_PICKLE))); // Leaves - registerFuel(new MachineFuel(1, new ItemStack(Material.OAK_LEAVES))); - registerFuel(new MachineFuel(1, new ItemStack(Material.BIRCH_LEAVES))); - registerFuel(new MachineFuel(1, new ItemStack(Material.SPRUCE_LEAVES))); - registerFuel(new MachineFuel(1, new ItemStack(Material.JUNGLE_LEAVES))); - registerFuel(new MachineFuel(1, new ItemStack(Material.ACACIA_LEAVES))); - registerFuel(new MachineFuel(1, new ItemStack(Material.DARK_OAK_LEAVES))); + for(Material m:Tag.LEAVES.getValues()) + registerFuel(new MachineFuel(1, new ItemStack(m))); // Saplings - registerFuel(new MachineFuel(1, new ItemStack(Material.OAK_SAPLING))); - registerFuel(new MachineFuel(1, new ItemStack(Material.BIRCH_SAPLING))); - registerFuel(new MachineFuel(1, new ItemStack(Material.SPRUCE_SAPLING))); - registerFuel(new MachineFuel(1, new ItemStack(Material.JUNGLE_SAPLING))); - registerFuel(new MachineFuel(1, new ItemStack(Material.ACACIA_SAPLING))); - registerFuel(new MachineFuel(1, new ItemStack(Material.DARK_OAK_SAPLING))); + for (Material m:Tag.SAPLINGS.getValues()) + registerFuel(new MachineFuel(1, new ItemStack(m))); + + // Small Flowers (formally just dandelions and poppies. + for(Material m:Tag.SMALL_FLOWERS.getValues()) + registerFuel(new MachineFuel(1, new ItemStack(m))); } @Override From 640915d85a20dc4fbfe790b25d9eee67e470ba6d Mon Sep 17 00:00:00 2001 From: dNiym Date: Sat, 3 Aug 2019 13:27:46 -0400 Subject: [PATCH 23/27] Fix issue #966 (Trying again) --- .../machines/AdvancedCargoOutputNode.java | 411 ++++++++-------- .../SlimefunItem/machines/CargoInputNode.java | 446 +++++++++--------- 2 files changed, 439 insertions(+), 418 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/AdvancedCargoOutputNode.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/AdvancedCargoOutputNode.java index e096b582a..8f4ee7b96 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/AdvancedCargoOutputNode.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/AdvancedCargoOutputNode.java @@ -1,200 +1,211 @@ -package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines; - -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; -import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper; -import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; -import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; -import me.mrCookieSlime.Slimefun.Lists.RecipeType; -import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; -import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; -import me.mrCookieSlime.Slimefun.Setup.Messages; -import me.mrCookieSlime.Slimefun.api.BlockStorage; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; -import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet; -import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; - -public class AdvancedCargoOutputNode extends SlimefunItem { - - private static final int[] border = {0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 24, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53}; - - public AdvancedCargoOutputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) { - super(category, item, name, recipeType, recipe, recipeOutput); - - new BlockMenuPreset(name, "&cOutput Node") { - - @Override - public void init() { - constructMenu(this); - } - - @Override - public void newInstance(final BlockMenu menu, final Block b) { - try { - if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) { - menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.WHITE_WOOL), "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist")); - menu.addMenuClickHandler(15, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-type", "blacklist"); - newInstance(menu, b); - return false; - }); - } - else { - menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.BLACK_WOOL), "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist")); - menu.addMenuClickHandler(15, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-type", "whitelist"); - newInstance(menu, b); - return false; - }); - } - - if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) { - menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.STONE_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match")); - menu.addMenuClickHandler(16, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-durability", "true"); - newInstance(menu, b); - return false; - }); - } - else { - menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.GOLDEN_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match")); - menu.addMenuClickHandler(16, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-durability", "false"); - newInstance(menu, b); - return false; - }); - } - - if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) { - menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match")); - menu.addMenuClickHandler(25, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-lore", "false"); - newInstance(menu, b); - return false; - }); - } - else { - menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match")); - menu.addMenuClickHandler(25, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-lore", "true"); - newInstance(menu, b); - return false; - }); - } - - menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&bChannel", "", "&e> Click to decrease the Channel ID by 1")); - menu.addMenuClickHandler(41, (p, slot, item, action) -> { - int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1; - if (channel < 0) { - if (CargoNet.EXTRA_CHANNELS) channel = 16; - else channel = 15; - } - BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel)); - newInstance(menu, b); - return false; - }); - - int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")))); - - if (channel == 16) { - menu.replaceExistingItem(42, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1))); - menu.addMenuClickHandler(42, - (p, slot, item, action) -> false - ); - } - else { - menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialHelper.WoolColours[channel]), "&bChannel ID: &3" + (channel + 1))); - menu.addMenuClickHandler(42, - (p, slot, item, action) -> false - ); - } - - menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&bChannel", "", "&e> Click to increase the Channel ID by 1")); - menu.addMenuClickHandler(43, (p, slot, item, action) -> { - int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1; - - if (CargoNet.EXTRA_CHANNELS) { - if (channeln > 16) channeln = 0; - } - else { - if (channeln > 15) channeln = 0; - } - - BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln)); - newInstance(menu, b); - return false; - }); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public boolean canOpen(Block b, Player p) { - boolean open = CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b) || p.hasPermission("slimefun.cargo.bypass"); - if (!open) { - Messages.local.sendTranslation(p, "inventory.no-access", true); - } - return open; - } - - @Override - public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) { - return new int[0]; - } - }; - - registerBlockHandler(name, new SlimefunBlockHandler() { - - @Override - public void onPlace(Player p, Block b, SlimefunItem item) { - BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString()); - BlockStorage.addBlockInfo(b, "index", "0"); - BlockStorage.addBlockInfo(b, "frequency", "0"); - BlockStorage.addBlockInfo(b, "filter-type", "whitelist"); - BlockStorage.addBlockInfo(b, "filter-lore", "true"); - BlockStorage.addBlockInfo(b, "filter-durability", "false"); - } - - @Override - public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { - BlockMenu inv = BlockStorage.getInventory(b); - if (inv != null) { - for (int slot: getInputSlots()) { - if (inv.getItemInSlot(slot) != null) { - b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); - inv.replaceExistingItem(slot, null); - } - } - } - return true; - } - }); - } - - protected void constructMenu(BlockMenuPreset preset) { - for (int i : border) { - preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - } - - preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), - (p, slot, item, action) -> false - ); - } - - public int[] getInputSlots() { - return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39}; - } - -} +package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; + +import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; +import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; +import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; +import me.mrCookieSlime.Slimefun.Setup.Messages; +import me.mrCookieSlime.Slimefun.api.BlockStorage; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; +import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet; +import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; + +public class AdvancedCargoOutputNode extends SlimefunItem { + + private static final int[] border = {0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 24, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53}; + + public AdvancedCargoOutputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) { + super(category, item, name, recipeType, recipe, recipeOutput); + + new BlockMenuPreset(name, "&cOutput Node") { + + @Override + public void init() { + constructMenu(this); + } + + @Override + public void newInstance(final BlockMenu menu, final Block b) { + try { + if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) { + menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.WHITE_WOOL), "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist")); + menu.addMenuClickHandler(15, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-type", "blacklist"); + newInstance(menu, b); + return false; + }); + } + else { + menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.BLACK_WOOL), "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist")); + menu.addMenuClickHandler(15, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-type", "whitelist"); + newInstance(menu, b); + return false; + }); + } + + if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) { + ItemStack is = new ItemStack(Material.STONE_SWORD); + Damageable dmg = (Damageable) is.getItemMeta(); + dmg.setDamage(20); + is.setItemMeta((ItemMeta) dmg); + + menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match")); + menu.addMenuClickHandler(16, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-durability", "true"); + newInstance(menu, b); + return false; + }); + } + else { + ItemStack is = new ItemStack(Material.GOLDEN_SWORD); + Damageable dmg = (Damageable) is.getItemMeta(); + dmg.setDamage(20); + is.setItemMeta((ItemMeta) dmg); + menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match")); + menu.addMenuClickHandler(16, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-durability", "false"); + newInstance(menu, b); + return false; + }); + } + + if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) { + menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match")); + menu.addMenuClickHandler(25, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-lore", "false"); + newInstance(menu, b); + return false; + }); + } + else { + menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match")); + menu.addMenuClickHandler(25, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-lore", "true"); + newInstance(menu, b); + return false; + }); + } + + menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&bChannel", "", "&e> Click to decrease the Channel ID by 1")); + menu.addMenuClickHandler(41, (p, slot, item, action) -> { + int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1; + if (channel < 0) { + if (CargoNet.EXTRA_CHANNELS) channel = 16; + else channel = 15; + } + BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel)); + newInstance(menu, b); + return false; + }); + + int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")))); + + if (channel == 16) { + menu.replaceExistingItem(42, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1))); + menu.addMenuClickHandler(42, + (p, slot, item, action) -> false + ); + } + else { + menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialHelper.WoolColours[channel]), "&bChannel ID: &3" + (channel + 1))); + menu.addMenuClickHandler(42, + (p, slot, item, action) -> false + ); + } + + menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&bChannel", "", "&e> Click to increase the Channel ID by 1")); + menu.addMenuClickHandler(43, (p, slot, item, action) -> { + int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1; + + if (CargoNet.EXTRA_CHANNELS) { + if (channeln > 16) channeln = 0; + } + else { + if (channeln > 15) channeln = 0; + } + + BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln)); + newInstance(menu, b); + return false; + }); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public boolean canOpen(Block b, Player p) { + boolean open = CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b) || p.hasPermission("slimefun.cargo.bypass"); + if (!open) { + Messages.local.sendTranslation(p, "inventory.no-access", true); + } + return open; + } + + @Override + public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) { + return new int[0]; + } + }; + + registerBlockHandler(name, new SlimefunBlockHandler() { + + @Override + public void onPlace(Player p, Block b, SlimefunItem item) { + BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString()); + BlockStorage.addBlockInfo(b, "index", "0"); + BlockStorage.addBlockInfo(b, "frequency", "0"); + BlockStorage.addBlockInfo(b, "filter-type", "whitelist"); + BlockStorage.addBlockInfo(b, "filter-lore", "true"); + BlockStorage.addBlockInfo(b, "filter-durability", "false"); + } + + @Override + public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { + BlockMenu inv = BlockStorage.getInventory(b); + if (inv != null) { + for (int slot: getInputSlots()) { + if (inv.getItemInSlot(slot) != null) { + b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); + inv.replaceExistingItem(slot, null); + } + } + } + return true; + } + }); + } + + protected void constructMenu(BlockMenuPreset preset) { + for (int i : border) { + preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + } + + preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), + (p, slot, item, action) -> false + ); + } + + public int[] getInputSlots() { + return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39}; + } + +} diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/CargoInputNode.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/CargoInputNode.java index 2efecd289..d45135d47 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/CargoInputNode.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/CargoInputNode.java @@ -1,218 +1,228 @@ -package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines; - -import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; -import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; -import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; -import me.mrCookieSlime.Slimefun.Lists.RecipeType; -import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; -import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; -import me.mrCookieSlime.Slimefun.Setup.Messages; -import me.mrCookieSlime.Slimefun.api.BlockStorage; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; -import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet; -import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; - -public class CargoInputNode extends SlimefunItem { - - private static final int[] border = {0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53}; - - public CargoInputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) { - super(category, item, name, recipeType, recipe, recipeOutput); - - new BlockMenuPreset(name, "&3Input Node") { - - @Override - public void init() { - constructMenu(this); - } - - @Override - public void newInstance(final BlockMenu menu, final Block b) { - try { - if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) { - menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.WHITE_WOOL), "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist")); - menu.addMenuClickHandler(15, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-type", "blacklist"); - newInstance(menu, b); - return false; - }); - } - else { - menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.BLACK_WOOL), "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist")); - menu.addMenuClickHandler(15, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-type", "whitelist"); - newInstance(menu, b); - return false; - }); - } - - if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) { - menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.STONE_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match")); - menu.addMenuClickHandler(16, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-durability", "true"); - newInstance(menu, b); - return false; - }); - } - else { - menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.GOLDEN_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match")); - menu.addMenuClickHandler(16, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-durability", "false"); - newInstance(menu, b); - return false; - }); - } - - if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "round-robin") == null || BlockStorage.getLocationInfo(b.getLocation(), "round-robin").equals("false")) { - menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&7Round-Robin Mode: &4\u2718", "", "&e> Click to enable Round Robin Mode", "&e(Items will be equally distributed on the Channel)")); - menu.addMenuClickHandler(24, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "round-robin", "true"); - newInstance(menu, b); - return false; - }); - } - else { - menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&7Round-Robin Mode: &2\u2714", "", "&e> Click to disable Round Robin Mode", "&e(Items will be equally distributed on the Channel)")); - menu.addMenuClickHandler(24, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "round-robin", "false"); - newInstance(menu, b); - return false; - }); - } - - if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) { - menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match")); - menu.addMenuClickHandler(25, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-lore", "false"); - newInstance(menu, b); - return false; - }); - } - else { - menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match")); - menu.addMenuClickHandler(25, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "filter-lore", "true"); - newInstance(menu, b); - return false; - }); - } - - menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&bChannel", "", "&e> Click to decrease the Channel ID by 1")); - menu.addMenuClickHandler(41, (p, slot, item, action) -> { - int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1; - if (channel < 0) { - if (CargoNet.EXTRA_CHANNELS) channel = 16; - else channel = 15; - } - BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel)); - newInstance(menu, b); - return false; - }); - - int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")))); - - if (channel == 16) { - menu.replaceExistingItem(42, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1))); - menu.addMenuClickHandler(42, - (p, slot, item, action) -> false - ); - } - else { - menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialHelper.WoolColours[channel]), "&bChannel ID: &3" + (channel + 1))); - menu.addMenuClickHandler(42, - (p, slot, item, action) -> false - ); - } - - menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&bChannel", "", "&e> Click to increase the Channel ID by 1")); - menu.addMenuClickHandler(43, (p, slot, item, action) -> { - int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1; - - if (CargoNet.EXTRA_CHANNELS) { - if (channeln > 16) channeln = 0; - } - else { - if (channeln > 15) channeln = 0; - } - - BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln)); - newInstance(menu, b); - return false; - }); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public boolean canOpen(Block b, Player p) { - boolean open = CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b) || p.hasPermission("slimefun.cargo.bypass"); - if (!open) { - Messages.local.sendTranslation(p, "inventory.no-access", true); - } - return open; - } - - @Override - public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) { - return new int[0]; - } - }; - - registerBlockHandler(name, new SlimefunBlockHandler() { - - @Override - public void onPlace(Player p, Block b, SlimefunItem item) { - BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString()); - BlockStorage.addBlockInfo(b, "index", "0"); - BlockStorage.addBlockInfo(b, "frequency", "0"); - BlockStorage.addBlockInfo(b, "filter-type", "whitelist"); - BlockStorage.addBlockInfo(b, "filter-lore", "true"); - BlockStorage.addBlockInfo(b, "filter-durability", "false"); - BlockStorage.addBlockInfo(b, "round-robin", "false"); - } - - @Override - public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { - BlockMenu inv = BlockStorage.getInventory(b); - if (inv != null) { - for (int slot : getInputSlots()) { - if (inv.getItemInSlot(slot) != null) { - b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); - inv.replaceExistingItem(slot, null); - } - } - } - return true; - } - }); - } - - protected void constructMenu(BlockMenuPreset preset) { - for (int i : border) { - preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - } - - preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), - (p, slot, item, action) -> false - ); - } - - public int[] getInputSlots() { - return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39}; - } - -} +package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines; + +import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; + +import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; +import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; +import me.mrCookieSlime.Slimefun.Setup.Messages; +import me.mrCookieSlime.Slimefun.api.BlockStorage; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; +import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet; +import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; + +public class CargoInputNode extends SlimefunItem { + + private static final int[] border = {0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53}; + + public CargoInputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) { + super(category, item, name, recipeType, recipe, recipeOutput); + + new BlockMenuPreset(name, "&3Input Node") { + + @Override + public void init() { + constructMenu(this); + } + + @Override + public void newInstance(final BlockMenu menu, final Block b) { + try { + if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) { + menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.WHITE_WOOL), "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist")); + menu.addMenuClickHandler(15, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-type", "blacklist"); + newInstance(menu, b); + return false; + }); + } + else { + menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.BLACK_WOOL), "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist")); + menu.addMenuClickHandler(15, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-type", "whitelist"); + newInstance(menu, b); + return false; + }); + } + + if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) { + ItemStack is = new ItemStack(Material.STONE_SWORD); + Damageable dmg = (Damageable) is.getItemMeta(); + dmg.setDamage(20); + is.setItemMeta((ItemMeta) dmg); + menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match")); + menu.addMenuClickHandler(16, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-durability", "true"); + newInstance(menu, b); + return false; + }); + } + else { + ItemStack is = new ItemStack(Material.GOLDEN_SWORD); + Damageable dmg = (Damageable) is.getItemMeta(); + dmg.setDamage(20); + is.setItemMeta((ItemMeta) dmg); + menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match")); + menu.addMenuClickHandler(16, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-durability", "false"); + newInstance(menu, b); + return false; + }); + } + + if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "round-robin") == null || BlockStorage.getLocationInfo(b.getLocation(), "round-robin").equals("false")) { + menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&7Round-Robin Mode: &4\u2718", "", "&e> Click to enable Round Robin Mode", "&e(Items will be equally distributed on the Channel)")); + menu.addMenuClickHandler(24, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "round-robin", "true"); + newInstance(menu, b); + return false; + }); + } + else { + menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&7Round-Robin Mode: &2\u2714", "", "&e> Click to disable Round Robin Mode", "&e(Items will be equally distributed on the Channel)")); + menu.addMenuClickHandler(24, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "round-robin", "false"); + newInstance(menu, b); + return false; + }); + } + + if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) { + menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match")); + menu.addMenuClickHandler(25, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-lore", "false"); + newInstance(menu, b); + return false; + }); + } + else { + menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match")); + menu.addMenuClickHandler(25, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "filter-lore", "true"); + newInstance(menu, b); + return false; + }); + } + + menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&bChannel", "", "&e> Click to decrease the Channel ID by 1")); + menu.addMenuClickHandler(41, (p, slot, item, action) -> { + int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1; + if (channel < 0) { + if (CargoNet.EXTRA_CHANNELS) channel = 16; + else channel = 15; + } + BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel)); + newInstance(menu, b); + return false; + }); + + int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")))); + + if (channel == 16) { + menu.replaceExistingItem(42, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1))); + menu.addMenuClickHandler(42, + (p, slot, item, action) -> false + ); + } + else { + menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialHelper.WoolColours[channel]), "&bChannel ID: &3" + (channel + 1))); + menu.addMenuClickHandler(42, + (p, slot, item, action) -> false + ); + } + + menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&bChannel", "", "&e> Click to increase the Channel ID by 1")); + menu.addMenuClickHandler(43, (p, slot, item, action) -> { + int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1; + + if (CargoNet.EXTRA_CHANNELS) { + if (channeln > 16) channeln = 0; + } + else { + if (channeln > 15) channeln = 0; + } + + BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln)); + newInstance(menu, b); + return false; + }); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public boolean canOpen(Block b, Player p) { + boolean open = CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b) || p.hasPermission("slimefun.cargo.bypass"); + if (!open) { + Messages.local.sendTranslation(p, "inventory.no-access", true); + } + return open; + } + + @Override + public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) { + return new int[0]; + } + }; + + registerBlockHandler(name, new SlimefunBlockHandler() { + + @Override + public void onPlace(Player p, Block b, SlimefunItem item) { + BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString()); + BlockStorage.addBlockInfo(b, "index", "0"); + BlockStorage.addBlockInfo(b, "frequency", "0"); + BlockStorage.addBlockInfo(b, "filter-type", "whitelist"); + BlockStorage.addBlockInfo(b, "filter-lore", "true"); + BlockStorage.addBlockInfo(b, "filter-durability", "false"); + BlockStorage.addBlockInfo(b, "round-robin", "false"); + } + + @Override + public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { + BlockMenu inv = BlockStorage.getInventory(b); + if (inv != null) { + for (int slot : getInputSlots()) { + if (inv.getItemInSlot(slot) != null) { + b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); + inv.replaceExistingItem(slot, null); + } + } + } + return true; + } + }); + } + + protected void constructMenu(BlockMenuPreset preset) { + for (int i : border) { + preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + } + + preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), + (p, slot, item, action) -> false + ); + } + + public int[] getInputSlots() { + return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39}; + } + +} From 751cc88321a0541b2bbda6fa19dc326a3726b336 Mon Sep 17 00:00:00 2001 From: dNiym Date: Sat, 3 Aug 2019 13:44:42 -0400 Subject: [PATCH 24/27] Re-Added SAW_MILL to research --- src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java index 847d02a43..1e24c09c2 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java @@ -94,6 +94,7 @@ public class ResearchSetup { Slimefun.registerResearch(new Research(89, "Night Vision Goggles", 10), SlimefunItems.NIGHT_VISION_GOGGLES); Slimefun.registerResearch(new Research(90, "Pickaxe of Containment", 14), SlimefunItems.PICKAXE_OF_CONTAINMENT, SlimefunItems.BROKEN_SPAWNER); Slimefun.registerResearch(new Research(91, "Hercules Pickaxe", 28), SlimefunItems.HERCULES_PICKAXE); + Slimefun.registerResearch(new Research(92, "Saw Mill", 2), SlimefunItems.SAW_MILL); Slimefun.registerResearch(new Research(92, "Table Saw", 2), SlimefunItems.TABLE_SAW); Slimefun.registerResearch(new Research(93, "Slimy Steel Armor", 27), SlimefunItems.SLIME_HELMET_STEEL, SlimefunItems.SLIME_CHESTPLATE_STEEL, SlimefunItems.SLIME_LEGGINGS_STEEL, SlimefunItems.SLIME_BOOTS_STEEL); Slimefun.registerResearch(new Research(94, "Blade of Vampires", 26), SlimefunItems.BLADE_OF_VAMPIRES); From 969fbf01a7f7bf5fec2de43af6f2636ef6c36871 Mon Sep 17 00:00:00 2001 From: dNiym Date: Sat, 3 Aug 2019 13:47:36 -0400 Subject: [PATCH 25/27] Added Requested Changes --- .../mrCookieSlime/Slimefun/AncientAltar/RitualAnimation.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/me/mrCookieSlime/Slimefun/AncientAltar/RitualAnimation.java b/src/me/mrCookieSlime/Slimefun/AncientAltar/RitualAnimation.java index 27593c7c2..56803e9ab 100644 --- a/src/me/mrCookieSlime/Slimefun/AncientAltar/RitualAnimation.java +++ b/src/me/mrCookieSlime/Slimefun/AncientAltar/RitualAnimation.java @@ -54,8 +54,10 @@ public class RitualAnimation implements Runnable { @Override public void run() { idle(); - if(!checkLockedItems()) + if(!checkLockedItems()) { abort(); + return; + } if(this.stage == 36) { finish(); return; From e62a3d850985678ea61fb005e3e5a47f6b0d2721 Mon Sep 17 00:00:00 2001 From: dNiym Date: Sat, 3 Aug 2019 13:51:34 -0400 Subject: [PATCH 26/27] Combined research for Table_Saw and Saw_Mill --- src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java index 1e24c09c2..05a9b0813 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/ResearchSetup.java @@ -94,8 +94,7 @@ public class ResearchSetup { Slimefun.registerResearch(new Research(89, "Night Vision Goggles", 10), SlimefunItems.NIGHT_VISION_GOGGLES); Slimefun.registerResearch(new Research(90, "Pickaxe of Containment", 14), SlimefunItems.PICKAXE_OF_CONTAINMENT, SlimefunItems.BROKEN_SPAWNER); Slimefun.registerResearch(new Research(91, "Hercules Pickaxe", 28), SlimefunItems.HERCULES_PICKAXE); - Slimefun.registerResearch(new Research(92, "Saw Mill", 2), SlimefunItems.SAW_MILL); - Slimefun.registerResearch(new Research(92, "Table Saw", 2), SlimefunItems.TABLE_SAW); + Slimefun.registerResearch(new Research(92, "Table Saw", 2), SlimefunItems.SAW_MILL, SlimefunItems.TABLE_SAW); Slimefun.registerResearch(new Research(93, "Slimy Steel Armor", 27), SlimefunItems.SLIME_HELMET_STEEL, SlimefunItems.SLIME_CHESTPLATE_STEEL, SlimefunItems.SLIME_LEGGINGS_STEEL, SlimefunItems.SLIME_BOOTS_STEEL); Slimefun.registerResearch(new Research(94, "Blade of Vampires", 26), SlimefunItems.BLADE_OF_VAMPIRES); Slimefun.registerResearch(new Research(95, "Lazy Mining", 40), SlimefunItems.DIGITAL_MINER); From b6a4322de6f13fe2fb7230f6c79016cc1189f09d Mon Sep 17 00:00:00 2001 From: NihilistBrew Date: Sat, 3 Aug 2019 20:16:19 +0200 Subject: [PATCH 27/27] Fix PR: Remove block storage clear --- src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index 23a4d0338..03c0f6fd0 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -1840,7 +1840,6 @@ public class SlimefunSetup { Block b = e.getBlock(); // Refactored it into this so we don't need to call e.getBlock() all the time. if (b.getType() != Material.SPAWNER || BlockStorage.hasBlockInfo(b)) return true; // If the spawner's BlockStorage has BlockInfo, then it's not a vanilla spawner and shouldn't give a broken spawner. - BlockStorage.clearBlockInfo(b); ItemStack spawner = SlimefunItems.BROKEN_SPAWNER.clone(); ItemMeta im = spawner.getItemMeta(); List lore = im.getLore();