Base transmitter TileEntity class
This commit is contained in:
parent
f64ea42e43
commit
046cab7880
5 changed files with 86 additions and 167 deletions
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.HashSet;
|
||||
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.api.TransmitterNetworkRegistry;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.network.PacketDataRequest;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -17,29 +16,15 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileEntityLogisticalTransporter extends TileEntity implements ILogisticalTransporter, ITileNetwork
|
||||
public class TileEntityLogisticalTransporter extends TileEntityTransmitter<InventoryNetwork> implements ILogisticalTransporter, ITileNetwork
|
||||
{
|
||||
/** The inventory network currently in use by this transporter segment. */
|
||||
public InventoryNetwork inventoryNetwork;
|
||||
|
||||
/** This transporter's active state. */
|
||||
public boolean isActive = false;
|
||||
|
||||
@Override
|
||||
public InventoryNetwork getNetwork()
|
||||
{
|
||||
if(inventoryNetwork == null)
|
||||
{
|
||||
inventoryNetwork = new InventoryNetwork(this);
|
||||
}
|
||||
|
||||
return inventoryNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryNetwork getNetwork(boolean createIfNull)
|
||||
{
|
||||
if(inventoryNetwork == null && createIfNull)
|
||||
if(theNetwork == null && createIfNull)
|
||||
{
|
||||
TileEntity[] adjacentTransporters = CableUtils.getConnectedCables(this);
|
||||
HashSet<InventoryNetwork> connectedNets = new HashSet<InventoryNetwork>();
|
||||
|
@ -53,20 +38,20 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ILogi
|
|||
}
|
||||
if(connectedNets.size() == 0 || worldObj.isRemote)
|
||||
{
|
||||
inventoryNetwork = new InventoryNetwork(this);
|
||||
theNetwork = new InventoryNetwork(this);
|
||||
}
|
||||
else if(connectedNets.size() == 1)
|
||||
{
|
||||
inventoryNetwork = connectedNets.iterator().next();
|
||||
inventoryNetwork.transmitters.add(this);
|
||||
theNetwork = connectedNets.iterator().next();
|
||||
theNetwork.transmitters.add(this);
|
||||
}
|
||||
else {
|
||||
inventoryNetwork = new InventoryNetwork(connectedNets);
|
||||
inventoryNetwork.transmitters.add(this);
|
||||
theNetwork = new InventoryNetwork(connectedNets);
|
||||
theNetwork.transmitters.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
return inventoryNetwork;
|
||||
return theNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,22 +71,12 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ILogi
|
|||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(InventoryNetwork network)
|
||||
{
|
||||
if(network != inventoryNetwork)
|
||||
{
|
||||
removeFromNetwork();
|
||||
inventoryNetwork = network;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromNetwork()
|
||||
{
|
||||
if(inventoryNetwork != null)
|
||||
if(theNetwork != null)
|
||||
{
|
||||
inventoryNetwork.removeTransmitter(this);
|
||||
theNetwork.removeTransmitter(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,17 +99,10 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ILogi
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
invalidate();
|
||||
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.util.Arrays;
|
|||
import java.util.HashSet;
|
||||
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.api.TransmitterNetworkRegistry;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.network.PacketDataRequest;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -24,7 +23,7 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalPipe, IFluidHandler, ITileNetwork
|
||||
public class TileEntityMechanicalPipe extends TileEntityTransmitter<FluidNetwork> implements IMechanicalPipe, IFluidHandler, ITileNetwork
|
||||
{
|
||||
/** The fake tank used for fluid transfer calculations. */
|
||||
public FluidTank dummyTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
||||
|
@ -32,9 +31,6 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
|
|||
/** The FluidStack displayed on this pipe. */
|
||||
public FluidStack refFluid = null;
|
||||
|
||||
/** The fluid network currently in use by this pipe segment. */
|
||||
public FluidNetwork fluidNetwork;
|
||||
|
||||
/** This pipe's active state. */
|
||||
public boolean isActive = false;
|
||||
|
||||
|
@ -55,21 +51,10 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidNetwork getNetwork()
|
||||
{
|
||||
if(fluidNetwork == null)
|
||||
{
|
||||
fluidNetwork = new FluidNetwork(this);
|
||||
}
|
||||
|
||||
return fluidNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidNetwork getNetwork(boolean createIfNull)
|
||||
{
|
||||
if(fluidNetwork == null && createIfNull)
|
||||
if(theNetwork == null && createIfNull)
|
||||
{
|
||||
TileEntity[] adjacentPipes = PipeUtils.getConnectedPipes(this);
|
||||
HashSet<FluidNetwork> connectedNets = new HashSet<FluidNetwork>();
|
||||
|
@ -84,20 +69,20 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
|
|||
|
||||
if(connectedNets.size() == 0 || worldObj.isRemote)
|
||||
{
|
||||
fluidNetwork = new FluidNetwork(this);
|
||||
theNetwork = new FluidNetwork(this);
|
||||
}
|
||||
else if(connectedNets.size() == 1)
|
||||
{
|
||||
fluidNetwork = connectedNets.iterator().next();
|
||||
fluidNetwork.transmitters.add(this);
|
||||
theNetwork = connectedNets.iterator().next();
|
||||
theNetwork.transmitters.add(this);
|
||||
}
|
||||
else {
|
||||
fluidNetwork = new FluidNetwork(connectedNets);
|
||||
fluidNetwork.transmitters.add(this);
|
||||
theNetwork = new FluidNetwork(connectedNets);
|
||||
theNetwork.transmitters.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
return fluidNetwork;
|
||||
return theNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -117,22 +102,12 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
|
|||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(FluidNetwork network)
|
||||
{
|
||||
if(network != fluidNetwork)
|
||||
{
|
||||
removeFromNetwork();
|
||||
fluidNetwork = network;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromNetwork()
|
||||
{
|
||||
if(fluidNetwork != null)
|
||||
if(theNetwork != null)
|
||||
{
|
||||
fluidNetwork.removeTransmitter(this);
|
||||
theNetwork.removeTransmitter(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,13 +130,6 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
invalidate();
|
||||
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
|
|
|
@ -9,12 +9,9 @@ import mekanism.api.IPressurizedTube;
|
|||
import mekanism.api.ITubeConnection;
|
||||
import mekanism.api.Object3D;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileEntityPressurizedTube extends TileEntity implements IPressurizedTube, ITubeConnection
|
||||
public class TileEntityPressurizedTube extends TileEntityTransmitter<GasNetwork> implements IPressurizedTube, ITubeConnection
|
||||
{
|
||||
/** The gas currently displayed in this tube. */
|
||||
public EnumGas refGas = null;
|
||||
|
@ -22,19 +19,10 @@ public class TileEntityPressurizedTube extends TileEntity implements IPressurize
|
|||
/** The scale of the gas (0F -> 1F) currently inside this tube. */
|
||||
public float gasScale;
|
||||
|
||||
/** The gas network currently in use by this tube segment. */
|
||||
public GasNetwork gasNetwork;
|
||||
|
||||
@Override
|
||||
public GasNetwork getNetwork()
|
||||
{
|
||||
return getNetwork(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GasNetwork getNetwork(boolean createIfNull)
|
||||
{
|
||||
if(gasNetwork == null && createIfNull)
|
||||
if(theNetwork == null && createIfNull)
|
||||
{
|
||||
TileEntity[] adjacentTubes = GasTransmission.getConnectedTubes(this);
|
||||
HashSet<GasNetwork> connectedNets = new HashSet<GasNetwork>();
|
||||
|
@ -49,20 +37,20 @@ public class TileEntityPressurizedTube extends TileEntity implements IPressurize
|
|||
|
||||
if(connectedNets.size() == 0 || worldObj.isRemote)
|
||||
{
|
||||
gasNetwork = new GasNetwork(this);
|
||||
theNetwork = new GasNetwork(this);
|
||||
}
|
||||
else if(connectedNets.size() == 1)
|
||||
{
|
||||
gasNetwork = (GasNetwork)connectedNets.iterator().next();
|
||||
gasNetwork.transmitters.add(this);
|
||||
theNetwork = (GasNetwork)connectedNets.iterator().next();
|
||||
theNetwork.transmitters.add(this);
|
||||
}
|
||||
else {
|
||||
gasNetwork = new GasNetwork(connectedNets);
|
||||
gasNetwork.transmitters.add(this);
|
||||
theNetwork = new GasNetwork(connectedNets);
|
||||
theNetwork.transmitters.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
return gasNetwork;
|
||||
return theNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,22 +70,12 @@ public class TileEntityPressurizedTube extends TileEntity implements IPressurize
|
|||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(GasNetwork network)
|
||||
{
|
||||
if(network != gasNetwork)
|
||||
{
|
||||
removeFromNetwork();
|
||||
gasNetwork = network;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromNetwork()
|
||||
{
|
||||
if(gasNetwork != null)
|
||||
if(theNetwork != null)
|
||||
{
|
||||
gasNetwork.removeTransmitter(this);
|
||||
theNetwork.removeTransmitter(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,11 +141,4 @@ public class TileEntityPressurizedTube extends TileEntity implements IPressurize
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox()
|
||||
{
|
||||
return INFINITE_EXTENT_AABB;
|
||||
}
|
||||
}
|
||||
|
|
43
common/mekanism/common/TileEntityTransmitter.java
Normal file
43
common/mekanism/common/TileEntityTransmitter.java
Normal file
|
@ -0,0 +1,43 @@
|
|||
package mekanism.common;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import mekanism.api.ITransmitter;
|
||||
import mekanism.api.TransmitterNetworkRegistry;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
public abstract class TileEntityTransmitter<N> extends TileEntity implements ITransmitter<N>
|
||||
{
|
||||
public N theNetwork;
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox()
|
||||
{
|
||||
return INFINITE_EXTENT_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
invalidate();
|
||||
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(N network)
|
||||
{
|
||||
if(network != theNetwork)
|
||||
{
|
||||
removeFromNetwork();
|
||||
theNetwork = network;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public N getNetwork()
|
||||
{
|
||||
return getNetwork(true);
|
||||
}
|
||||
}
|
|
@ -18,14 +18,11 @@ import buildcraft.api.power.PowerHandler.PowerReceiver;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileEntityUniversalCable extends TileEntity implements IUniversalCable, IPowerReceptor
|
||||
public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwork> implements IUniversalCable, IPowerReceptor
|
||||
{
|
||||
/** A fake power handler used to initiate energy transfer calculations. */
|
||||
public PowerHandler powerHandler;
|
||||
|
||||
/** The energy network currently in use by this cable segment. */
|
||||
public EnergyNetwork energyNetwork;
|
||||
|
||||
public double energyScale;
|
||||
|
||||
public TileEntityUniversalCable()
|
||||
|
@ -40,19 +37,14 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnergyNetwork getNetwork()
|
||||
{
|
||||
return getNetwork(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnergyNetwork getNetwork(boolean createIfNull)
|
||||
{
|
||||
if(energyNetwork == null && createIfNull)
|
||||
if(theNetwork == null && createIfNull)
|
||||
{
|
||||
TileEntity[] adjacentCables = CableUtils.getConnectedCables(this);
|
||||
HashSet<EnergyNetwork> connectedNets = new HashSet<EnergyNetwork>();
|
||||
|
||||
for(TileEntity cable : adjacentCables)
|
||||
{
|
||||
if(cable instanceof IUniversalCable && ((IUniversalCable)cable).getNetwork(false) != null)
|
||||
|
@ -60,22 +52,23 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
|
|||
connectedNets.add(((IUniversalCable)cable).getNetwork());
|
||||
}
|
||||
}
|
||||
|
||||
if(connectedNets.size() == 0 || worldObj.isRemote)
|
||||
{
|
||||
energyNetwork = new EnergyNetwork(this);
|
||||
theNetwork = new EnergyNetwork(this);
|
||||
}
|
||||
else if(connectedNets.size() == 1)
|
||||
{
|
||||
energyNetwork = connectedNets.iterator().next();
|
||||
energyNetwork.transmitters.add(this);
|
||||
theNetwork = connectedNets.iterator().next();
|
||||
theNetwork.transmitters.add(this);
|
||||
}
|
||||
else {
|
||||
energyNetwork = new EnergyNetwork(connectedNets);
|
||||
energyNetwork.transmitters.add(this);
|
||||
theNetwork = new EnergyNetwork(connectedNets);
|
||||
theNetwork.transmitters.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
return energyNetwork;
|
||||
return theNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,22 +88,12 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
|
|||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(EnergyNetwork network)
|
||||
{
|
||||
if(network != energyNetwork)
|
||||
{
|
||||
removeFromNetwork();
|
||||
energyNetwork = network;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromNetwork()
|
||||
{
|
||||
if(energyNetwork != null)
|
||||
if(theNetwork != null)
|
||||
{
|
||||
energyNetwork.removeTransmitter(this);
|
||||
theNetwork.removeTransmitter(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,20 +131,6 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
|
|||
@Override
|
||||
public void doWork(PowerHandler workProvider) {}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox()
|
||||
{
|
||||
return INFINITE_EXTENT_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
invalidate();
|
||||
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCachedEnergy(double scale)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue