diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java index 506d1ce08..526634444 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java @@ -29,7 +29,7 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.energy.EnergyNet; -import me.mrCookieSlime.Slimefun.api.energy.EnergyNet.NetworkComponent; +import me.mrCookieSlime.Slimefun.api.energy.EnergyNetComponent; import me.mrCookieSlime.Slimefun.api.energy.EnergyTicker; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; @@ -405,7 +405,7 @@ public class SlimefunItem { } else if (h instanceof EnergyTicker) { this.energyTicker = (EnergyTicker) h; - EnergyNet.registerComponent(getID(), NetworkComponent.SOURCE); + EnergyNet.registerComponent(getID(), EnergyNetComponent.SOURCE); } } } @@ -480,7 +480,7 @@ public class SlimefunItem { public void registerChargeableBlock(boolean slimefun, int capacity) { this.register(slimefun); ChargableBlock.registerChargableBlock(id, capacity, true); - EnergyNet.registerComponent(id, NetworkComponent.CONSUMER); + EnergyNet.registerComponent(id, EnergyNetComponent.CONSUMER); } public void registerUnrechargeableBlock(boolean slimefun, int capacity) { @@ -495,12 +495,12 @@ public class SlimefunItem { public void registerEnergyDistributor(boolean slimefun) { this.register(slimefun); - EnergyNet.registerComponent(id, NetworkComponent.DISTRIBUTOR); + EnergyNet.registerComponent(id, EnergyNetComponent.DISTRIBUTOR); } public void registerDistibutingCapacitor(boolean slimefun, final int capacity) { this.register(slimefun); - EnergyNet.registerComponent(id, NetworkComponent.DISTRIBUTOR); + EnergyNet.registerComponent(id, EnergyNetComponent.DISTRIBUTOR); ChargableBlock.registerCapacitor(id, capacity); } diff --git a/src/me/mrCookieSlime/Slimefun/api/energy/EnergyNet.java b/src/me/mrCookieSlime/Slimefun/api/energy/EnergyNet.java index cc694bf9b..c923f0a89 100644 --- a/src/me/mrCookieSlime/Slimefun/api/energy/EnergyNet.java +++ b/src/me/mrCookieSlime/Slimefun/api/energy/EnergyNet.java @@ -13,16 +13,10 @@ import me.mrCookieSlime.Slimefun.SlimefunStartup; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.network.Network; +import me.mrCookieSlime.Slimefun.api.network.NetworkComponent; import me.mrCookieSlime.Slimefun.holograms.EnergyHologram; public class EnergyNet extends Network { - - public static enum NetworkComponent { - SOURCE, - DISTRIBUTOR, - CONSUMER, - NONE; - } private static final int RANGE = 6; @@ -30,27 +24,27 @@ public class EnergyNet extends Network { public static Set machinesStorage = new HashSet<>(); public static Set machinesOutput = new HashSet<>(); - public static NetworkComponent getComponent(Block b) { + public static EnergyNetComponent getComponent(Block b) { return getComponent(b.getLocation()); } - public static NetworkComponent getComponent(String id) { - if (machinesInput.contains(id)) return NetworkComponent.SOURCE; - if (machinesStorage.contains(id)) return NetworkComponent.DISTRIBUTOR; - if (machinesOutput.contains(id)) return NetworkComponent.CONSUMER; - return NetworkComponent.NONE; + public static EnergyNetComponent getComponent(String id) { + if (machinesInput.contains(id)) return EnergyNetComponent.SOURCE; + if (machinesStorage.contains(id)) return EnergyNetComponent.DISTRIBUTOR; + if (machinesOutput.contains(id)) return EnergyNetComponent.CONSUMER; + return EnergyNetComponent.NONE; } - public static NetworkComponent getComponent(Location l) { - if (!BlockStorage.hasBlockInfo(l)) return NetworkComponent.NONE; + public static EnergyNetComponent getComponent(Location l) { + if (!BlockStorage.hasBlockInfo(l)) return EnergyNetComponent.NONE; String id = BlockStorage.checkID(l); - if (machinesInput.contains(id)) return NetworkComponent.SOURCE; - if (machinesStorage.contains(id)) return NetworkComponent.DISTRIBUTOR; - if (machinesOutput.contains(id)) return NetworkComponent.CONSUMER; - return NetworkComponent.NONE; + if (machinesInput.contains(id)) return EnergyNetComponent.SOURCE; + if (machinesStorage.contains(id)) return EnergyNetComponent.DISTRIBUTOR; + if (machinesOutput.contains(id)) return EnergyNetComponent.CONSUMER; + return EnergyNetComponent.NONE; } - public static void registerComponent(String id, NetworkComponent component) { + public static void registerComponent(String id, EnergyNetComponent component) { switch (component) { case CONSUMER: machinesOutput.add(id); @@ -91,24 +85,25 @@ public class EnergyNet extends Network { return RANGE; } - public Network.Component classifyLocation(Location l) { - if (regulator.equals(l)) return Network.Component.REGULATOR; + public NetworkComponent classifyLocation(Location l) { + if (regulator.equals(l)) return NetworkComponent.REGULATOR; switch (getComponent(l)) { case DISTRIBUTOR: - return Network.Component.CONNECTOR; + return NetworkComponent.CONNECTOR; case CONSUMER: case SOURCE: - return Network.Component.TERMINUS; + return NetworkComponent.TERMINUS; default: return null; } } - public void locationClassificationChange(Location l, Network.Component from, Network.Component to) { - if (from == Network.Component.TERMINUS) { + public void locationClassificationChange(Location l, NetworkComponent from, NetworkComponent to) { + if (from == NetworkComponent.TERMINUS) { input.remove(l); output.remove(l); } + switch (getComponent(l)) { case DISTRIBUTOR: if (ChargableBlock.isCapacitor(l)) storage.add(l); diff --git a/src/me/mrCookieSlime/Slimefun/api/energy/EnergyNetComponent.java b/src/me/mrCookieSlime/Slimefun/api/energy/EnergyNetComponent.java new file mode 100644 index 000000000..76bfe8714 --- /dev/null +++ b/src/me/mrCookieSlime/Slimefun/api/energy/EnergyNetComponent.java @@ -0,0 +1,10 @@ +package me.mrCookieSlime.Slimefun.api.energy; + +public enum EnergyNetComponent { + + SOURCE, + DISTRIBUTOR, + CONSUMER, + NONE; + +} \ No newline at end of file diff --git a/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java b/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java index 220b47f65..0e3a8629c 100644 --- a/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java +++ b/src/me/mrCookieSlime/Slimefun/api/item_transport/CargoNet.java @@ -30,6 +30,7 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu; import me.mrCookieSlime.Slimefun.api.network.Network; +import me.mrCookieSlime.Slimefun.api.network.NetworkComponent; import me.mrCookieSlime.Slimefun.holograms.CargoHologram; public class CargoNet extends Network { @@ -86,28 +87,28 @@ public class CargoNet extends Network { return RANGE; } - public Network.Component classifyLocation(Location l) { + public NetworkComponent classifyLocation(Location l) { String id = BlockStorage.checkID(l); if (id == null) return null; switch(id) { case "CARGO_MANAGER": - return Component.REGULATOR; + return NetworkComponent.REGULATOR; case "CARGO_NODE": - return Component.CONNECTOR; + return NetworkComponent.CONNECTOR; case "CARGO_NODE_INPUT": case "CARGO_NODE_OUTPUT": case "CARGO_NODE_OUTPUT_ADVANCED": case "CT_IMPORT_BUS": case "CT_EXPORT_BUS": case "CHEST_TERMINAL": - return Component.TERMINUS; + return NetworkComponent.TERMINUS; default: return null; } } - public void locationClassificationChange(Location l, Component from, Component to) { - if (from == Component.TERMINUS) { + public void locationClassificationChange(Location l, NetworkComponent from, NetworkComponent to) { + if (from == NetworkComponent.TERMINUS) { inputNodes.remove(l); outputNodes.remove(l); advancedOutputNodes.remove(l); @@ -115,7 +116,7 @@ public class CargoNet extends Network { imports.remove(l); exports.remove(l); } - if (to == Component.TERMINUS) { + if (to == NetworkComponent.TERMINUS) { switch(BlockStorage.checkID(l)) { case "CARGO_NODE_INPUT": inputNodes.add(l); diff --git a/src/me/mrCookieSlime/Slimefun/api/network/Network.java b/src/me/mrCookieSlime/Slimefun/api/network/Network.java index fce90e4bb..4bf4d5fea 100644 --- a/src/me/mrCookieSlime/Slimefun/api/network/Network.java +++ b/src/me/mrCookieSlime/Slimefun/api/network/Network.java @@ -49,16 +49,9 @@ public abstract class Network { } } - public static enum Component { - CONNECTOR, - REGULATOR, - TERMINUS; - } - - public abstract int getRange(); - public abstract Component classifyLocation(Location l); - public abstract void locationClassificationChange(Location l, Component from, Component to); + public abstract NetworkComponent classifyLocation(Location l); + public abstract void locationClassificationChange(Location l, NetworkComponent from, NetworkComponent to); protected Location regulator; private Queue nodeQueue = new ArrayDeque<>(); @@ -94,15 +87,15 @@ public abstract class Network { return connectedLocations.contains(l); } - private Component getCurrentClassification(Location l) { + private NetworkComponent getCurrentClassification(Location l) { if(regulatorNodes.contains(l)) { - return Component.REGULATOR; + return NetworkComponent.REGULATOR; } else if(connectorNodes.contains(l)) { - return Component.CONNECTOR; + return NetworkComponent.CONNECTOR; } else if(terminusNodes.contains(l)) { - return Component.TERMINUS; + return NetworkComponent.TERMINUS; } return null; } @@ -111,28 +104,28 @@ public abstract class Network { int steps = 0; while (nodeQueue.peek() != null) { Location l = nodeQueue.poll(); - Component currentAssignment = getCurrentClassification(l); - Component classification = classifyLocation(l); + NetworkComponent currentAssignment = getCurrentClassification(l); + NetworkComponent classification = classifyLocation(l); if (classification != currentAssignment) { - if (currentAssignment == Component.REGULATOR || currentAssignment == Component.CONNECTOR) { + if (currentAssignment == NetworkComponent.REGULATOR || currentAssignment == NetworkComponent.CONNECTOR) { // Requires a complete rebuild of the network, so we just throw the current one away. unregisterNetwork(this); return; } - else if (currentAssignment == Component.TERMINUS) { + else if (currentAssignment == NetworkComponent.TERMINUS) { terminusNodes.remove(l); } - if (classification == Component.REGULATOR) { + if (classification == NetworkComponent.REGULATOR) { regulatorNodes.add(l); discoverNeighbors(l); } - else if(classification == Component.CONNECTOR) { + else if(classification == NetworkComponent.CONNECTOR) { connectorNodes.add(l); discoverNeighbors(l); } - else if(classification == Component.TERMINUS) { + else if(classification == NetworkComponent.TERMINUS) { terminusNodes.add(l); } diff --git a/src/me/mrCookieSlime/Slimefun/api/network/NetworkComponent.java b/src/me/mrCookieSlime/Slimefun/api/network/NetworkComponent.java new file mode 100644 index 000000000..dd8bc53c7 --- /dev/null +++ b/src/me/mrCookieSlime/Slimefun/api/network/NetworkComponent.java @@ -0,0 +1,7 @@ +package me.mrCookieSlime.Slimefun.api.network; + +public enum NetworkComponent { + CONNECTOR, + REGULATOR, + TERMINUS; +} \ No newline at end of file