From de4f779a64ee267c6abf5fabc40cc6d5899699a0 Mon Sep 17 00:00:00 2001 From: John000708 Date: Mon, 6 Feb 2017 18:23:11 +0100 Subject: [PATCH] Added EmeraldEnchants limit to AutoEnchanter. Started "documenting" the API --- src/config.yml | 1 + .../SlimefunItem/machines/AutoEnchanter.java | 17 ++++++++------ .../Slimefun/SlimefunStartup.java | 4 ++++ .../api/item_transport/CargoManager.java | 2 +- .../Slimefun/api/item_transport/CargoNet.java | 22 ++++++++++++++----- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/config.yml b/src/config.yml index f6bc39103..e5a81a226 100644 --- a/src/config.yml +++ b/src/config.yml @@ -8,6 +8,7 @@ options: auto-save-delay-in-minutes: 10 show-vanilla-recipes-in-guide: true allow-free-creative-research: true + emerald-enchantment-limit: 2 guide: default-view-book: false URID: diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/AutoEnchanter.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/AutoEnchanter.java index ecc27e12b..9d0ec7836 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/AutoEnchanter.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/AutoEnchanter.java @@ -29,6 +29,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.material.MaterialData; public class AutoEnchanter extends AContainer { + public static int max_emerald_enchantments = 2; public AutoEnchanter(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe) { super(category, item, name, recipeType, recipe); @@ -51,7 +52,7 @@ public class AutoEnchanter extends AContainer { public int getEnergyConsumption() { return 9; } - + @SuppressWarnings("deprecation") @Override protected void tick(Block b) { @@ -68,9 +69,9 @@ public class AutoEnchanter extends AContainer { lore.add(MachineHelper.getTimeLeft(timeleft / 2)); im.setLore(lore); item.setItemMeta(im); - + BlockStorage.getInventory(b).replaceExistingItem(22, item); - + if (ChargableBlock.isChargable(b)) { if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return; ChargableBlock.addCharge(b, -getEnergyConsumption()); @@ -81,7 +82,7 @@ public class AutoEnchanter extends AContainer { else { BlockStorage.getInventory(b).replaceExistingItem(22, new CustomItem(new MaterialData(Material.STAINED_GLASS_PANE, (byte) 15), " ")); pushItems(b, processing.get(b).getOutput()); - + progress.remove(b); processing.remove(b); } @@ -96,6 +97,7 @@ public class AutoEnchanter extends AContainer { Map enchantments = new HashMap(); Set enchantments2 = new HashSet(); int amount = 0; + int special_amount = 0; EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta(); for (Map.Entry e: meta.getStoredEnchants().entrySet()) { if (e.getKey().canEnchantItem(target)) { @@ -107,12 +109,13 @@ public class AutoEnchanter extends AContainer { for (ItemEnchantment enchantment: EmeraldEnchants.getInstance().getRegistry().getEnchantments(item)) { if (EmeraldEnchants.getInstance().getRegistry().isApplicable(target, enchantment.getEnchantment()) && EmeraldEnchants.getInstance().getRegistry().getEnchantmentLevel(target, enchantment.getEnchantment().getName()) < enchantment.getLevel()) { amount++; + special_amount++; enchantments2.add(enchantment); } } + special_amount+=EmeraldEnchants.getInstance().getRegistry().getEnchantments(target).size(); } - - if (amount > 0) { + if (amount > 0 && special_amount <= max_emerald_enchantments) { ItemStack newItem = target.clone(); for (Map.Entry e: enchantments.entrySet()) { newItem.addUnsafeEnchantment(e.getKey(), e.getValue()); @@ -125,7 +128,7 @@ public class AutoEnchanter extends AContainer { break slots; } } - + if (r != null) { if (!fits(b, r.getOutput())) return; for (int slot: getInputSlots()) { diff --git a/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java b/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java index 641c8b8c0..e5bc80500 100644 --- a/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java +++ b/src/me/mrCookieSlime/Slimefun/SlimefunStartup.java @@ -15,6 +15,7 @@ import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.AutoEnchanter; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.block.Block; @@ -385,6 +386,9 @@ public class SlimefunStartup extends JavaPlugin { if (clearlag) new ClearLaggIntegration(this); SlimefunGuide.creative_research = config.getBoolean("options.allow-free-creative-research"); + + AutoEnchanter.max_emerald_enchantments = config.getInt("options.emerald-enchantment-limit"); + // Do not show /sf elevator command in our Log, it could get quite spammy CSCoreLib.getLib().filterLog("([A-Za-z0-9_]{3,16}) issued server command: /sf elevator (.{0,})"); } diff --git a/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoManager.java b/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoManager.java index 4f2667499..5bca98cc3 100644 --- a/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoManager.java +++ b/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoManager.java @@ -185,7 +185,7 @@ public class CargoManager { return stack; } - + //Whitelist or blacklist slots private static int[] slots = new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39}; public static boolean matchesFilter(Block block, ItemStack item, int index) { diff --git a/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java b/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java index 04266dade..48bb2f193 100644 --- a/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java +++ b/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java @@ -55,7 +55,8 @@ public class CargoNet { public static Set requests = new HashSet(); private static int[] slots = new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39}; - + + //Chest Terminal Stuff private static final ChestTerminalSorter sorter = new ChestTerminalSorter(); public static final int[] terminal_slots = new int[] {0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, 39, 40, 41, 42}; private static final ItemStack terminal_noitem_item = new CustomItem(new MaterialData(Material.BARRIER), "&4No Item cached"); @@ -66,11 +67,20 @@ public class CargoNet { return false; } }; - public static void tick(final Block b) { + /* + Input/Output Nodes can be found here after a scan. + Input Nodes: + Location = The location of the node. + Integer = The frequency of the node. + Output Nodes: + Integer = The frequency of the node. + List = The locations of the corresponding input nodes + */ final Map input = new HashMap(); final Map> output = new HashMap>(); - + + //Chest Terminal Stuff final Set providers = new HashSet(); final Set terminals = new HashSet(); final Set imports = new HashSet(); @@ -103,7 +113,7 @@ public class CargoNet { } } } - + //Chest Terminal Code if (EXTRA_CHANNELS) { for (Location bus: imports) { BlockMenu menu = BlockStorage.getInventory(bus); @@ -225,7 +235,7 @@ public class CargoNet { } } } - + //All operations happen here: Everything gets iterated from the Input Nodes. (Apart from ChestTerminal Buses) for (Map.Entry entry: input.entrySet()) { Block inputTarget = getAttachedBlock(entry.getKey().getBlock()); ItemStack stack = null; @@ -289,7 +299,7 @@ public class CargoNet { } } } - + //Chest Terminal Code if (EXTRA_CHANNELS) { List items = new ArrayList(); for (Location l: providers) {