Removed ugly registry system, need to find a better alternative
This commit is contained in:
@@ -1,55 +1,10 @@
|
|||||||
package refinedstorage.api;
|
package refinedstorage.api;
|
||||||
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
|
||||||
import refinedstorage.api.network.INetworkNode;
|
|
||||||
import refinedstorage.api.network.registry.INetworkRegistry;
|
|
||||||
import refinedstorage.api.network.registry.INetworkRegistryProvider;
|
|
||||||
import refinedstorage.api.solderer.ISoldererRegistry;
|
import refinedstorage.api.solderer.ISoldererRegistry;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public final class RefinedStorageAPI {
|
public final class RefinedStorageAPI {
|
||||||
/**
|
/**
|
||||||
* The solderer registry, set in pre-initialization
|
* The solderer registry, set in pre-initialization
|
||||||
*/
|
*/
|
||||||
public static ISoldererRegistry SOLDERER_REGISTRY;
|
public static ISoldererRegistry SOLDERER_REGISTRY;
|
||||||
|
|
||||||
/**
|
|
||||||
* The network registry provider, set in pre-initialization
|
|
||||||
*/
|
|
||||||
public static INetworkRegistryProvider NETWORK_REGISTRY_PROVIDER;
|
|
||||||
|
|
||||||
private static final Map<Integer, INetworkRegistry> NETWORK_REGISTRY = new HashMap<>();
|
|
||||||
|
|
||||||
public static INetworkRegistry getNetworkRegistry(World world) {
|
|
||||||
return getNetworkRegistry(world.provider.getDimension());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeNetworkRegistry(World world) {
|
|
||||||
NETWORK_REGISTRY.remove(world.provider.getDimension());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static INetworkRegistry getNetworkRegistry(int dimension) {
|
|
||||||
if (!NETWORK_REGISTRY.containsKey(dimension)) {
|
|
||||||
NETWORK_REGISTRY.put(dimension, NETWORK_REGISTRY_PROVIDER.provide(dimension));
|
|
||||||
}
|
|
||||||
|
|
||||||
return NETWORK_REGISTRY.get(dimension);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static INetworkMaster getNetwork(INetworkNode node) {
|
|
||||||
for (INetworkRegistry registry : NETWORK_REGISTRY.values()) {
|
|
||||||
for (INetworkMaster network : registry.getNetworks()) {
|
|
||||||
for (INetworkNode otherNode : network.getNodeGraph().all()) {
|
|
||||||
if (node.equals(otherNode)) {
|
|
||||||
return network;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
package refinedstorage.api.network.registry;
|
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A registry of all Refined Storage networks on this server.
|
|
||||||
*/
|
|
||||||
public interface INetworkRegistry {
|
|
||||||
/**
|
|
||||||
* Adds a network to the registry.
|
|
||||||
*
|
|
||||||
* @param network The network
|
|
||||||
*/
|
|
||||||
void addNetwork(@Nonnull INetworkMaster network);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes a network from the registry.
|
|
||||||
*
|
|
||||||
* @param pos The position of the network
|
|
||||||
*/
|
|
||||||
void removeNetwork(@Nonnull BlockPos pos);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return All the networks in this registry
|
|
||||||
*/
|
|
||||||
Collection<INetworkMaster> getNetworks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a network at a position.
|
|
||||||
*
|
|
||||||
* @param pos The position of the network
|
|
||||||
* @return The network
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
INetworkMaster getNetwork(@Nonnull BlockPos pos);
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package refinedstorage.api.network.registry;
|
|
||||||
|
|
||||||
public interface INetworkRegistryProvider {
|
|
||||||
INetworkRegistry provide(int dimension);
|
|
||||||
}
|
|
||||||
@@ -52,8 +52,8 @@ public class NetworkNodeGraph implements INetworkNodeGraph {
|
|||||||
while ((currentPos = toCheck.poll()) != null) {
|
while ((currentPos = toCheck.poll()) != null) {
|
||||||
TileEntity tile = world.getTileEntity(currentPos);
|
TileEntity tile = world.getTileEntity(currentPos);
|
||||||
|
|
||||||
if (tile instanceof TileController && !controller.getPos().equals(tile.getPos())) {
|
if (tile instanceof TileController && !controller.getPos().equals(currentPos)) {
|
||||||
world.createExplosion(null, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), 4.5f, true);
|
world.createExplosion(null, currentPos.getX(), currentPos.getY(), currentPos.getZ(), 3.5f, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(tile instanceof INetworkNode)) {
|
if (!(tile instanceof INetworkNode)) {
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package refinedstorage.apiimpl.network.registry;
|
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
|
||||||
import refinedstorage.api.network.registry.INetworkRegistry;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class NetworkRegistry implements INetworkRegistry {
|
|
||||||
private Map<BlockPos, INetworkMaster> networks = new HashMap<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addNetwork(@Nonnull INetworkMaster network) {
|
|
||||||
networks.put(network.getPosition(), network);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeNetwork(@Nonnull BlockPos pos) {
|
|
||||||
networks.remove(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<INetworkMaster> getNetworks() {
|
|
||||||
return networks.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public INetworkMaster getNetwork(@Nonnull BlockPos pos) {
|
|
||||||
return networks.get(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package refinedstorage.apiimpl.network.registry;
|
|
||||||
|
|
||||||
import refinedstorage.api.network.registry.INetworkRegistry;
|
|
||||||
import refinedstorage.api.network.registry.INetworkRegistryProvider;
|
|
||||||
|
|
||||||
public class NetworkRegistryProvider implements INetworkRegistryProvider {
|
|
||||||
@Override
|
|
||||||
public INetworkRegistry provide(int dimension) {
|
|
||||||
return new NetworkRegistry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package refinedstorage.apiimpl.network.registry;
|
|
||||||
|
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import refinedstorage.api.RefinedStorageAPI;
|
|
||||||
|
|
||||||
public class NetworkRegistryUnloader {
|
|
||||||
@Mod.EventHandler
|
|
||||||
public void onWorldUnload(WorldEvent.Unload e) {
|
|
||||||
RefinedStorageAPI.removeNetworkRegistry(e.getWorld());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,8 +17,6 @@ import refinedstorage.RefinedStorage;
|
|||||||
import refinedstorage.RefinedStorageBlocks;
|
import refinedstorage.RefinedStorageBlocks;
|
||||||
import refinedstorage.RefinedStorageItems;
|
import refinedstorage.RefinedStorageItems;
|
||||||
import refinedstorage.api.RefinedStorageAPI;
|
import refinedstorage.api.RefinedStorageAPI;
|
||||||
import refinedstorage.apiimpl.network.registry.NetworkRegistryProvider;
|
|
||||||
import refinedstorage.apiimpl.network.registry.NetworkRegistryUnloader;
|
|
||||||
import refinedstorage.apiimpl.solderer.*;
|
import refinedstorage.apiimpl.solderer.*;
|
||||||
import refinedstorage.apiimpl.storage.fluid.FluidStorageNBT;
|
import refinedstorage.apiimpl.storage.fluid.FluidStorageNBT;
|
||||||
import refinedstorage.apiimpl.storage.item.ItemStorageNBT;
|
import refinedstorage.apiimpl.storage.item.ItemStorageNBT;
|
||||||
@@ -46,10 +44,6 @@ public class CommonProxy {
|
|||||||
|
|
||||||
RefinedStorageAPI.SOLDERER_REGISTRY = new SoldererRegistry();
|
RefinedStorageAPI.SOLDERER_REGISTRY = new SoldererRegistry();
|
||||||
|
|
||||||
RefinedStorageAPI.NETWORK_REGISTRY_PROVIDER = new NetworkRegistryProvider();
|
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.register(new NetworkRegistryUnloader());
|
|
||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
RefinedStorage.INSTANCE.network.registerMessage(MessageTileDataParameter.class, MessageTileDataParameter.class, id++, Side.CLIENT);
|
RefinedStorage.INSTANCE.network.registerMessage(MessageTileDataParameter.class, MessageTileDataParameter.class, id++, Side.CLIENT);
|
||||||
|
|||||||
@@ -18,14 +18,12 @@ import net.minecraftforge.fluids.FluidStack;
|
|||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.RefinedStorageBlocks;
|
import refinedstorage.RefinedStorageBlocks;
|
||||||
import refinedstorage.api.RefinedStorageAPI;
|
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||||
import refinedstorage.api.autocrafting.ICraftingTask;
|
import refinedstorage.api.autocrafting.ICraftingTask;
|
||||||
import refinedstorage.api.network.*;
|
import refinedstorage.api.network.*;
|
||||||
import refinedstorage.api.network.grid.IFluidGridHandler;
|
import refinedstorage.api.network.grid.IFluidGridHandler;
|
||||||
import refinedstorage.api.network.grid.IItemGridHandler;
|
import refinedstorage.api.network.grid.IItemGridHandler;
|
||||||
import refinedstorage.api.network.registry.INetworkRegistry;
|
|
||||||
import refinedstorage.api.storage.CompareUtils;
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
import refinedstorage.api.storage.fluid.IFluidStorage;
|
import refinedstorage.api.storage.fluid.IFluidStorage;
|
||||||
import refinedstorage.api.storage.fluid.IGroupedFluidStorage;
|
import refinedstorage.api.storage.fluid.IGroupedFluidStorage;
|
||||||
@@ -186,8 +184,6 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
private IControllerEnergyIC2 energyEU;
|
private IControllerEnergyIC2 energyEU;
|
||||||
private ControllerEnergyTesla energyTesla;
|
private ControllerEnergyTesla energyTesla;
|
||||||
|
|
||||||
private boolean destroyed;
|
|
||||||
|
|
||||||
private int lastEnergyDisplay;
|
private int lastEnergyDisplay;
|
||||||
private int lastEnergyComparator;
|
private int lastEnergyComparator;
|
||||||
|
|
||||||
@@ -238,12 +234,6 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
INetworkRegistry registry = RefinedStorageAPI.getNetworkRegistry(worldObj);
|
|
||||||
|
|
||||||
if (!destroyed && registry.getNetwork(pos) == null) {
|
|
||||||
registry.addNetwork(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
energyEU.update();
|
energyEU.update();
|
||||||
|
|
||||||
if (canRun()) {
|
if (canRun()) {
|
||||||
@@ -370,14 +360,12 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
super.onChunkUnload();
|
super.onChunkUnload();
|
||||||
|
|
||||||
energyEU.onChunkUnload();
|
energyEU.onChunkUnload();
|
||||||
|
|
||||||
|
onDestroyed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroyed() {
|
public void onDestroyed() {
|
||||||
nodeGraph.disconnectAll();
|
nodeGraph.disconnectAll();
|
||||||
|
|
||||||
destroyed = true;
|
|
||||||
|
|
||||||
RefinedStorageAPI.getNetworkRegistry(worldObj).removeNetwork(pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGroupedItemStorage getItemStorage() {
|
public IGroupedItemStorage getItemStorage() {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.api.RefinedStorageAPI;
|
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
import refinedstorage.api.network.INetworkNode;
|
import refinedstorage.api.network.INetworkNode;
|
||||||
import refinedstorage.api.network.NetworkUtils;
|
import refinedstorage.api.network.NetworkUtils;
|
||||||
@@ -21,6 +20,7 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
|
|||||||
private boolean active;
|
private boolean active;
|
||||||
private boolean update;
|
private boolean update;
|
||||||
private boolean connected;
|
private boolean connected;
|
||||||
|
private INetworkMaster network;
|
||||||
|
|
||||||
protected boolean rebuildOnUpdateChange;
|
protected boolean rebuildOnUpdateChange;
|
||||||
|
|
||||||
@@ -66,12 +66,18 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnected(INetworkMaster network) {
|
public void onConnected(INetworkMaster network) {
|
||||||
|
this.connected = true;
|
||||||
|
this.network = network;
|
||||||
|
|
||||||
onConnectionChange(network, true);
|
onConnectionChange(network, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnected(INetworkMaster network) {
|
public void onDisconnected(INetworkMaster network) {
|
||||||
onConnectionChange(network, false);
|
onConnectionChange(network, false);
|
||||||
|
|
||||||
|
this.connected = false;
|
||||||
|
this.network = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,7 +92,7 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public INetworkMaster getNetwork() {
|
public INetworkMaster getNetwork() {
|
||||||
return (worldObj != null && !worldObj.isRemote) ? RefinedStorageAPI.getNetwork(this) : null;
|
return network;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,7 +107,7 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
return worldObj.isRemote ? connected : (getNetwork() != null);
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user