diff --git a/CHANGELOG.md b/CHANGELOG.md index e0e7ef12f..8c33b2046 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,9 @@ * Added Makeshift Smeltery * Added Tree Growth Accelerator * Added "Glass to Glass Panes" recipe to the Electric Press +* Added "Snowballs to Snow blocks" recipe to the Electric Press +* Added "Snow blocks to Ice" recipe to the Freezer +* You can now use Cooked Salmon in an Auto Drier to craft Fish Jerky * The Lumber Axe can now strip logs too #### Changes diff --git a/README.md b/README.md index 931f6dd1f..69453ee24 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ We got everything from magical wands to nuclear reactors.
We feature a magical altar, an electric power grid and even item transport systems. This project originally started back in 2013 and has grown ever since.
+From one single person working on this plugin back then, we grew to a community of thousands of players and over 100 of contributors to this project.
It currently adds over **500 new items and recipes** to Minecraft ([Read more about the history of this project](https://github.com/TheBusyBiscuit/Slimefun4/wiki/Slimefun-in-a-nutshell)). But it also comes with a lot of Addons too!
@@ -98,9 +99,11 @@ Slimefun4 has recently added suport for translations, note that translations are So not everything may be available for translation yet.
[Read more...](https://github.com/TheBusyBiscuit/Slimefun4/wiki/Translating-Slimefun) -## Data Collection -Slimefun4 uses various systems that collect or download data.
-We do not collect any personal information from you but here is a full list of what services may collect or download other kind of data. +## Disclaimer +Slimefun4 uses various systems that collect usage information or download automatic updates as well as the latest information about the project.
+We do __not__ collect any personal information from you but here is a full list of what services may collect or download other kinds of data. + +You can opt-out of the Auto-Updater and stats collection at any time. ### Auto-Updates Slimefun4 uses an Auto-Updater which connects to https://thebusybiscuit.github.io/builds/ to check for and download updates.
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java index c6278eb45..6d2b32dee 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java @@ -75,6 +75,9 @@ public class AutoDrier extends AContainer implements RecipeDisplayItem { recipeList.add(new ItemStack(Material.COOKED_COD)); recipeList.add(SlimefunItems.FISH_JERKY); + + recipeList.add(new ItemStack(Material.COOKED_SALMON)); + recipeList.add(SlimefunItems.FISH_JERKY); } @Override diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java index 0cf0e5169..5f0f58b6c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java @@ -59,6 +59,7 @@ public class AutoEnchanter extends AContainer { @Override protected void tick(Block b) { BlockMenu menu = BlockStorage.getInventory(b.getLocation()); + if (isProcessing(b)) { int timeleft = progress.get(b); @@ -85,7 +86,8 @@ public class AutoEnchanter extends AContainer { for (int slot : getInputSlots()) { ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]); - // Check if enchantable + + // Check if the item is enchantable SlimefunItem sfTarget = SlimefunItem.getByItem(target); if (sfTarget != null && !sfTarget.isEnchantable()) return; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java index 25f6cca6c..39ac3206f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java @@ -25,12 +25,14 @@ public abstract class ElectricFurnace extends AContainer { public void registerDefaultRecipes() { Iterator iterator = Bukkit.recipeIterator(); while (iterator.hasNext()) { - Recipe r = iterator.next(); - if (r instanceof CookingRecipe) { - RecipeChoice choice = ((CookingRecipe) r).getInputChoice(); + Recipe recipe = iterator.next(); + + if (recipe instanceof CookingRecipe) { + RecipeChoice choice = ((CookingRecipe) recipe).getInputChoice(); + if (choice instanceof MaterialChoice) { for (Material input : ((MaterialChoice) choice).getChoices()) { - registerRecipe(4, new ItemStack[] { new ItemStack(input) }, new ItemStack[] { r.getResult() }); + registerRecipe(4, new ItemStack[] { new ItemStack(input) }, new ItemStack[] { recipe.getResult() }); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java index e87ef3601..23a14305a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java @@ -8,7 +8,6 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; import me.mrCookieSlime.Slimefun.Lists.RecipeType; -import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; @@ -39,19 +38,6 @@ public class ElectricIngotPulverizer extends AContainer implements RecipeDisplay return new ItemStack(Material.IRON_PICKAXE); } - @Override - protected void registerDefaultRecipes() { - registerRecipe(3, new ItemStack[] { SlimefunItems.ALUMINUM_INGOT }, new ItemStack[] { SlimefunItems.ALUMINUM_DUST }); - registerRecipe(3, new ItemStack[] { SlimefunItems.COPPER_INGOT }, new ItemStack[] { SlimefunItems.COPPER_DUST }); - registerRecipe(3, new ItemStack[] { SlimefunItems.GOLD_4K }, new ItemStack[] { SlimefunItems.GOLD_DUST }); - registerRecipe(3, new ItemStack[] { new ItemStack(Material.IRON_INGOT) }, new ItemStack[] { SlimefunItems.IRON_DUST }); - registerRecipe(3, new ItemStack[] { SlimefunItems.LEAD_INGOT }, new ItemStack[] { SlimefunItems.LEAD_DUST }); - registerRecipe(3, new ItemStack[] { SlimefunItems.MAGNESIUM_INGOT }, new ItemStack[] { SlimefunItems.MAGNESIUM_DUST }); - registerRecipe(3, new ItemStack[] { SlimefunItems.SILVER_INGOT }, new ItemStack[] { SlimefunItems.SILVER_DUST }); - registerRecipe(3, new ItemStack[] { SlimefunItems.TIN_INGOT }, new ItemStack[] { SlimefunItems.TIN_DUST }); - registerRecipe(3, new ItemStack[] { SlimefunItems.ZINC_INGOT }, new ItemStack[] { SlimefunItems.ZINC_DUST }); - } - @Override public List getDisplayRecipes() { List displayRecipes = new ArrayList<>(recipes.size() * 2); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricPress.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricPress.java index fa73fe793..107be9e2d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricPress.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricPress.java @@ -22,7 +22,8 @@ public abstract class ElectricPress extends AContainer implements RecipeDisplayI addRecipe(4, new CustomItem(SlimefunItems.STONE_CHUNK, 3), new ItemStack(Material.COBBLESTONE)); addRecipe(4, new ItemStack(Material.FLINT, 6), new ItemStack(Material.COBBLESTONE)); addRecipe(5, new ItemStack(Material.GLASS), new ItemStack(Material.GLASS_PANE, 3)); - + addRecipe(4, new ItemStack(Material.SNOWBALL, 4), new ItemStack(Material.SNOW_BLOCK)); + addRecipe(6, SlimefunItems.COPPER_INGOT, new CustomItem(SlimefunItems.COPPER_WIRE, 3)); addRecipe(16, new CustomItem(SlimefunItems.STEEL_INGOT, 8), SlimefunItems.STEEL_PLATE); addRecipe(18, new CustomItem(SlimefunItems.REINFORCED_ALLOY_INGOT, 8), SlimefunItems.REINFORCED_PLATE); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/Freezer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/Freezer.java index b0e3faab8..15730f210 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/Freezer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/Freezer.java @@ -27,6 +27,7 @@ public abstract class Freezer extends AContainer implements RecipeDisplayItem { registerRecipe(4, new ItemStack[] { new ItemStack(Material.ICE) }, new ItemStack[] { new ItemStack(Material.PACKED_ICE) }); registerRecipe(6, new ItemStack[] { new ItemStack(Material.PACKED_ICE) }, new ItemStack[] { new ItemStack(Material.BLUE_ICE) }); registerRecipe(8, new ItemStack[] { new ItemStack(Material.BLUE_ICE) }, new ItemStack[] { SlimefunItems.REACTOR_COOLANT_CELL }); + registerRecipe(6, new ItemStack[] { new ItemStack(Material.SNOW_BLOCK, 2) }, new ItemStack[] { new ItemStack(Material.ICE) }); } @Override diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java index 531bb96a8..463e06b28 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java @@ -183,7 +183,9 @@ public final class PostSetup { // We want to exclude Dust to Ingot Recipes if (inputs.size() == 1 && isDust(inputs.get(0))) { ((MakeshiftSmeltery) SlimefunItems.MAKESHIFT_SMELTERY.getItem()).addRecipe(new ItemStack[] { inputs.get(0) }, recipe[0]); + registerMachineRecipe("ELECTRIC_INGOT_FACTORY", 8, new ItemStack[] { inputs.get(0) }, new ItemStack[] { recipe[0] }); + registerMachineRecipe("ELECTRIC_INGOT_PULVERIZER", 3, new ItemStack[] { recipe[0] }, new ItemStack[] { inputs.get(0) }); } else { registerMachineRecipe("ELECTRIC_SMELTERY", 12, inputs.toArray(new ItemStack[0]), new ItemStack[] { recipe[0] }); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java b/src/main/java/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java index 22c0738f6..f4386ffa7 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java @@ -44,8 +44,8 @@ public class CargoNet extends Network { private static final int[] slots = { 19, 20, 21, 28, 29, 30, 37, 38, 39 }; // Chest Terminal Stuff - public static final int[] TERMINAL_SLOTS = { 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 }; - public static final int TERMINAL_OUT_SLOT = 17; + private static final int[] TERMINAL_SLOTS = { 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 int TERMINAL_OUT_SLOT = 17; private final ItemStack terminalPlaceholderItem = new CustomItem(new ItemStack(Material.BARRIER), "&4No Item cached"); @@ -75,11 +75,6 @@ public class CargoNet extends Network { return cargoNetwork; } - @Deprecated - public static boolean isConnected(Block b) { - return getNetworkFromLocation(b.getLocation()) != null; - } - protected CargoNet(Location l) { super(l); } @@ -197,324 +192,325 @@ public class CargoNet extends Network { } } - Slimefun.runSync(() -> { + Slimefun.runSync(() -> run(b, providers, destinations, output)); + } + } + + private void run(Block b, Set providers, Set destinations, Map> output) { + if (BlockStorage.getLocationInfo(b.getLocation(), "visualizer") == null) { + display(); + } - if (BlockStorage.getLocationInfo(b.getLocation(), "visualizer") == null) { - display(); - } + // Chest Terminal Code + if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) { + for (Location bus : imports) { + BlockMenu menu = BlockStorage.getInventory(bus); - // Chest Terminal Code - if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) { - for (Location bus : imports) { - BlockMenu menu = BlockStorage.getInventory(bus); - - if (menu.getItemInSlot(17) == null) { - Block target = getAttachedBlock(bus.getBlock()); - ItemStackAndInteger stack = CargoUtils.withdraw(bus.getBlock(), target, -1); - - if (stack != null) { - menu.replaceExistingItem(17, stack.getItem()); - } - } - - if (menu.getItemInSlot(17) != null) { - itemRequests.add(new ItemRequest(bus, 17, menu.getItemInSlot(17), ItemTransportFlow.INSERT)); - } - } - - for (Location bus : exports) { - BlockMenu menu = BlockStorage.getInventory(bus); - - if (menu.getItemInSlot(17) != null) { - Block target = getAttachedBlock(bus.getBlock()); - - menu.replaceExistingItem(17, CargoUtils.insert(bus.getBlock(), target, menu.getItemInSlot(17), -1)); - } - - if (menu.getItemInSlot(17) == null) { - List items = new ArrayList<>(); - for (int slot : slots) { - ItemStack template = menu.getItemInSlot(slot); - if (template != null) items.add(new CustomItem(template, 1)); - } - - if (!items.isEmpty()) { - int index = Integer.parseInt(BlockStorage.getLocationInfo(bus, "index")); - - index++; - if (index > (items.size() - 1)) index = 0; - - BlockStorage.addBlockInfo(bus, "index", String.valueOf(index)); - itemRequests.add(new ItemRequest(bus, 17, items.get(index), ItemTransportFlow.WITHDRAW)); - } - } - } - - for (Location terminal : terminals) { - BlockMenu menu = BlockStorage.getInventory(terminal); - ItemStack sendingItem = menu.getItemInSlot(TERMINAL_OUT_SLOT); - - if (sendingItem != null) { - itemRequests.add(new ItemRequest(terminal, TERMINAL_OUT_SLOT, sendingItem, ItemTransportFlow.INSERT)); - } - } - - Iterator iterator = itemRequests.iterator(); - while (iterator.hasNext()) { - ItemRequest request = iterator.next(); - - if (terminals.contains(request.getTerminal()) || imports.contains(request.getTerminal()) || exports.contains(request.getTerminal())) { - BlockMenu menu = BlockStorage.getInventory(request.getTerminal()); - - switch (request.getDirection()) { - case INSERT: - ItemStack requestedItem = request.getItem(); - - for (Location l : destinations) { - Block target = getAttachedBlock(l.getBlock()); - requestedItem = CargoUtils.insert(l.getBlock(), target, requestedItem, -1); - - if (requestedItem == null) { - menu.replaceExistingItem(request.getSlot(), null); - break; - } - } - - if (requestedItem != null) { - menu.replaceExistingItem(request.getSlot(), requestedItem); - } - - iterator.remove(); - break; - case WITHDRAW: - int slot = request.getSlot(); - ItemStack prevStack = menu.getItemInSlot(slot); - - if (!(prevStack == null || (prevStack.getAmount() + request.getItem().getAmount() <= prevStack.getMaxStackSize() && SlimefunManager.isItemSimilar(prevStack, new CustomItem(request.getItem(), 1), true)))) { - iterator.remove(); - break; - } - - ItemStack stack = null; - ItemStack requested = request.getItem(); - - for (Location l : providers) { - Block target = getAttachedBlock(l.getBlock()); - ItemStack is = CargoUtils.withdraw(l.getBlock(), target, requested); - - if (is != null) { - if (stack == null) { - stack = is; - } - else { - stack = new CustomItem(stack, stack.getAmount() + is.getAmount()); - } - - if (is.getAmount() == requested.getAmount()) { - break; - } - else { - requested = new CustomItem(requested, requested.getAmount() - is.getAmount()); - } - } - } - - if (stack != null) { - ItemStack prev = menu.getItemInSlot(slot); - - if (prev == null) menu.replaceExistingItem(slot, stack); - else menu.replaceExistingItem(slot, new CustomItem(stack, stack.getAmount() + prev.getAmount())); - } - - iterator.remove(); - break; - default: - break; - } - } - } - } - - // All operations happen here: Everything gets iterated from the Input Nodes. (Apart from ChestTerminal - // Buses) - for (Location input : inputNodes) { - int frequency = getFrequency(input); - - if (frequency < 0 || frequency > 15) { - continue; - } - - Block inputTarget = getAttachedBlock(input.getBlock()); - ItemStack stack = null; - int previousSlot = -1; - - Config cfg = BlockStorage.getLocationInfo(input); - boolean roundrobin = "true".equals(cfg.getString("round-robin")); - - if (inputTarget != null) { - ItemStackAndInteger slot = CargoUtils.withdraw(input.getBlock(), inputTarget, Integer.parseInt(cfg.getString("index"))); - - if (slot != null) { - stack = slot.getItem(); - previousSlot = slot.getInt(); - } - } + if (menu.getItemInSlot(17) == null) { + Block target = getAttachedBlock(bus.getBlock()); + ItemStackAndInteger stack = CargoUtils.withdraw(bus.getBlock(), target, -1); if (stack != null) { - List outputs = output.get(frequency); - - if (outputs != null) { - List outputlist = new ArrayList<>(outputs); - - if (roundrobin) { - int cIndex = roundRobin.getOrDefault(input, 0); - - if (cIndex < outputlist.size()) { - for (int i = 0; i < cIndex; i++) { - Location temp = outputlist.get(0); - outputlist.remove(temp); - outputlist.add(temp); - } - cIndex++; - } - else cIndex = 1; - - roundRobin.put(input, cIndex); - } - - for (Location out : outputlist) { - Block target = getAttachedBlock(out.getBlock()); - - if (target != null) { - stack = CargoUtils.insert(out.getBlock(), target, stack, -1); - if (stack == null) break; - } - } - } - } - - if (stack != null && previousSlot > -1) { - DirtyChestMenu menu = CargoUtils.getChestMenu(inputTarget); - - if (menu != null) { - menu.replaceExistingItem(previousSlot, stack); - } - else { - BlockState state = inputTarget.getState(); - if (state instanceof InventoryHolder) { - Inventory inv = ((InventoryHolder) state).getInventory(); - inv.setItem(previousSlot, stack); - } - } + menu.replaceExistingItem(17, stack.getItem()); } } - // Chest Terminal Code - if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) { - List items = new ArrayList<>(); + if (menu.getItemInSlot(17) != null) { + itemRequests.add(new ItemRequest(bus, 17, menu.getItemInSlot(17), ItemTransportFlow.INSERT)); + } + } - for (Location l : providers) { - Block target = getAttachedBlock(l.getBlock()); - UniversalBlockMenu menu = BlockStorage.getUniversalInventory(target); + for (Location bus : exports) { + BlockMenu menu = BlockStorage.getInventory(bus); - if (menu != null) { - for (int slot : menu.getPreset().getSlotsAccessedByItemTransport((DirtyChestMenu) menu, ItemTransportFlow.WITHDRAW, null)) { - ItemStack is = menu.getItemInSlot(slot); - filter(is, items, l); - } - } - else if (BlockStorage.hasInventory(target)) { - BlockMenu blockMenu = BlockStorage.getInventory(target); - Config cfg = BlockStorage.getLocationInfo(target.getLocation()); + if (menu.getItemInSlot(17) != null) { + Block target = getAttachedBlock(bus.getBlock()); - if (cfg.getString("id").startsWith("BARREL_") && cfg.getString("storedItems") != null) { - int stored = Integer.parseInt(cfg.getString("storedItems")); + menu.replaceExistingItem(17, CargoUtils.insert(bus.getBlock(), target, menu.getItemInSlot(17), -1)); + } - for (int slot : blockMenu.getPreset().getSlotsAccessedByItemTransport((DirtyChestMenu) blockMenu, ItemTransportFlow.WITHDRAW, null)) { - ItemStack is = blockMenu.getItemInSlot(slot); - - if (is != null && CargoUtils.matchesFilter(l.getBlock(), is, -1)) { - boolean add = true; - - for (ItemStackAndInteger item : items) { - if (SlimefunManager.isItemSimilar(is, item.getItem(), true)) { - add = false; - item.add(is.getAmount() + stored); - } - } - - if (add) { - items.add(new ItemStackAndInteger(new CustomItem(is, 1), is.getAmount() + stored)); - } - } - } - } - else { - handleWithdraw(blockMenu, items, l); - } - } - else { - BlockState state = target.getState(); - - if (state instanceof InventoryHolder) { - Inventory inv = ((InventoryHolder) state).getInventory(); - - for (ItemStack is : inv.getContents()) { - filter(is, items, l); - } - } - } + if (menu.getItemInSlot(17) == null) { + List items = new ArrayList<>(); + for (int slot : slots) { + ItemStack template = menu.getItemInSlot(slot); + if (template != null) items.add(new CustomItem(template, 1)); } - Collections.sort(items, Comparator.comparingInt(item -> -item.getInt())); + if (!items.isEmpty()) { + int index = Integer.parseInt(BlockStorage.getLocationInfo(bus, "index")); - for (Location l : terminals) { - BlockMenu menu = BlockStorage.getInventory(l); - int page = Integer.parseInt(BlockStorage.getLocationInfo(l, "page")); + index++; + if (index > (items.size() - 1)) index = 0; - if (!items.isEmpty() && items.size() < (page - 1) * TERMINAL_SLOTS.length + 1) { - page = 1; - BlockStorage.addBlockInfo(l, "page", String.valueOf(1)); + BlockStorage.addBlockInfo(bus, "index", String.valueOf(index)); + itemRequests.add(new ItemRequest(bus, 17, items.get(index), ItemTransportFlow.WITHDRAW)); + } + } + } + + for (Location terminal : terminals) { + BlockMenu menu = BlockStorage.getInventory(terminal); + ItemStack sendingItem = menu.getItemInSlot(TERMINAL_OUT_SLOT); + + if (sendingItem != null) { + itemRequests.add(new ItemRequest(terminal, TERMINAL_OUT_SLOT, sendingItem, ItemTransportFlow.INSERT)); + } + } + + Iterator iterator = itemRequests.iterator(); + while (iterator.hasNext()) { + ItemRequest request = iterator.next(); + + if (terminals.contains(request.getTerminal()) || imports.contains(request.getTerminal()) || exports.contains(request.getTerminal())) { + BlockMenu menu = BlockStorage.getInventory(request.getTerminal()); + + switch (request.getDirection()) { + case INSERT: + ItemStack requestedItem = request.getItem(); + + for (Location l : destinations) { + Block target = getAttachedBlock(l.getBlock()); + requestedItem = CargoUtils.insert(l.getBlock(), target, requestedItem, -1); + + if (requestedItem == null) { + menu.replaceExistingItem(request.getSlot(), null); + break; + } } - for (int i = 0; i < TERMINAL_SLOTS.length; i++) { - int slot = TERMINAL_SLOTS[i]; + if (requestedItem != null) { + menu.replaceExistingItem(request.getSlot(), requestedItem); + } - if (items.size() > i + (TERMINAL_SLOTS.length * (page - 1))) { - ItemStackAndInteger item = items.get(i + (TERMINAL_SLOTS.length * (page - 1))); + iterator.remove(); + break; + case WITHDRAW: + int slot = request.getSlot(); + ItemStack prevStack = menu.getItemInSlot(slot); - ItemStack stack = item.getItem().clone(); - ItemMeta im = stack.getItemMeta(); - List lore = new ArrayList<>(); - lore.add(""); - lore.add(ChatColors.color("&7Stored Items: &r" + DoubleHandler.getFancyDouble(item.getInt()))); + if (!(prevStack == null || (prevStack.getAmount() + request.getItem().getAmount() <= prevStack.getMaxStackSize() && SlimefunManager.isItemSimilar(prevStack, new CustomItem(request.getItem(), 1), true)))) { + iterator.remove(); + break; + } - if (stack.getMaxStackSize() > 1) lore.add(ChatColors.color("&7 stack.getMaxStackSize() ? stack.getMaxStackSize() : item.getInt()) + ">")); - else lore.add(ChatColors.color("&7")); + ItemStack stack = null; + ItemStack requested = request.getItem(); - lore.add(""); - if (im.hasLore()) { - lore.addAll(im.getLore()); + for (Location l : providers) { + Block target = getAttachedBlock(l.getBlock()); + ItemStack is = CargoUtils.withdraw(l.getBlock(), target, requested); + + if (is != null) { + if (stack == null) { + stack = is; + } + else { + stack = new CustomItem(stack, stack.getAmount() + is.getAmount()); } - im.setLore(lore); - stack.setItemMeta(im); - menu.replaceExistingItem(slot, stack); - menu.addMenuClickHandler(slot, (p, sl, is, action) -> { - int amount = item.getInt() > item.getItem().getMaxStackSize() ? item.getItem().getMaxStackSize() : item.getInt(); - itemRequests.add(new ItemRequest(l, 44, new CustomItem(item.getItem(), action.isRightClicked() ? amount : 1), ItemTransportFlow.WITHDRAW)); - return false; - }); + if (is.getAmount() == requested.getAmount()) { + break; + } + else { + requested = new CustomItem(requested, requested.getAmount() - is.getAmount()); + } + } + } + if (stack != null) { + ItemStack prev = menu.getItemInSlot(slot); + + if (prev == null) menu.replaceExistingItem(slot, stack); + else menu.replaceExistingItem(slot, new CustomItem(stack, stack.getAmount() + prev.getAmount())); + } + + iterator.remove(); + break; + default: + break; + } + } + } + } + + // All operations happen here: Everything gets iterated from the Input Nodes. (Apart from ChestTerminal + // Buses) + for (Location input : inputNodes) { + int frequency = getFrequency(input); + + if (frequency < 0 || frequency > 15) { + continue; + } + + Block inputTarget = getAttachedBlock(input.getBlock()); + ItemStack stack = null; + int previousSlot = -1; + + Config cfg = BlockStorage.getLocationInfo(input); + boolean roundrobin = "true".equals(cfg.getString("round-robin")); + + if (inputTarget != null) { + ItemStackAndInteger slot = CargoUtils.withdraw(input.getBlock(), inputTarget, Integer.parseInt(cfg.getString("index"))); + + if (slot != null) { + stack = slot.getItem(); + previousSlot = slot.getInt(); + } + } + + if (stack != null) { + List outputs = output.get(frequency); + + if (outputs != null) { + List outputlist = new ArrayList<>(outputs); + + if (roundrobin) { + int cIndex = roundRobin.getOrDefault(input, 0); + + if (cIndex < outputlist.size()) { + for (int i = 0; i < cIndex; i++) { + Location temp = outputlist.get(0); + outputlist.remove(temp); + outputlist.add(temp); } - else { - menu.replaceExistingItem(slot, terminalPlaceholderItem); - menu.addMenuClickHandler(slot, ChestMenuUtils.getEmptyClickHandler()); - } + cIndex++; + } + else cIndex = 1; + + roundRobin.put(input, cIndex); + } + + for (Location out : outputlist) { + Block target = getAttachedBlock(out.getBlock()); + + if (target != null) { + stack = CargoUtils.insert(out.getBlock(), target, stack, -1); + if (stack == null) break; } } } - }); + } + + if (stack != null && previousSlot > -1) { + DirtyChestMenu menu = CargoUtils.getChestMenu(inputTarget); + + if (menu != null) { + menu.replaceExistingItem(previousSlot, stack); + } + else { + BlockState state = inputTarget.getState(); + if (state instanceof InventoryHolder) { + Inventory inv = ((InventoryHolder) state).getInventory(); + inv.setItem(previousSlot, stack); + } + } + } + } + + // Chest Terminal Code + if (SlimefunPlugin.getNetworkManager().isChestTerminalInstalled()) { + List items = new ArrayList<>(); + + for (Location l : providers) { + Block target = getAttachedBlock(l.getBlock()); + UniversalBlockMenu menu = BlockStorage.getUniversalInventory(target); + + if (menu != null) { + for (int slot : menu.getPreset().getSlotsAccessedByItemTransport((DirtyChestMenu) menu, ItemTransportFlow.WITHDRAW, null)) { + ItemStack is = menu.getItemInSlot(slot); + filter(is, items, l); + } + } + else if (BlockStorage.hasInventory(target)) { + BlockMenu blockMenu = BlockStorage.getInventory(target); + Config cfg = BlockStorage.getLocationInfo(target.getLocation()); + + if (cfg.getString("id").startsWith("BARREL_") && cfg.getString("storedItems") != null) { + int stored = Integer.parseInt(cfg.getString("storedItems")); + + for (int slot : blockMenu.getPreset().getSlotsAccessedByItemTransport((DirtyChestMenu) blockMenu, ItemTransportFlow.WITHDRAW, null)) { + ItemStack is = blockMenu.getItemInSlot(slot); + + if (is != null && CargoUtils.matchesFilter(l.getBlock(), is, -1)) { + boolean add = true; + + for (ItemStackAndInteger item : items) { + if (SlimefunManager.isItemSimilar(is, item.getItem(), true)) { + add = false; + item.add(is.getAmount() + stored); + } + } + + if (add) { + items.add(new ItemStackAndInteger(new CustomItem(is, 1), is.getAmount() + stored)); + } + } + } + } + else { + handleWithdraw(blockMenu, items, l); + } + } + else { + BlockState state = target.getState(); + + if (state instanceof InventoryHolder) { + Inventory inv = ((InventoryHolder) state).getInventory(); + + for (ItemStack is : inv.getContents()) { + filter(is, items, l); + } + } + } + } + + Collections.sort(items, Comparator.comparingInt(item -> -item.getInt())); + + for (Location l : terminals) { + BlockMenu menu = BlockStorage.getInventory(l); + int page = Integer.parseInt(BlockStorage.getLocationInfo(l, "page")); + + if (!items.isEmpty() && items.size() < (page - 1) * TERMINAL_SLOTS.length + 1) { + page = 1; + BlockStorage.addBlockInfo(l, "page", String.valueOf(1)); + } + + for (int i = 0; i < TERMINAL_SLOTS.length; i++) { + int slot = TERMINAL_SLOTS[i]; + + if (items.size() > i + (TERMINAL_SLOTS.length * (page - 1))) { + ItemStackAndInteger item = items.get(i + (TERMINAL_SLOTS.length * (page - 1))); + + ItemStack stack = item.getItem().clone(); + ItemMeta im = stack.getItemMeta(); + List lore = new ArrayList<>(); + lore.add(""); + lore.add(ChatColors.color("&7Stored Items: &r" + DoubleHandler.getFancyDouble(item.getInt()))); + + if (stack.getMaxStackSize() > 1) lore.add(ChatColors.color("&7 stack.getMaxStackSize() ? stack.getMaxStackSize() : item.getInt()) + ">")); + else lore.add(ChatColors.color("&7")); + + lore.add(""); + if (im.hasLore()) { + lore.addAll(im.getLore()); + } + + im.setLore(lore); + stack.setItemMeta(im); + menu.replaceExistingItem(slot, stack); + menu.addMenuClickHandler(slot, (p, sl, is, action) -> { + int amount = item.getInt() > item.getItem().getMaxStackSize() ? item.getItem().getMaxStackSize() : item.getInt(); + itemRequests.add(new ItemRequest(l, 44, new CustomItem(item.getItem(), action.isRightClicked() ? amount : 1), ItemTransportFlow.WITHDRAW)); + return false; + }); + + } + else { + menu.replaceExistingItem(slot, terminalPlaceholderItem); + menu.addMenuClickHandler(slot, ChestMenuUtils.getEmptyClickHandler()); + } + } + } } }