Transmitter Network Interface

This commit is contained in:
Ben Spiers 2013-08-04 01:18:43 +01:00
parent 503c4eb0b5
commit 837689a061
5 changed files with 56 additions and 19 deletions

View file

@ -19,7 +19,7 @@ import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.ChunkEvent;
import cpw.mods.fml.common.FMLCommonHandler;
public class GasNetwork
public class GasNetwork implements ITransmitterNetwork
{
public Set<IPressurizedTube> tubes = new HashSet<IPressurizedTube>();
@ -309,4 +309,14 @@ public class GasNetwork
{
return "[GasNetwork] " + tubes.size() + " pipes, " + possibleAcceptors.size() + " acceptors.";
}
public void tick()
{
}
@Override
public int getSize()
{
return tubes.size();
}
}

View file

@ -0,0 +1,8 @@
package mekanism.api;
public interface ITransmitterNetwork
{
public void tick();
public int getSize();
}

View file

@ -1,4 +1,4 @@
package mekanism.common;
package mekanism.api;
import java.util.EnumSet;
import java.util.HashSet;
@ -9,28 +9,28 @@ import cpw.mods.fml.common.TickType;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;
public class EnergyNetworkRegistry implements ITickHandler
public class TransmitterNetworkRegistry implements ITickHandler
{
private static EnergyNetworkRegistry INSTANCE = new EnergyNetworkRegistry();
private static TransmitterNetworkRegistry INSTANCE = new TransmitterNetworkRegistry();
private HashSet<EnergyNetwork> networks = new HashSet<EnergyNetwork>();
private HashSet<ITransmitterNetwork> networks = new HashSet<ITransmitterNetwork>();
public EnergyNetworkRegistry()
public TransmitterNetworkRegistry()
{
TickRegistry.registerTickHandler(this, Side.SERVER);
}
public static EnergyNetworkRegistry getInstance()
public static TransmitterNetworkRegistry getInstance()
{
return INSTANCE;
}
public void registerNetwork(EnergyNetwork network)
public void registerNetwork(ITransmitterNetwork network)
{
networks.add(network);
}
public void removeNetwork(EnergyNetwork network)
public void removeNetwork(ITransmitterNetwork network)
{
if(networks.contains(network))
{
@ -40,14 +40,13 @@ public class EnergyNetworkRegistry implements ITickHandler
public void pruneEmptyNetworks()
{
for(EnergyNetwork e : networks)
for(ITransmitterNetwork e : networks)
{
if(e.cables.size() == 0)
if(e.getSize() == 0)
{
removeNetwork(e);
}
}
}
@Override
@ -55,12 +54,12 @@ public class EnergyNetworkRegistry implements ITickHandler
{
return;
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
Set<EnergyNetwork> iterNetworks = (Set<EnergyNetwork>) networks.clone();
for(EnergyNetwork net : iterNetworks)
Set<ITransmitterNetwork> iterNetworks = (Set<ITransmitterNetwork>) networks.clone();
for(ITransmitterNetwork net : iterNetworks)
{
if(networks.contains(net))
{
@ -84,6 +83,6 @@ public class EnergyNetworkRegistry implements ITickHandler
@Override
public String toString()
{
return networks.toString();
return "Network Registry:\n" + networks;
}
}

View file

@ -13,7 +13,9 @@ import java.util.Map;
import java.util.Set;
import mekanism.api.IStrictEnergyAcceptor;
import mekanism.api.ITransmitterNetwork;
import mekanism.api.Object3D;
import mekanism.api.TransmitterNetworkRegistry;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
@ -23,7 +25,7 @@ import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
public class EnergyNetwork
public class EnergyNetwork implements ITransmitterNetwork
{
public HashSet<IUniversalCable> cables = new HashSet<IUniversalCable>();
@ -438,4 +440,10 @@ public class EnergyNetwork
{
return joulesLastTick * 20;
}
@Override
public int getSize()
{
return cables.size();
}
}

View file

@ -10,7 +10,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import mekanism.api.ITransmitterNetwork;
import mekanism.api.Object3D;
import mekanism.api.TransmitterNetworkRegistry;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
@ -22,7 +24,7 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import cpw.mods.fml.common.FMLCommonHandler;
public class FluidNetwork
public class FluidNetwork implements ITransmitterNetwork
{
public Set<IMechanicalPipe> pipes = new HashSet<IMechanicalPipe>();
@ -301,9 +303,19 @@ public class FluidNetwork
}
}
public void tick()
{
}
@Override
public String toString()
{
return "[FluidNetwork] " + pipes.size() + " pipes, " + possibleAcceptors.size() + " acceptors.";
}
@Override
public int getSize()
{
return pipes.size();
}
}