Tile Network changes

This commit is contained in:
DarkGuardsman 2013-11-08 03:05:18 -05:00
parent 7fa0a418f4
commit 951b309c7d
10 changed files with 85 additions and 142 deletions

View file

@ -1,33 +0,0 @@
package dark.core.prefab.tilenetwork.fluid;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import dark.api.parts.INetworkPart;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
public class FluidNetworkHelper
{
/** Invalidates a TileEntity that is part of a fluid network */
public static void invalidate(TileEntity tileEntity)
{
for (int i = 0; i < 6; i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
TileEntity checkTile = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction);
if (checkTile instanceof INetworkPart)
{
NetworkTileEntities network = ((INetworkPart) checkTile).getTileNetwork();
if (network != null && network instanceof NetworkFluidTiles)
{
network.removeTile(tileEntity);
}
}
}
}
}

View file

@ -9,15 +9,20 @@ import net.minecraftforge.fluids.IFluidHandler;
import dark.api.fluid.INetworkFluidPart;
import dark.api.parts.INetworkPart;
import dark.core.prefab.helpers.FluidHelper;
import dark.core.prefab.tilenetwork.NetworkHandler;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
/** Side note: the network should act like this when done {@link http
* ://www.e4training.com/hydraulic_calculators/B1.htm} as well as stay compatible with the forge
* Liquids
/** Basically the same as network Fluid tiles class with the only difference being in how it stores
* the fluid. When it goes to sort the fluid it will use the fluid properties to adjust its position
* in the over all tank. Eg water goes down air goes up.
*
* @author Rseifert */
* @author DarkGuardsman */
public class NetworkFluidContainers extends NetworkFluidTiles
{
static
{
NetworkHandler.registerNetworkClass("FluidContainers", NetworkFluidContainers.class);
}
public NetworkFluidContainers(INetworkPart... parts)
{
@ -25,28 +30,22 @@ public class NetworkFluidContainers extends NetworkFluidTiles
}
@Override
public NetworkTileEntities newInstance()
{
return new NetworkFluidContainers();
}
@Override
public void writeDataToTiles()
public void save()
{
this.cleanUpMembers();
if (this.getNetworkTank() == null || this.getNetworkTank().getFluid() == null)
{
super.writeDataToTiles();
super.save();
return;
}
FluidStack fillStack = this.getNetworkTank().getFluid().copy();
int lowestY = 255, highestY = 0;
if (this.getNetworkTank().getFluid() != null && this.getNetworkMemebers().size() > 0)
if (this.getNetworkTank().getFluid() != null && this.getMembers().size() > 0)
{
for (INetworkPart part : this.getNetworkMemebers())
for (INetworkPart part : this.getMembers())
{
if (part instanceof IFluidHandler)
{
@ -69,7 +68,7 @@ public class NetworkFluidContainers extends NetworkFluidTiles
List<INetworkFluidPart> parts = new ArrayList<INetworkFluidPart>();
/* Grab all parts that share this Y level*/
for (INetworkPart part : this.getNetworkMemebers())
for (INetworkPart part : this.getMembers())
{
if (part instanceof INetworkFluidPart && ((TileEntity) part).yCoord == y)
{

View file

@ -13,7 +13,9 @@ import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import dark.api.fluid.INetworkFluidPart;
import dark.api.parts.INetworkPart;
import dark.api.parts.ITileNetwork;
import dark.core.prefab.helpers.FluidHelper;
import dark.core.prefab.tilenetwork.NetworkHandler;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
public class NetworkFluidTiles extends NetworkTileEntities
@ -27,17 +29,16 @@ public class NetworkFluidTiles extends NetworkTileEntities
/** Has the collective tank been loaded yet */
protected boolean loadedLiquids = false;
static
{
NetworkHandler.registerNetworkClass("FluidTiles", NetworkFluidTiles.class);
}
public NetworkFluidTiles(INetworkPart... parts)
{
super(parts);
}
@Override
public NetworkTileEntities newInstance()
{
return new NetworkFluidTiles();
}
/** Gets the collective tank of the network */
public FluidTank getNetworkTank()
{
@ -62,7 +63,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
{
if (!this.loadedLiquids)
{
this.readDataFromTiles();
this.load();
this.loadedLiquids = true;
}
if (!world.isRemote && this.getNetworkTank() != null && stack != null)
@ -75,7 +76,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
if (p != this.getNetworkTank().getFluidAmount())
{
this.sharedTankInfo = this.getNetworkTank().getInfo();
this.writeDataToTiles();
this.save();
}
}
return r;
@ -88,7 +89,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
if (!this.loadedLiquids)
{
this.readDataFromTiles();
this.load();
this.loadedLiquids = true;
}
FluidStack before = this.getNetworkTank().getFluid();
@ -103,7 +104,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
if (!before.isFluidEqual(after) || (before != null && after != null && before.amount != after.amount))
{
this.sharedTankInfo = this.getNetworkTank().getInfo();
this.writeDataToTiles();
this.save();
/*TODO do a client update from the network rather than each pipe updating itself.
*This will save on packet size but will increase the CPU load of the client since the client
*will need to do network calculations */
@ -115,18 +116,18 @@ public class NetworkFluidTiles extends NetworkTileEntities
}
@Override
public void writeDataToTiles()
public void save()
{
this.cleanUpMembers();
if (this.getNetworkTank().getFluid() != null && this.networkMember.size() > 0)
if (this.getNetworkTank().getFluid() != null && this.getMembers().size() > 0)
{
FluidStack stack = this.getNetworkTank().getFluid() == null ? null : this.getNetworkTank().getFluid().copy();
int membersFilled = 0;
for (INetworkPart par : this.networkMember)
for (INetworkPart par : this.getMembers())
{
//UPDATE FILL VOLUME
int fillVol = stack == null ? 0 : (stack.amount / (this.networkMember.size() - membersFilled));
int fillVol = stack == null ? 0 : (stack.amount / (this.getMembers().size() - membersFilled));
if (par instanceof INetworkFluidPart)
{
@ -145,11 +146,11 @@ public class NetworkFluidTiles extends NetworkTileEntities
}
@Override
public void readDataFromTiles()
public void load()
{
FluidStack stack = null;
this.cleanUpMembers();
for (INetworkPart par : this.networkMember)
for (INetworkPart par : this.getMembers())
{
if (par instanceof INetworkFluidPart)
{
@ -201,53 +202,47 @@ public class NetworkFluidTiles extends NetworkTileEntities
}
@Override
public void init()
public boolean preMergeProcessing(ITileNetwork mergingNetwork, INetworkPart mergePoint)
{
super.init();
this.readDataFromTiles();
}
@Override
public boolean preMergeProcessing(NetworkTileEntities mergingNetwork, INetworkPart mergePoint)
{
if (mergingNetwork instanceof NetworkFluidTiles && ((NetworkFluidTiles) mergingNetwork).getClass() == this.getClass())
if (mergingNetwork instanceof NetworkFluidTiles)
{
if (!((NetworkFluidTiles) mergingNetwork).loadedLiquids)
{
((NetworkFluidTiles) mergingNetwork).readDataFromTiles();
((NetworkFluidTiles) mergingNetwork).load();
}
if (!this.loadedLiquids)
{
this.readDataFromTiles();
this.load();
}
return true;
}
return false;
return super.preMergeProcessing(mergingNetwork, mergePoint);
}
@Override
protected void mergeDo(NetworkTileEntities network)
protected void mergeDo(ITileNetwork network)
{
ITileNetwork newNetwork = NetworkHandler.createNewNetwork(NetworkHandler.getID(this.getClass()));
if (newNetwork instanceof NetworkFluidTiles)
{
NetworkFluidTiles newNetwork = (NetworkFluidTiles) this.newInstance();
FluidStack one = this.getNetworkTank().getFluid();
FluidStack two = ((NetworkFluidTiles) network).getNetworkTank().getFluid();
this.getNetworkTank().setFluid(null);
((NetworkFluidTiles) network).getNetworkTank().setFluid(null);
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());
newNetwork.getNetworkMemebers().addAll(network.getNetworkMemebers());
newNetwork.cleanUpMembers();
newNetwork.getNetworkTank().setFluid(FluidCraftingHandler.mergeFluidStacks(one, two));
newNetwork.sharedTankInfo = newNetwork.getNetworkTank().getInfo();
newNetwork.writeDataToTiles();
((NetworkFluidTiles) newNetwork).getNetworkTank().setFluid(FluidCraftingHandler.mergeFluidStacks(one, two));
((NetworkFluidTiles) newNetwork).sharedTankInfo = ((NetworkFluidTiles) newNetwork).getNetworkTank().getInfo();
}
newNetwork.getMembers().addAll(this.getMembers());
newNetwork.getMembers().addAll(network.getMembers());
newNetwork.onCreated();
}
@Override
public void cleanUpMembers()
{
Iterator<INetworkPart> it = this.networkMember.iterator();
Iterator<INetworkPart> it = this.getMembers().iterator();
int capacity = 0;
while (it.hasNext())
{
@ -278,7 +273,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
@Override
public String toString()
{
return "FluidNetwork[" + this.hashCode() + "|parts:" + this.networkMember.size() + "]";
return "FluidNetwork[" + this.hashCode() + "|parts:" + this.getMembers().size() + "]";
}
public String getNetworkFluid()

View file

@ -9,11 +9,12 @@ import dark.api.fluid.INetworkPipe;
import dark.api.parts.INetworkPart;
import dark.core.prefab.helpers.ConnectionHelper;
import dark.core.prefab.helpers.FluidHelper;
import dark.core.prefab.tilenetwork.NetworkHandler;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
/** Side note: the network should act like this when done {@link http
* ://www.e4training.com/hydraulic_calculators/B1.htm} as well as stay compatible with the forge
* Liquids
/** Extension on the fluid container network to provide a more advanced reaction to fluid passing
* threw each pipe. As well this doubled as a pressure network for those machines that support the
* use of pressure.
*
* @author Rseifert */
public class NetworkPipes extends NetworkFluidTiles
@ -21,23 +22,16 @@ public class NetworkPipes extends NetworkFluidTiles
private boolean processingRequest;
public float pressureProduced;
static
{
NetworkHandler.registerNetworkClass("FluidPipes", NetworkPipes.class);
}
public NetworkPipes(INetworkPart... parts)
{
super(parts);
}
@Override
public NetworkTileEntities newInstance()
{
return new NetworkPipes();
}
@Override
public boolean removeTile(TileEntity ent)
{
return super.removeTile(ent);
}
/** Adds FLuid to this network from one of the connected Pipes
*
* @param source - Were this liquid came from
@ -177,10 +171,6 @@ public class NetworkPipes extends NetworkFluidTiles
// this.combinedStorage.getLiquid().amount : 0));
}
if (prevCombined != null && this.getNetworkTank().getFluid() != null && prevCombined.amount != this.getNetworkTank().getFluid().amount)
{
this.writeDataToTiles();
}
}
this.processingRequest = false;
return used;

View file

@ -1,6 +1,6 @@
package dark.fluid.common.machines;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
import dark.api.parts.ITileNetwork;
import dark.core.prefab.tilenetwork.fluid.NetworkFluidContainers;
import dark.fluid.common.prefab.TileEntityFluidNetworkTile;
@ -22,7 +22,7 @@ public class TileEntityTank extends TileEntityFluidNetworkTile
}
@Override
public void setTileNetwork(NetworkTileEntities network)
public void setTileNetwork(ITileNetwork network)
{
if (network instanceof NetworkFluidContainers)
{

View file

@ -9,7 +9,7 @@ import universalelectricity.core.vector.Vector3;
import dark.api.ColorCode;
import dark.api.ColorCode.IColorCoded;
import dark.api.fluid.INetworkPipe;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
import dark.api.parts.ITileNetwork;
import dark.core.prefab.tilenetwork.fluid.NetworkPipes;
import dark.fluid.common.FluidPartsMaterial;
import dark.fluid.common.prefab.TileEntityFluidNetworkTile;
@ -52,19 +52,19 @@ public class TileEntityPipe extends TileEntityFluidNetworkTile implements IColor
//Same pipe types can connect
if (pipeMat == pipeMatOther)
{
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
this.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
this.renderConnection[side.ordinal()] = true;
}//Wood and stone pipes can connect to each other but not other pipe types since they are more like a trough than a pipe
else if ((pipeMat == FluidPartsMaterial.WOOD || pipeMat == FluidPartsMaterial.STONE) && (pipeMatOther == FluidPartsMaterial.WOOD || pipeMatOther == FluidPartsMaterial.STONE))
{
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
this.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
this.renderConnection[side.ordinal()] = true;
}//Any other pipe can connect to each other as long as the color matches except for glass which only works with itself at the moment
else if (pipeMat != FluidPartsMaterial.WOOD && pipeMat != FluidPartsMaterial.STONE && pipeMatOther != FluidPartsMaterial.WOOD && pipeMatOther != FluidPartsMaterial.STONE && pipeMat != FluidPartsMaterial.GLASS && pipeMatOther != FluidPartsMaterial.GLASS)
{
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
this.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
this.renderConnection[side.ordinal()] = true;
}
@ -107,7 +107,7 @@ public class TileEntityPipe extends TileEntityFluidNetworkTile implements IColor
}
@Override
public void setTileNetwork(NetworkTileEntities network)
public void setTileNetwork(ITileNetwork network)
{
if (network instanceof NetworkPipes)
{

View file

@ -7,7 +7,7 @@ import net.minecraftforge.common.ForgeDirection;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import dark.api.IToolReadOut;
import dark.api.parts.ITileConnector;
import dark.core.prefab.tilenetwork.fluid.FluidNetworkHelper;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
public abstract class TileEntityFluidDevice extends TileEntityAdvanced implements IToolReadOut, ITileConnector
{
@ -17,7 +17,7 @@ public abstract class TileEntityFluidDevice extends TileEntityAdvanced implement
public void invalidate()
{
super.invalidate();
FluidNetworkHelper.invalidate(this);
NetworkTileEntities.invalidate(this);
}
@Override

View file

@ -30,10 +30,10 @@ import cpw.mods.fml.relauncher.SideOnly;
import dark.api.fluid.FluidMasterList;
import dark.api.fluid.INetworkFluidPart;
import dark.api.parts.INetworkPart;
import dark.api.parts.ITileNetwork;
import dark.core.common.DarkMain;
import dark.core.network.ISimplePacketReceiver;
import dark.core.network.PacketHandler;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
import dark.core.prefab.tilenetwork.fluid.NetworkFluidTiles;
import dark.fluid.common.FluidPartsMaterial;
@ -108,7 +108,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
@Override
public void invalidate()
{
this.getTileNetwork().splitNetwork(this.worldObj, this);
this.getTileNetwork().splitNetwork(this);
super.invalidate();
}
@ -205,7 +205,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
{
if (this.canTileConnect(Connection.NETWORK, side.getOpposite()))
{
this.getTileNetwork().merge(((INetworkFluidPart) tileEntity).getTileNetwork(), (INetworkPart) tileEntity);
this.getTileNetwork().mergeNetwork(((INetworkFluidPart) tileEntity).getTileNetwork(), (INetworkPart) tileEntity);
this.renderConnection[side.ordinal()] = true;
connectedBlocks.add(tileEntity);
}
@ -224,7 +224,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
}
@Override
public void setTileNetwork(NetworkTileEntities fluidNetwork)
public void setTileNetwork(ITileNetwork fluidNetwork)
{
if (fluidNetwork instanceof NetworkFluidTiles)
{
@ -233,12 +233,6 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
}
@Override
public boolean mergeDamage(String result)
{
return false;
}
@Override
public FluidTankInfo[] getTankInfo()
{

View file

@ -21,7 +21,7 @@ import com.builtbroken.common.Pair;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.prefab.tilenetwork.fluid.FluidNetworkHelper;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
import dark.fluid.client.render.BlockRenderHelper;
import dark.fluid.common.FMRecipeLoader;
import dark.fluid.common.FluidMech;
@ -130,7 +130,7 @@ public class BlockConstructionPump extends BlockFM
TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TileEntityConstructionPump)
{
FluidNetworkHelper.invalidate(entity);
NetworkTileEntities.invalidate(entity);
}
if (meta == 3)

View file

@ -21,7 +21,6 @@ import com.builtbroken.common.Pair;
import dark.api.fluid.IDrain;
import dark.api.fluid.INetworkPipe;
import dark.api.parts.ITileConnector;
import dark.core.prefab.tilenetwork.fluid.FluidNetworkHelper;
import dark.core.prefab.tilenetwork.fluid.NetworkFluidTiles;
public class TileEntityConstructionPump extends TileEntityStarterPump implements IFluidHandler, ITileConnector
@ -162,7 +161,6 @@ public class TileEntityConstructionPump extends TileEntityStarterPump implements
public void invalidate()
{
super.invalidate();
FluidNetworkHelper.invalidate(this);
}
@Override