Base transmitter TileEntity class

This commit is contained in:
Aidan Brady 2013-08-18 17:04:20 -04:00
parent f64ea42e43
commit 046cab7880
5 changed files with 86 additions and 167 deletions

View file

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import mekanism.api.Object3D; import mekanism.api.Object3D;
import mekanism.api.TransmitterNetworkRegistry;
import mekanism.common.PacketHandler.Transmission; import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketDataRequest; import mekanism.common.network.PacketDataRequest;
import net.minecraft.nbt.NBTTagCompound; 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.Side;
import cpw.mods.fml.relauncher.SideOnly; 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. */ /** This transporter's active state. */
public boolean isActive = false; public boolean isActive = false;
@Override
public InventoryNetwork getNetwork()
{
if(inventoryNetwork == null)
{
inventoryNetwork = new InventoryNetwork(this);
}
return inventoryNetwork;
}
@Override @Override
public InventoryNetwork getNetwork(boolean createIfNull) public InventoryNetwork getNetwork(boolean createIfNull)
{ {
if(inventoryNetwork == null && createIfNull) if(theNetwork == null && createIfNull)
{ {
TileEntity[] adjacentTransporters = CableUtils.getConnectedCables(this); TileEntity[] adjacentTransporters = CableUtils.getConnectedCables(this);
HashSet<InventoryNetwork> connectedNets = new HashSet<InventoryNetwork>(); HashSet<InventoryNetwork> connectedNets = new HashSet<InventoryNetwork>();
@ -53,20 +38,20 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ILogi
} }
if(connectedNets.size() == 0 || worldObj.isRemote) if(connectedNets.size() == 0 || worldObj.isRemote)
{ {
inventoryNetwork = new InventoryNetwork(this); theNetwork = new InventoryNetwork(this);
} }
else if(connectedNets.size() == 1) else if(connectedNets.size() == 1)
{ {
inventoryNetwork = connectedNets.iterator().next(); theNetwork = connectedNets.iterator().next();
inventoryNetwork.transmitters.add(this); theNetwork.transmitters.add(this);
} }
else { else {
inventoryNetwork = new InventoryNetwork(connectedNets); theNetwork = new InventoryNetwork(connectedNets);
inventoryNetwork.transmitters.add(this); theNetwork.transmitters.add(this);
} }
} }
return inventoryNetwork; return theNetwork;
} }
@Override @Override
@ -86,22 +71,12 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ILogi
super.invalidate(); super.invalidate();
} }
@Override
public void setNetwork(InventoryNetwork network)
{
if(network != inventoryNetwork)
{
removeFromNetwork();
inventoryNetwork = network;
}
}
@Override @Override
public void removeFromNetwork() 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 @Override
public boolean canUpdate() public boolean canUpdate()
{ {
return true; return false;
} }
@Override @Override

View file

@ -5,7 +5,6 @@ import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import mekanism.api.Object3D; import mekanism.api.Object3D;
import mekanism.api.TransmitterNetworkRegistry;
import mekanism.common.PacketHandler.Transmission; import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketDataRequest; import mekanism.common.network.PacketDataRequest;
import net.minecraft.nbt.NBTTagCompound; 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.Side;
import cpw.mods.fml.relauncher.SideOnly; 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. */ /** The fake tank used for fluid transfer calculations. */
public FluidTank dummyTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME); 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. */ /** The FluidStack displayed on this pipe. */
public FluidStack refFluid = null; public FluidStack refFluid = null;
/** The fluid network currently in use by this pipe segment. */
public FluidNetwork fluidNetwork;
/** This pipe's active state. */ /** This pipe's active state. */
public boolean isActive = false; 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 @Override
public FluidNetwork getNetwork(boolean createIfNull) public FluidNetwork getNetwork(boolean createIfNull)
{ {
if(fluidNetwork == null && createIfNull) if(theNetwork == null && createIfNull)
{ {
TileEntity[] adjacentPipes = PipeUtils.getConnectedPipes(this); TileEntity[] adjacentPipes = PipeUtils.getConnectedPipes(this);
HashSet<FluidNetwork> connectedNets = new HashSet<FluidNetwork>(); HashSet<FluidNetwork> connectedNets = new HashSet<FluidNetwork>();
@ -84,20 +69,20 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
if(connectedNets.size() == 0 || worldObj.isRemote) if(connectedNets.size() == 0 || worldObj.isRemote)
{ {
fluidNetwork = new FluidNetwork(this); theNetwork = new FluidNetwork(this);
} }
else if(connectedNets.size() == 1) else if(connectedNets.size() == 1)
{ {
fluidNetwork = connectedNets.iterator().next(); theNetwork = connectedNets.iterator().next();
fluidNetwork.transmitters.add(this); theNetwork.transmitters.add(this);
} }
else { else {
fluidNetwork = new FluidNetwork(connectedNets); theNetwork = new FluidNetwork(connectedNets);
fluidNetwork.transmitters.add(this); theNetwork.transmitters.add(this);
} }
} }
return fluidNetwork; return theNetwork;
} }
@Override @Override
@ -117,22 +102,12 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
super.invalidate(); super.invalidate();
} }
@Override
public void setNetwork(FluidNetwork network)
{
if(network != fluidNetwork)
{
removeFromNetwork();
fluidNetwork = network;
}
}
@Override @Override
public void removeFromNetwork() 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 @Override
public void updateEntity() public void updateEntity()
{ {

View file

@ -9,12 +9,9 @@ import mekanism.api.IPressurizedTube;
import mekanism.api.ITubeConnection; import mekanism.api.ITubeConnection;
import mekanism.api.Object3D; import mekanism.api.Object3D;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection; 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. */ /** The gas currently displayed in this tube. */
public EnumGas refGas = null; 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. */ /** The scale of the gas (0F -> 1F) currently inside this tube. */
public float gasScale; public float gasScale;
/** The gas network currently in use by this tube segment. */
public GasNetwork gasNetwork;
@Override
public GasNetwork getNetwork()
{
return getNetwork(true);
}
@Override @Override
public GasNetwork getNetwork(boolean createIfNull) public GasNetwork getNetwork(boolean createIfNull)
{ {
if(gasNetwork == null && createIfNull) if(theNetwork == null && createIfNull)
{ {
TileEntity[] adjacentTubes = GasTransmission.getConnectedTubes(this); TileEntity[] adjacentTubes = GasTransmission.getConnectedTubes(this);
HashSet<GasNetwork> connectedNets = new HashSet<GasNetwork>(); HashSet<GasNetwork> connectedNets = new HashSet<GasNetwork>();
@ -49,20 +37,20 @@ public class TileEntityPressurizedTube extends TileEntity implements IPressurize
if(connectedNets.size() == 0 || worldObj.isRemote) if(connectedNets.size() == 0 || worldObj.isRemote)
{ {
gasNetwork = new GasNetwork(this); theNetwork = new GasNetwork(this);
} }
else if(connectedNets.size() == 1) else if(connectedNets.size() == 1)
{ {
gasNetwork = (GasNetwork)connectedNets.iterator().next(); theNetwork = (GasNetwork)connectedNets.iterator().next();
gasNetwork.transmitters.add(this); theNetwork.transmitters.add(this);
} }
else { else {
gasNetwork = new GasNetwork(connectedNets); theNetwork = new GasNetwork(connectedNets);
gasNetwork.transmitters.add(this); theNetwork.transmitters.add(this);
} }
} }
return gasNetwork; return theNetwork;
} }
@Override @Override
@ -82,22 +70,12 @@ public class TileEntityPressurizedTube extends TileEntity implements IPressurize
super.invalidate(); super.invalidate();
} }
@Override
public void setNetwork(GasNetwork network)
{
if(network != gasNetwork)
{
removeFromNetwork();
gasNetwork = network;
}
}
@Override @Override
public void removeFromNetwork() 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; return false;
} }
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return INFINITE_EXTENT_AABB;
}
} }

View 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);
}
}

View file

@ -18,14 +18,11 @@ import buildcraft.api.power.PowerHandler.PowerReceiver;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; 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. */ /** A fake power handler used to initiate energy transfer calculations. */
public PowerHandler powerHandler; public PowerHandler powerHandler;
/** The energy network currently in use by this cable segment. */
public EnergyNetwork energyNetwork;
public double energyScale; public double energyScale;
public TileEntityUniversalCable() public TileEntityUniversalCable()
@ -40,19 +37,14 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
return false; return false;
} }
@Override
public EnergyNetwork getNetwork()
{
return getNetwork(true);
}
@Override @Override
public EnergyNetwork getNetwork(boolean createIfNull) public EnergyNetwork getNetwork(boolean createIfNull)
{ {
if(energyNetwork == null && createIfNull) if(theNetwork == null && createIfNull)
{ {
TileEntity[] adjacentCables = CableUtils.getConnectedCables(this); TileEntity[] adjacentCables = CableUtils.getConnectedCables(this);
HashSet<EnergyNetwork> connectedNets = new HashSet<EnergyNetwork>(); HashSet<EnergyNetwork> connectedNets = new HashSet<EnergyNetwork>();
for(TileEntity cable : adjacentCables) for(TileEntity cable : adjacentCables)
{ {
if(cable instanceof IUniversalCable && ((IUniversalCable)cable).getNetwork(false) != null) 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()); connectedNets.add(((IUniversalCable)cable).getNetwork());
} }
} }
if(connectedNets.size() == 0 || worldObj.isRemote) if(connectedNets.size() == 0 || worldObj.isRemote)
{ {
energyNetwork = new EnergyNetwork(this); theNetwork = new EnergyNetwork(this);
} }
else if(connectedNets.size() == 1) else if(connectedNets.size() == 1)
{ {
energyNetwork = connectedNets.iterator().next(); theNetwork = connectedNets.iterator().next();
energyNetwork.transmitters.add(this); theNetwork.transmitters.add(this);
} }
else { else {
energyNetwork = new EnergyNetwork(connectedNets); theNetwork = new EnergyNetwork(connectedNets);
energyNetwork.transmitters.add(this); theNetwork.transmitters.add(this);
} }
} }
return energyNetwork; return theNetwork;
} }
@Override @Override
@ -95,22 +88,12 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
super.invalidate(); super.invalidate();
} }
@Override
public void setNetwork(EnergyNetwork network)
{
if(network != energyNetwork)
{
removeFromNetwork();
energyNetwork = network;
}
}
@Override @Override
public void removeFromNetwork() 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 @Override
public void doWork(PowerHandler workProvider) {} 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 @Override
public void setCachedEnergy(double scale) public void setCachedEnergy(double scale)
{ {