mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Removed ChestTerminal support
This commit is contained in:
parent
a82e362dd8
commit
72bd02b833
@ -1,17 +1,9 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.networks.cargo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -21,29 +13,15 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import io.github.bakedlibs.dough.common.ChatColors;
|
||||
import io.github.bakedlibs.dough.items.CustomItemStack;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
|
||||
import io.github.thebusybiscuit.slimefun4.api.network.Network;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
|
||||
import io.papermc.lib.PaperLib;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
|
||||
|
||||
/**
|
||||
@ -55,21 +33,6 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
|
||||
*/
|
||||
abstract class AbstractItemNetwork extends Network {
|
||||
|
||||
private static final int[] slots = { 19, 20, 21, 28, 29, 30, 37, 38, 39 };
|
||||
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 CustomItemStack(Material.BARRIER, "&4No Item cached");
|
||||
|
||||
protected final Set<Location> terminals = new HashSet<>();
|
||||
protected final Set<Location> imports = new HashSet<>();
|
||||
protected final Set<Location> exports = new HashSet<>();
|
||||
|
||||
/**
|
||||
* This represents a {@link Queue} of requests to handle
|
||||
*/
|
||||
private final Queue<ItemRequest> itemRequests = new LinkedList<>();
|
||||
|
||||
/**
|
||||
* This is a cache for the {@link BlockFace} a node is facing, so we don't need to
|
||||
* request the {@link BlockData} each time we visit a node
|
||||
@ -81,11 +44,11 @@ abstract class AbstractItemNetwork extends Network {
|
||||
*/
|
||||
protected Map<Location, ItemFilter> filterCache = new HashMap<>();
|
||||
|
||||
protected AbstractItemNetwork(Location regulator) {
|
||||
protected AbstractItemNetwork(@Nonnull Location regulator) {
|
||||
super(Slimefun.getNetworkManager(), regulator);
|
||||
}
|
||||
|
||||
protected Optional<Block> getAttachedBlock(Location l) {
|
||||
protected Optional<Block> getAttachedBlock(@Nonnull Location l) {
|
||||
if (l.getWorld().isChunkLoaded(l.getBlockX() >> 4, l.getBlockZ() >> 4)) {
|
||||
Block block = l.getBlock();
|
||||
|
||||
@ -105,235 +68,6 @@ abstract class AbstractItemNetwork extends Network {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
protected void handleItemRequests(Map<Location, Inventory> inventories, Set<Location> providers, Set<Location> destinations) {
|
||||
collectImportRequests(inventories);
|
||||
collectExportRequests(inventories);
|
||||
collectTerminalRequests();
|
||||
|
||||
Iterator<ItemRequest> iterator = itemRequests.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ItemRequest request = iterator.next();
|
||||
BlockMenu menu = BlockStorage.getInventory(request.getTerminal());
|
||||
|
||||
if (menu != null) {
|
||||
switch (request.getDirection()) {
|
||||
case INSERT:
|
||||
distributeInsertionRequest(inventories, request, menu, iterator, destinations);
|
||||
break;
|
||||
case WITHDRAW:
|
||||
collectExtractionRequest(inventories, request, menu, iterator, providers);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void distributeInsertionRequest(Map<Location, Inventory> inventories, ItemRequest request, BlockMenu terminal, Iterator<ItemRequest> iterator, Set<Location> destinations) {
|
||||
ItemStack item = request.getItem();
|
||||
|
||||
for (Location l : destinations) {
|
||||
Optional<Block> target = getAttachedBlock(l);
|
||||
|
||||
if (target.isPresent()) {
|
||||
item = CargoUtils.insert(this, inventories, l.getBlock(), target.get(), false, item, ItemStackWrapper.wrap(item));
|
||||
|
||||
if (item == null) {
|
||||
terminal.replaceExistingItem(request.getSlot(), null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item != null) {
|
||||
terminal.replaceExistingItem(request.getSlot(), item);
|
||||
}
|
||||
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
private void collectExtractionRequest(Map<Location, Inventory> inventories, ItemRequest request, BlockMenu terminal, Iterator<ItemRequest> iterator, Set<Location> providers) {
|
||||
int slot = request.getSlot();
|
||||
ItemStack prevStack = terminal.getItemInSlot(slot);
|
||||
|
||||
if (!(prevStack == null || (prevStack.getAmount() + request.getItem().getAmount() <= prevStack.getMaxStackSize() && SlimefunUtils.isItemSimilar(prevStack, request.getItem(), true, false)))) {
|
||||
iterator.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = null;
|
||||
ItemStack item = request.getItem();
|
||||
|
||||
for (Location l : providers) {
|
||||
Optional<Block> target = getAttachedBlock(l);
|
||||
|
||||
if (target.isPresent()) {
|
||||
ItemStack is = CargoUtils.withdraw(this, inventories, l.getBlock(), target.get(), item);
|
||||
|
||||
if (is != null) {
|
||||
if (stack == null) {
|
||||
stack = is;
|
||||
} else {
|
||||
stack = new CustomItemStack(stack, stack.getAmount() + is.getAmount());
|
||||
}
|
||||
|
||||
if (is.getAmount() == item.getAmount()) {
|
||||
break;
|
||||
} else {
|
||||
item = new CustomItemStack(item, item.getAmount() - is.getAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stack != null) {
|
||||
ItemStack prev = terminal.getItemInSlot(slot);
|
||||
|
||||
if (prev == null) {
|
||||
terminal.replaceExistingItem(slot, stack);
|
||||
} else {
|
||||
terminal.replaceExistingItem(slot, new CustomItemStack(stack, stack.getAmount() + prev.getAmount()));
|
||||
}
|
||||
}
|
||||
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
private void collectImportRequests(Map<Location, Inventory> inventories) {
|
||||
SlimefunItem item = SlimefunItem.getById("CT_IMPORT_BUS");
|
||||
|
||||
for (Location bus : imports) {
|
||||
long timestamp = Slimefun.getProfiler().newEntry();
|
||||
BlockMenu menu = BlockStorage.getInventory(bus);
|
||||
|
||||
if (menu.getItemInSlot(17) == null) {
|
||||
Optional<Block> target = getAttachedBlock(bus);
|
||||
|
||||
if (target.isPresent()) {
|
||||
ItemStackAndInteger stack = CargoUtils.withdraw(this, inventories, bus.getBlock(), target.get());
|
||||
|
||||
if (stack != null) {
|
||||
menu.replaceExistingItem(17, stack.getItem());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (menu.getItemInSlot(17) != null) {
|
||||
itemRequests.add(new ItemRequest(bus, 17, menu.getItemInSlot(17), ItemTransportFlow.INSERT));
|
||||
}
|
||||
|
||||
Slimefun.getProfiler().closeEntry(bus, item, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
private void collectExportRequests(Map<Location, Inventory> inventories) {
|
||||
SlimefunItem item = SlimefunItem.getById("CT_EXPORT_BUS");
|
||||
|
||||
for (Location bus : exports) {
|
||||
long timestamp = Slimefun.getProfiler().newEntry();
|
||||
BlockMenu menu = BlockStorage.getInventory(bus);
|
||||
|
||||
ItemStack itemSlot17 = menu.getItemInSlot(17);
|
||||
if (itemSlot17 != null) {
|
||||
Optional<Block> target = getAttachedBlock(bus);
|
||||
target.ifPresent(block -> menu.replaceExistingItem(17, CargoUtils.insert(this, inventories, bus.getBlock(), block, false, itemSlot17, ItemStackWrapper.wrap(itemSlot17))));
|
||||
}
|
||||
|
||||
if (menu.getItemInSlot(17) == null) {
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
|
||||
for (int slot : slots) {
|
||||
ItemStack template = menu.getItemInSlot(slot);
|
||||
|
||||
if (template != null) {
|
||||
items.add(new CustomItemStack(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));
|
||||
}
|
||||
}
|
||||
|
||||
Slimefun.getProfiler().closeEntry(bus, item, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
private void collectTerminalRequests() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method updates every terminal on the network with {@link ItemStack ItemStacks}
|
||||
* found in any provider of the network.
|
||||
*
|
||||
* @param providers
|
||||
* A {@link Set} of providers to this {@link AbstractItemNetwork}
|
||||
*
|
||||
* @return The time it took to compute this operation
|
||||
*/
|
||||
protected long updateTerminals(@Nonnull Set<Location> providers) {
|
||||
if (terminals.isEmpty()) {
|
||||
// Performance improvement - We don't need to compute items for
|
||||
// Cargo networks without any Chest Terminals
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Timings will be slightly inaccurate here but most often people are not
|
||||
// gonna use no more than one terminal anyway, so this might be fine
|
||||
long timestamp = System.nanoTime();
|
||||
Location firstTerminal = null;
|
||||
SlimefunItem item = SlimefunItem.getById("CHEST_TERMINAL");
|
||||
List<ItemStackAndInteger> items = findAvailableItems(providers);
|
||||
|
||||
try {
|
||||
for (Location l : terminals) {
|
||||
BlockMenu terminal = BlockStorage.getInventory(l);
|
||||
String data = BlockStorage.getLocationInfo(l, "page");
|
||||
int page = data == null ? 1 : Integer.parseInt(data);
|
||||
|
||||
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];
|
||||
int index = i + (TERMINAL_SLOTS.length * (page - 1));
|
||||
updateTerminal(l, terminal, slot, index, items);
|
||||
}
|
||||
|
||||
if (firstTerminal == null) {
|
||||
firstTerminal = l;
|
||||
}
|
||||
}
|
||||
} catch (Exception | LinkageError x) {
|
||||
item.error("An Exception was caused while trying to tick Chest terminals", x);
|
||||
}
|
||||
|
||||
if (firstTerminal != null) {
|
||||
return Slimefun.getProfiler().closeEntry(firstTerminal, item, timestamp);
|
||||
} else {
|
||||
return System.nanoTime() - timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty(@Nonnull Location l) {
|
||||
markCargoNodeConfigurationDirty(l);
|
||||
@ -357,88 +91,6 @@ abstract class AbstractItemNetwork extends Network {
|
||||
connectorCache.remove(node);
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void updateTerminal(Location l, BlockMenu terminal, int slot, int index, List<ItemStackAndInteger> items) {
|
||||
if (items.size() > index) {
|
||||
ItemStackAndInteger item = items.get(index);
|
||||
|
||||
ItemStack stack = item.getItem().clone();
|
||||
stack.setAmount(1);
|
||||
ItemMeta im = stack.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("");
|
||||
lore.add(ChatColors.color("&7Stored Items: &f" + NumberUtils.getCompactDouble(item.getInt())));
|
||||
|
||||
if (stack.getMaxStackSize() > 1) {
|
||||
int amount = item.getInt() > stack.getMaxStackSize() ? stack.getMaxStackSize() : item.getInt();
|
||||
lore.add(ChatColors.color("&7<Left Click: Request 1 | Right Click: Request " + amount + ">"));
|
||||
} else {
|
||||
lore.add(ChatColors.color("&7<Left Click: Request 1>"));
|
||||
}
|
||||
|
||||
lore.add("");
|
||||
|
||||
if (im.hasLore()) {
|
||||
lore.addAll(im.getLore());
|
||||
}
|
||||
|
||||
im.setLore(lore);
|
||||
stack.setItemMeta(im);
|
||||
terminal.replaceExistingItem(slot, stack);
|
||||
terminal.addMenuClickHandler(slot, (p, sl, is, action) -> {
|
||||
int amount = item.getInt() > item.getItem().getMaxStackSize() ? item.getItem().getMaxStackSize() : item.getInt();
|
||||
ItemStack requestedItem = new CustomItemStack(item.getItem(), action.isRightClicked() ? amount : 1);
|
||||
itemRequests.add(new ItemRequest(l, 44, requestedItem, ItemTransportFlow.WITHDRAW));
|
||||
return false;
|
||||
});
|
||||
|
||||
} else {
|
||||
terminal.replaceExistingItem(slot, terminalPlaceholderItem);
|
||||
terminal.addMenuClickHandler(slot, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private List<ItemStackAndInteger> findAvailableItems(@Nonnull Set<Location> providers) {
|
||||
List<ItemStackAndInteger> items = new LinkedList<>();
|
||||
|
||||
for (Location l : providers) {
|
||||
Optional<Block> block = getAttachedBlock(l);
|
||||
|
||||
if (block.isPresent()) {
|
||||
findAllItems(items, l, block.get());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(items, Comparator.comparingInt(item -> -item.getInt()));
|
||||
return items;
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void findAllItems(List<ItemStackAndInteger> items, Location l, Block target) {
|
||||
UniversalBlockMenu menu = BlockStorage.getUniversalInventory(target);
|
||||
|
||||
if (menu != null) {
|
||||
for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) {
|
||||
ItemStack is = menu.getItemInSlot(slot);
|
||||
filter(is, items, l);
|
||||
}
|
||||
} else if (BlockStorage.hasInventory(target)) {
|
||||
BlockMenu blockMenu = BlockStorage.getInventory(target);
|
||||
handleWithdraw(blockMenu, items, l);
|
||||
} else if (CargoUtils.hasInventory(target)) {
|
||||
BlockState state = PaperLib.getBlockState(target, false).getState();
|
||||
|
||||
if (state instanceof InventoryHolder) {
|
||||
Inventory inv = ((InventoryHolder) state).getInventory();
|
||||
|
||||
for (ItemStack is : inv.getContents()) {
|
||||
filter(is, items, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void handleWithdraw(DirtyChestMenu menu, List<ItemStackAndInteger> items, Location l) {
|
||||
for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) {
|
||||
@ -464,8 +116,7 @@ abstract class AbstractItemNetwork extends Network {
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
protected ItemFilter getItemFilter(@Nonnull Block node) {
|
||||
protected @Nonnull ItemFilter getItemFilter(@Nonnull Block node) {
|
||||
Location loc = node.getLocation();
|
||||
ItemFilter filter = filterCache.get(loc);
|
||||
|
||||
|
@ -50,13 +50,11 @@ public class CargoNet extends AbstractItemNetwork implements HologramOwner {
|
||||
protected final Map<Location, Integer> roundRobin = new HashMap<>();
|
||||
private int tickDelayThreshold = 0;
|
||||
|
||||
@Nullable
|
||||
public static CargoNet getNetworkFromLocation(@Nonnull Location l) {
|
||||
public static @Nullable CargoNet getNetworkFromLocation(@Nonnull Location l) {
|
||||
return Slimefun.getNetworkManager().getNetworkFromLocation(l, CargoNet.class).orElse(null);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static CargoNet getNetworkFromLocationOrCreate(@Nonnull Location l) {
|
||||
public static @Nonnull CargoNet getNetworkFromLocationOrCreate(@Nonnull Location l) {
|
||||
Optional<CargoNet> cargoNetwork = Slimefun.getNetworkManager().getNetworkFromLocation(l, CargoNet.class);
|
||||
|
||||
if (cargoNetwork.isPresent()) {
|
||||
@ -120,9 +118,6 @@ public class CargoNet extends AbstractItemNetwork implements HologramOwner {
|
||||
if (from == NetworkComponent.TERMINUS) {
|
||||
inputNodes.remove(l);
|
||||
outputNodes.remove(l);
|
||||
terminals.remove(l);
|
||||
imports.remove(l);
|
||||
exports.remove(l);
|
||||
}
|
||||
|
||||
if (to == NetworkComponent.TERMINUS) {
|
||||
@ -135,15 +130,6 @@ public class CargoNet extends AbstractItemNetwork implements HologramOwner {
|
||||
case "CARGO_NODE_OUTPUT_ADVANCED":
|
||||
outputNodes.add(l);
|
||||
break;
|
||||
case "CHEST_TERMINAL":
|
||||
terminals.add(l);
|
||||
break;
|
||||
case "CT_IMPORT_BUS":
|
||||
imports.add(l);
|
||||
break;
|
||||
case "CT_EXPORT_BUS":
|
||||
exports.add(l);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -173,34 +159,27 @@ public class CargoNet extends AbstractItemNetwork implements HologramOwner {
|
||||
// Reset the internal threshold, so we can start skipping again
|
||||
tickDelayThreshold = 0;
|
||||
|
||||
// Chest Terminal Stuff
|
||||
Set<Location> chestTerminalInputs = new HashSet<>();
|
||||
Set<Location> chestTerminalOutputs = new HashSet<>();
|
||||
|
||||
Map<Location, Integer> inputs = mapInputNodes(chestTerminalInputs);
|
||||
Map<Integer, List<Location>> outputs = mapOutputNodes(chestTerminalOutputs);
|
||||
Map<Location, Integer> inputs = mapInputNodes();
|
||||
Map<Integer, List<Location>> outputs = mapOutputNodes();
|
||||
|
||||
if (BlockStorage.getLocationInfo(b.getLocation(), "visualizer") == null) {
|
||||
display();
|
||||
}
|
||||
|
||||
Slimefun.getProfiler().scheduleEntries((terminals.isEmpty() ? 1 : 2) + inputs.size());
|
||||
Slimefun.getProfiler().scheduleEntries(inputs.size() + 1);
|
||||
|
||||
CargoNetworkTask runnable = new CargoNetworkTask(this, inputs, outputs, chestTerminalInputs, chestTerminalOutputs);
|
||||
CargoNetworkTask runnable = new CargoNetworkTask(this, inputs, outputs);
|
||||
Slimefun.runSync(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private Map<Location, Integer> mapInputNodes(@Nonnull Set<Location> chestTerminalNodes) {
|
||||
private @Nonnull Map<Location, Integer> mapInputNodes() {
|
||||
Map<Location, Integer> inputs = new HashMap<>();
|
||||
|
||||
for (Location node : inputNodes) {
|
||||
int frequency = getFrequency(node);
|
||||
|
||||
if (frequency == 16) {
|
||||
chestTerminalNodes.add(node);
|
||||
} else if (frequency >= 0 && frequency < 16) {
|
||||
if (frequency >= 0 && frequency < 16) {
|
||||
inputs.put(node, frequency);
|
||||
}
|
||||
}
|
||||
@ -208,8 +187,7 @@ public class CargoNet extends AbstractItemNetwork implements HologramOwner {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private Map<Integer, List<Location>> mapOutputNodes(@Nonnull Set<Location> chestTerminalOutputs) {
|
||||
private @Nonnull Map<Integer, List<Location>> mapOutputNodes() {
|
||||
Map<Integer, List<Location>> output = new HashMap<>();
|
||||
|
||||
List<Location> list = new LinkedList<>();
|
||||
@ -218,11 +196,6 @@ public class CargoNet extends AbstractItemNetwork implements HologramOwner {
|
||||
for (Location node : outputNodes) {
|
||||
int frequency = getFrequency(node);
|
||||
|
||||
if (frequency == 16) {
|
||||
chestTerminalOutputs.add(node);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (frequency != lastFrequency && lastFrequency != -1) {
|
||||
output.merge(lastFrequency, list, (prev, next) -> {
|
||||
prev.addAll(next);
|
||||
|
@ -9,7 +9,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -55,18 +54,13 @@ class CargoNetworkTask implements Runnable {
|
||||
private final Map<Location, Integer> inputs;
|
||||
private final Map<Integer, List<Location>> outputs;
|
||||
|
||||
private final Set<Location> chestTerminalInputs;
|
||||
private final Set<Location> chestTerminalOutputs;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
CargoNetworkTask(CargoNet network, Map<Location, Integer> inputs, Map<Integer, List<Location>> outputs, Set<Location> chestTerminalInputs, Set<Location> chestTerminalOutputs) {
|
||||
CargoNetworkTask(CargoNet network, Map<Location, Integer> inputs, Map<Integer, List<Location>> outputs) {
|
||||
this.network = network;
|
||||
this.manager = Slimefun.getNetworkManager();
|
||||
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
this.chestTerminalInputs = chestTerminalInputs;
|
||||
this.chestTerminalOutputs = chestTerminalOutputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,11 +68,6 @@ class CargoNetworkTask implements Runnable {
|
||||
long timestamp = System.nanoTime();
|
||||
|
||||
try {
|
||||
// Chest Terminal Code
|
||||
if (Slimefun.getIntegrations().isChestTerminalInstalled()) {
|
||||
network.handleItemRequests(inventories, chestTerminalInputs, chestTerminalOutputs);
|
||||
}
|
||||
|
||||
/**
|
||||
* All operations happen here: Everything gets iterated from the Input Nodes.
|
||||
* (Apart from ChestTerminal Buses)
|
||||
@ -94,12 +83,6 @@ class CargoNetworkTask implements Runnable {
|
||||
// This will prevent this timings from showing up for the Cargo Manager
|
||||
timestamp += Slimefun.getProfiler().closeEntry(entry.getKey(), inputNode, nodeTimestamp);
|
||||
}
|
||||
|
||||
// Chest Terminal Code
|
||||
if (Slimefun.getIntegrations().isChestTerminalInstalled()) {
|
||||
// This will deduct any CT timings and attribute them towards the actual terminal
|
||||
timestamp += network.updateTerminals(chestTerminalInputs);
|
||||
}
|
||||
} catch (Exception | LinkageError x) {
|
||||
Slimefun.logger().log(Level.SEVERE, x, () -> "An Exception was caught while ticking a Cargo network @ " + new BlockPosition(network.getRegulator()));
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.networks.cargo;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
|
||||
|
||||
class ItemRequest {
|
||||
|
||||
private final ItemStack item;
|
||||
private final ItemTransportFlow flow;
|
||||
private final Location terminal;
|
||||
private final int slot;
|
||||
|
||||
ItemRequest(Location terminal, int slot, ItemStack item, ItemTransportFlow flow) {
|
||||
this.terminal = terminal;
|
||||
this.item = item;
|
||||
this.slot = slot;
|
||||
this.flow = flow;
|
||||
}
|
||||
|
||||
public Location getTerminal() {
|
||||
return terminal;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public ItemTransportFlow getDirection() {
|
||||
return flow;
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(item, slot, flow, terminal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ItemRequest) {
|
||||
ItemRequest request = (ItemRequest) obj;
|
||||
return Objects.equals(item, request.item) && Objects.equals(terminal, request.terminal) && slot == request.slot && flow == request.flow;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -89,7 +89,6 @@ abstract class AbstractCargoNode extends SimpleSlimefunItem<BlockPlaceHandler> i
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
protected void addChannelSelector(Block b, BlockMenu menu, int slotPrev, int slotCurrent, int slotNext) {
|
||||
boolean isChestTerminalInstalled = Slimefun.getIntegrations().isChestTerminalInstalled();
|
||||
int channel = getSelectedChannel(b);
|
||||
|
||||
menu.replaceExistingItem(slotPrev, new CustomItemStack(HeadTexture.CARGO_ARROW_LEFT.getAsItemStack(), "&bPrevious Channel", "", "&e> Click to decrease the Channel ID by 1"));
|
||||
@ -97,12 +96,8 @@ abstract class AbstractCargoNode extends SimpleSlimefunItem<BlockPlaceHandler> i
|
||||
int newChannel = channel - 1;
|
||||
|
||||
if (newChannel < 0) {
|
||||
if (isChestTerminalInstalled) {
|
||||
newChannel = 16;
|
||||
} else {
|
||||
newChannel = 15;
|
||||
}
|
||||
}
|
||||
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(newChannel));
|
||||
updateBlockMenu(menu, b);
|
||||
@ -121,11 +116,7 @@ abstract class AbstractCargoNode extends SimpleSlimefunItem<BlockPlaceHandler> i
|
||||
menu.addMenuClickHandler(slotNext, (p, slot, item, action) -> {
|
||||
int newChannel = channel + 1;
|
||||
|
||||
if (isChestTerminalInstalled) {
|
||||
if (newChannel > 16) {
|
||||
newChannel = 0;
|
||||
}
|
||||
} else if (newChannel > 15) {
|
||||
if (newChannel > 15) {
|
||||
newChannel = 0;
|
||||
}
|
||||
|
||||
|
@ -60,9 +60,6 @@ public class IntegrationsManager {
|
||||
private boolean isItemsAdderInstalled = false;
|
||||
private boolean isOrebfuscatorInstalled = false;
|
||||
|
||||
// Addon support
|
||||
private boolean isChestTerminalInstalled = false;
|
||||
|
||||
/**
|
||||
* This initializes the {@link IntegrationsManager}
|
||||
*
|
||||
@ -150,25 +147,6 @@ public class IntegrationsManager {
|
||||
new OrebfuscatorIntegration(plugin).register();
|
||||
isOrebfuscatorInstalled = true;
|
||||
});
|
||||
|
||||
isChestTerminalInstalled = isAddonInstalled("ChestTerminal");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks if the given addon is installed.
|
||||
*
|
||||
* @param addon
|
||||
* The name of the addon
|
||||
*
|
||||
* @return Whether that addon is installed on the {@link Server}
|
||||
*/
|
||||
private boolean isAddonInstalled(@Nonnull String addon) {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled(addon)) {
|
||||
Slimefun.logger().log(Level.INFO, "Hooked into Slimefun Addon: {0}", addon);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -328,10 +306,6 @@ public class IntegrationsManager {
|
||||
return isItemsAdderInstalled;
|
||||
}
|
||||
|
||||
public boolean isChestTerminalInstalled() {
|
||||
return isChestTerminalInstalled;
|
||||
}
|
||||
|
||||
public boolean isOrebfuscatorInstalled() {
|
||||
return isOrebfuscatorInstalled;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user