Transmitter Network Interface
This commit is contained in:
parent
503c4eb0b5
commit
837689a061
5 changed files with 56 additions and 19 deletions
|
@ -19,7 +19,7 @@ import net.minecraftforge.event.ForgeSubscribe;
|
||||||
import net.minecraftforge.event.world.ChunkEvent;
|
import net.minecraftforge.event.world.ChunkEvent;
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
|
||||||
public class GasNetwork
|
public class GasNetwork implements ITransmitterNetwork
|
||||||
{
|
{
|
||||||
public Set<IPressurizedTube> tubes = new HashSet<IPressurizedTube>();
|
public Set<IPressurizedTube> tubes = new HashSet<IPressurizedTube>();
|
||||||
|
|
||||||
|
@ -309,4 +309,14 @@ public class GasNetwork
|
||||||
{
|
{
|
||||||
return "[GasNetwork] " + tubes.size() + " pipes, " + possibleAcceptors.size() + " acceptors.";
|
return "[GasNetwork] " + tubes.size() + " pipes, " + possibleAcceptors.size() + " acceptors.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void tick()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize()
|
||||||
|
{
|
||||||
|
return tubes.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
8
common/mekanism/api/ITransmitterNetwork.java
Normal file
8
common/mekanism/api/ITransmitterNetwork.java
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package mekanism.api;
|
||||||
|
|
||||||
|
public interface ITransmitterNetwork
|
||||||
|
{
|
||||||
|
public void tick();
|
||||||
|
|
||||||
|
public int getSize();
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package mekanism.common;
|
package mekanism.api;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashSet;
|
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.common.registry.TickRegistry;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
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);
|
TickRegistry.registerTickHandler(this, Side.SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnergyNetworkRegistry getInstance()
|
public static TransmitterNetworkRegistry getInstance()
|
||||||
{
|
{
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerNetwork(EnergyNetwork network)
|
public void registerNetwork(ITransmitterNetwork network)
|
||||||
{
|
{
|
||||||
networks.add(network);
|
networks.add(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeNetwork(EnergyNetwork network)
|
public void removeNetwork(ITransmitterNetwork network)
|
||||||
{
|
{
|
||||||
if(networks.contains(network))
|
if(networks.contains(network))
|
||||||
{
|
{
|
||||||
|
@ -40,14 +40,13 @@ public class EnergyNetworkRegistry implements ITickHandler
|
||||||
|
|
||||||
public void pruneEmptyNetworks()
|
public void pruneEmptyNetworks()
|
||||||
{
|
{
|
||||||
for(EnergyNetwork e : networks)
|
for(ITransmitterNetwork e : networks)
|
||||||
{
|
{
|
||||||
if(e.cables.size() == 0)
|
if(e.getSize() == 0)
|
||||||
{
|
{
|
||||||
removeNetwork(e);
|
removeNetwork(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,12 +54,12 @@ public class EnergyNetworkRegistry implements ITickHandler
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
||||||
{
|
{
|
||||||
Set<EnergyNetwork> iterNetworks = (Set<EnergyNetwork>) networks.clone();
|
Set<ITransmitterNetwork> iterNetworks = (Set<ITransmitterNetwork>) networks.clone();
|
||||||
for(EnergyNetwork net : iterNetworks)
|
for(ITransmitterNetwork net : iterNetworks)
|
||||||
{
|
{
|
||||||
if(networks.contains(net))
|
if(networks.contains(net))
|
||||||
{
|
{
|
||||||
|
@ -84,6 +83,6 @@ public class EnergyNetworkRegistry implements ITickHandler
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return networks.toString();
|
return "Network Registry:\n" + networks;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,7 +13,9 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import mekanism.api.IStrictEnergyAcceptor;
|
import mekanism.api.IStrictEnergyAcceptor;
|
||||||
|
import mekanism.api.ITransmitterNetwork;
|
||||||
import mekanism.api.Object3D;
|
import mekanism.api.Object3D;
|
||||||
|
import mekanism.api.TransmitterNetworkRegistry;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
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.PowerReceiver;
|
||||||
import buildcraft.api.power.PowerHandler.Type;
|
import buildcraft.api.power.PowerHandler.Type;
|
||||||
|
|
||||||
public class EnergyNetwork
|
public class EnergyNetwork implements ITransmitterNetwork
|
||||||
{
|
{
|
||||||
public HashSet<IUniversalCable> cables = new HashSet<IUniversalCable>();
|
public HashSet<IUniversalCable> cables = new HashSet<IUniversalCable>();
|
||||||
|
|
||||||
|
@ -438,4 +440,10 @@ public class EnergyNetwork
|
||||||
{
|
{
|
||||||
return joulesLastTick * 20;
|
return joulesLastTick * 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize()
|
||||||
|
{
|
||||||
|
return cables.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import mekanism.api.ITransmitterNetwork;
|
||||||
import mekanism.api.Object3D;
|
import mekanism.api.Object3D;
|
||||||
|
import mekanism.api.TransmitterNetworkRegistry;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
@ -22,7 +24,7 @@ import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
|
||||||
public class FluidNetwork
|
public class FluidNetwork implements ITransmitterNetwork
|
||||||
{
|
{
|
||||||
public Set<IMechanicalPipe> pipes = new HashSet<IMechanicalPipe>();
|
public Set<IMechanicalPipe> pipes = new HashSet<IMechanicalPipe>();
|
||||||
|
|
||||||
|
@ -301,9 +303,19 @@ public class FluidNetwork
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void tick()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "[FluidNetwork] " + pipes.size() + " pipes, " + possibleAcceptors.size() + " acceptors.";
|
return "[FluidNetwork] " + pipes.size() + " pipes, " + possibleAcceptors.size() + " acceptors.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize()
|
||||||
|
{
|
||||||
|
return pipes.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue