Mekanism-tilera-Edition/common/mekanism/api/TransmitterNetworkRegistry.java

89 lines
1.7 KiB
Java
Raw Normal View History

2013-08-04 02:18:43 +02:00
package mekanism.api;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;
2013-08-04 02:18:43 +02:00
public class TransmitterNetworkRegistry implements ITickHandler
{
2013-08-04 02:18:43 +02:00
private static TransmitterNetworkRegistry INSTANCE = new TransmitterNetworkRegistry();
2013-08-04 02:18:43 +02:00
private HashSet<ITransmitterNetwork> networks = new HashSet<ITransmitterNetwork>();
2013-08-04 02:18:43 +02:00
public TransmitterNetworkRegistry()
{
TickRegistry.registerTickHandler(this, Side.SERVER);
}
2013-08-04 02:18:43 +02:00
public static TransmitterNetworkRegistry getInstance()
{
return INSTANCE;
}
2013-08-04 02:18:43 +02:00
public void registerNetwork(ITransmitterNetwork network)
{
networks.add(network);
}
2013-08-04 02:18:43 +02:00
public void removeNetwork(ITransmitterNetwork network)
{
if(networks.contains(network))
{
networks.remove(network);
}
}
2013-07-31 22:44:53 +02:00
public void pruneEmptyNetworks()
{
2013-08-04 02:18:43 +02:00
for(ITransmitterNetwork e : networks)
2013-07-28 04:32:41 +02:00
{
2013-08-04 02:18:43 +02:00
if(e.getSize() == 0)
2013-07-28 04:32:41 +02:00
{
removeNetwork(e);
}
}
}
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
return;
}
2013-08-04 02:18:43 +02:00
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
2013-08-04 02:18:43 +02:00
Set<ITransmitterNetwork> iterNetworks = (Set<ITransmitterNetwork>) networks.clone();
for(ITransmitterNetwork net : iterNetworks)
{
2013-07-28 04:32:41 +02:00
if(networks.contains(net))
{
net.tick();
}
}
}
@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.SERVER);
}
@Override
public String getLabel()
{
return "Mekanism Energy Networks";
}
@Override
public String toString()
{
2013-08-04 02:18:43 +02:00
return "Network Registry:\n" + networks;
}
}