network changes

This commit is contained in:
DarkGuardsman 2013-07-06 00:48:12 -04:00
parent f231b67db3
commit 04318b350b
7 changed files with 72 additions and 74 deletions

View file

@ -25,6 +25,11 @@ public class NetworkFluidContainers extends NetworkFluidTiles
{ {
super(color, parts); super(color, parts);
} }
@Override
public NetworkTileEntities newInstance()
{
return new NetworkFluidContainers(this.color);
}
@Override @Override
// TODO change this to place liquids at the bottom first // TODO change this to place liquids at the bottom first
@ -153,7 +158,7 @@ public class NetworkFluidContainers extends NetworkFluidTiles
} }
@Override @Override
public void postMergeProcessing(NetworkTileEntities network) public void mergeDo(NetworkTileEntities network)
{ {
NetworkFluidContainers newNetwork = new NetworkFluidContainers(this.color); NetworkFluidContainers newNetwork = new NetworkFluidContainers(this.color);
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers()); newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());

View file

@ -1,6 +1,5 @@
package dark.core.network.fluid; package dark.core.network.fluid;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -20,6 +19,7 @@ import dark.core.hydraulic.helpers.FluidHelper;
import dark.core.tile.network.NetworkPathFinder; import dark.core.tile.network.NetworkPathFinder;
import dark.core.tile.network.NetworkTileEntities; import dark.core.tile.network.NetworkTileEntities;
import dark.fluid.api.INetworkFluidPart; import dark.fluid.api.INetworkFluidPart;
import dark.helpers.ConnectionHelper;
public class NetworkFluidTiles extends NetworkTileEntities public class NetworkFluidTiles extends NetworkTileEntities
{ {
@ -38,6 +38,12 @@ public class NetworkFluidTiles extends NetworkTileEntities
this.color = color; this.color = color;
} }
@Override
public NetworkTileEntities newInstance()
{
return new NetworkFluidTiles(this.color);
}
public LiquidTank combinedStorage() public LiquidTank combinedStorage()
{ {
if (this.sharedTank == null) if (this.sharedTank == null)
@ -48,9 +54,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
return this.sharedTank; return this.sharedTank;
} }
/** /** Stores Fluid in this network's collective tank */
* Stores Fluid in this network's collective tank
*/
public int storeFluidInSystem(LiquidStack stack, boolean doFill) public int storeFluidInSystem(LiquidStack stack, boolean doFill)
{ {
if (stack == null || this.combinedStorage().containsValidLiquid() && (this.combinedStorage().getLiquid() != null && !this.combinedStorage().getLiquid().isLiquidEqual(stack))) if (stack == null || this.combinedStorage().containsValidLiquid() && (this.combinedStorage().getLiquid() != null && !this.combinedStorage().getLiquid().isLiquidEqual(stack)))
@ -73,9 +77,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
return 0; return 0;
} }
/** /** Drains the network's collective tank */
* Drains the network's collective tank
*/
public LiquidStack drainFluidFromSystem(int maxDrain, boolean doDrain) public LiquidStack drainFluidFromSystem(int maxDrain, boolean doDrain)
{ {
if (!loadedLiquids) if (!loadedLiquids)
@ -99,12 +101,10 @@ public class NetworkFluidTiles extends NetworkTileEntities
return stack; return stack;
} }
/** /** Moves the volume stored in the network to the parts or sums up the volume from the parts and
* Moves the volume stored in the network to the parts or sums up the volume from the parts and
* loads it to the network. Assumes that all liquidStacks stored are equal * loads it to the network. Assumes that all liquidStacks stored are equal
* *
* @param sumParts - loads the volume from the parts before leveling out the volumes * @param sumParts - loads the volume from the parts before leveling out the volumes */
*/
public void balanceColletiveTank(boolean sumParts) public void balanceColletiveTank(boolean sumParts)
{ {
int volume = 0, itemID = 0, itemMeta = 0; int volume = 0, itemID = 0, itemMeta = 0;
@ -157,9 +157,9 @@ public class NetworkFluidTiles extends NetworkTileEntities
} }
@Override @Override
public boolean addEntity(TileEntity ent, boolean member) public boolean addTile(TileEntity ent, boolean member)
{ {
if (!(super.addEntity(ent, member)) && ent instanceof ITankContainer && !connectedTanks.contains(ent)) if (!(super.addTile(ent, member)) && ent instanceof ITankContainer && !connectedTanks.contains(ent))
{ {
connectedTanks.add((ITankContainer) ent); connectedTanks.add((ITankContainer) ent);
return true; return true;
@ -167,9 +167,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
return false; return false;
} }
/** /** Checks too see if the tileEntity is part of or connected too the network */
* Checks too see if the tileEntity is part of or connected too the network
*/
public boolean isConnected(TileEntity tileEntity) public boolean isConnected(TileEntity tileEntity)
{ {
return this.connectedTanks.contains(tileEntity); return this.connectedTanks.contains(tileEntity);
@ -192,11 +190,9 @@ public class NetworkFluidTiles extends NetworkTileEntities
{ {
this.getNetworkMemebers().remove(splitPoint); this.getNetworkMemebers().remove(splitPoint);
this.balanceColletiveTank(false); this.balanceColletiveTank(false);
/** /** Loop through the connected blocks and attempt to see if there are connections between
* Loop through the connected blocks and attempt to see if there are connections between * the two points elsewhere. */
* the two points elsewhere. TileEntity[] connectedBlocks = ConnectionHelper.getSurroundingTileEntities((TileEntity) splitPoint);
*/
TileEntity[] connectedBlocks = splitPoint.getNetworkConnections();
for (int i = 0; i < connectedBlocks.length; i++) for (int i = 0; i < connectedBlocks.length; i++)
{ {
@ -287,7 +283,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
} }
@Override @Override
public void postMergeProcessing(NetworkTileEntities network) public void mergeDo(NetworkTileEntities network)
{ {
NetworkFluidTiles newNetwork = new NetworkFluidTiles(this.color); NetworkFluidTiles newNetwork = new NetworkFluidTiles(this.color);
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers()); newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());

View file

@ -42,6 +42,12 @@ public class NetworkPipes extends NetworkFluidTiles
{ {
super(color, parts); super(color, parts);
} }
@Override
public NetworkTileEntities newInstance()
{
return new NetworkPipes(this.color);
}
public boolean isPartOfNetwork(TileEntity ent) public boolean isPartOfNetwork(TileEntity ent)
{ {
@ -367,7 +373,7 @@ public class NetworkPipes extends NetworkFluidTiles
} }
@Override @Override
public void postMergeProcessing(NetworkTileEntities network) public void mergeDo(NetworkTileEntities network)
{ {
NetworkPipes newNetwork = new NetworkPipes(this.color); NetworkPipes newNetwork = new NetworkPipes(this.color);
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers()); newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());

View file

@ -1,5 +1,8 @@
package dark.fluid.common.machines; package dark.fluid.common.machines;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetworkManager;
@ -39,7 +42,7 @@ import dark.fluid.common.prefab.TileEntityFluidDevice;
public class TileEntityTank extends TileEntityFluidDevice implements ITankContainer, IToolReadOut, IColorCoded, INetworkFluidPart, IPacketReceiver public class TileEntityTank extends TileEntityFluidDevice implements ITankContainer, IToolReadOut, IColorCoded, INetworkFluidPart, IPacketReceiver
{ {
/* CURRENTLY CONNECTED TILE ENTITIES TO THIS */ /* CURRENTLY CONNECTED TILE ENTITIES TO THIS */
private TileEntity[] connectedBlocks = new TileEntity[6]; private List<TileEntity> connectedBlocks = new ArrayList<TileEntity>();
public int[] renderConnection = new int[6]; public int[] renderConnection = new int[6];
private LiquidTank tank = new LiquidTank(this.getTankSize()); private LiquidTank tank = new LiquidTank(this.getTankSize());
@ -206,7 +209,7 @@ public class TileEntityTank extends TileEntityFluidDevice implements ITankContai
if (((TileEntityTank) tileEntity).getColor() == this.getColor()) if (((TileEntityTank) tileEntity).getColor() == this.getColor())
{ {
this.getTileNetwork().merge(((TileEntityTank) tileEntity).getTileNetwork(), this); this.getTileNetwork().merge(((TileEntityTank) tileEntity).getTileNetwork(), this);
connectedBlocks[side.ordinal()] = tileEntity; connectedBlocks.add(tileEntity);
} }
} }
if(tileEntity instanceof TileEntityComparator) if(tileEntity instanceof TileEntityComparator)
@ -224,7 +227,7 @@ public class TileEntityTank extends TileEntityFluidDevice implements ITankContai
if (this.worldObj != null && !this.worldObj.isRemote) if (this.worldObj != null && !this.worldObj.isRemote)
{ {
int[] previousConnections = this.renderConnection.clone(); int[] previousConnections = this.renderConnection.clone();
this.connectedBlocks = new TileEntity[6]; this.connectedBlocks.clear();
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
@ -272,7 +275,7 @@ public class TileEntityTank extends TileEntityFluidDevice implements ITankContai
} }
@Override @Override
public TileEntity[] getNetworkConnections() public List<TileEntity> getNetworkConnections()
{ {
return this.connectedBlocks; return this.connectedBlocks;
} }

View file

@ -1,6 +1,8 @@
package dark.fluid.common.pipes; package dark.fluid.common.pipes;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random; import java.util.Random;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -48,7 +50,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
/* TANK TO FAKE OTHER TILES INTO BELIVING THIS HAS AN INTERNAL STORAGE */ /* TANK TO FAKE OTHER TILES INTO BELIVING THIS HAS AN INTERNAL STORAGE */
protected LiquidTank fakeTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME); protected LiquidTank fakeTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME);
/* CURRENTLY CONNECTED TILE ENTITIES TO THIS */ /* CURRENTLY CONNECTED TILE ENTITIES TO THIS */
private TileEntity[] connectedBlocks = new TileEntity[6]; private List<TileEntity> connectedBlocks = new ArrayList<TileEntity>();
public boolean[] renderConnection = new boolean[6]; public boolean[] renderConnection = new boolean[6];
public IPipeExtention[] subEntities = new IPipeExtention[6]; public IPipeExtention[] subEntities = new IPipeExtention[6];
/* RANDOM INSTANCE USED BY THE UPDATE TICK */ /* RANDOM INSTANCE USED BY THE UPDATE TICK */
@ -60,7 +62,9 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
public enum PacketID public enum PacketID
{ {
PIPE_CONNECTIONS, EXTENTION_CREATE, EXTENTION_UPDATE; PIPE_CONNECTIONS,
EXTENTION_CREATE,
EXTENTION_UPDATE;
} }
@Override @Override
@ -112,9 +116,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
} }
} }
/** /** Builds and sends data to client for all PipeExtentions */
* Builds and sends data to client for all PipeExtentions
*/
private void updateSubEntities() private void updateSubEntities()
{ {
@ -195,9 +197,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
return PacketManager.getPacket(FluidMech.CHANNEL, this, PacketID.PIPE_CONNECTIONS.ordinal(), this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]); return PacketManager.getPacket(FluidMech.CHANNEL, this, PacketID.PIPE_CONNECTIONS.ordinal(), this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]);
} }
/** /** Reads a tile entity from NBT. */
* Reads a tile entity from NBT.
*/
@Override @Override
public void readFromNBT(NBTTagCompound nbt) public void readFromNBT(NBTTagCompound nbt)
{ {
@ -216,9 +216,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
} }
} }
/** /** Writes a tile entity to NBT. */
* Writes a tile entity to NBT.
*/
@Override @Override
public void writeToNBT(NBTTagCompound nbt) public void writeToNBT(NBTTagCompound nbt)
{ {
@ -298,9 +296,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
} }
} }
/** /** Sends the save data for the tileEntity too the client */
* Sends the save data for the tileEntity too the client
*/
public void sendExtentionToClient(int side) public void sendExtentionToClient(int side)
{ {
if (worldObj != null && !worldObj.isRemote && this.subEntities[side] instanceof TileEntity) if (worldObj != null && !worldObj.isRemote && this.subEntities[side] instanceof TileEntity)
@ -322,9 +318,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
} }
/** /** gets the current color mark of the pipe */
* gets the current color mark of the pipe
*/
@Override @Override
public ColorCode getColor() public ColorCode getColor()
{ {
@ -335,9 +329,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
return ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); return ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
} }
/** /** sets the current color mark of the pipe */
* sets the current color mark of the pipe
*/
@Override @Override
public void setColor(Object cc) public void setColor(Object cc)
{ {
@ -364,7 +356,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
{ {
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
string += ":" + (this.renderConnection[i] ? "T" : "F") + (this.getNetworkConnections()[i] != null ? "T" : "F"); string += ":" + (this.renderConnection[i] ? "T" : "F") + (this.renderConnection[i] ? "T" : "F");
} }
} }
if (testNetwork) if (testNetwork)
@ -440,20 +432,18 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
return null; return null;
} }
/** /** Checks to make sure the connection is valid to the tileEntity
* Checks to make sure the connection is valid to the tileEntity
* *
* @param tileEntity - the tileEntity being checked * @param tileEntity - the tileEntity being checked
* @param side - side the connection is too * @param side - side the connection is too
*/ * @return */
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side) public boolean validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{ {
if (!this.worldObj.isRemote && tileEntity != null) if (!this.worldObj.isRemote && tileEntity != null)
{ {
if (this.subEntities[side.ordinal()] != null) if (this.subEntities[side.ordinal()] != null)
{ {
connectedBlocks[side.ordinal()] = null; return false;
return;
} }
if (tileEntity instanceof ITileConnector) if (tileEntity instanceof ITileConnector)
{ {
@ -464,12 +454,13 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
if (((INetworkPipe) tileEntity).getColor() == this.getColor()) if (((INetworkPipe) tileEntity).getColor() == this.getColor())
{ {
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this); this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks[side.ordinal()] = tileEntity; return connectedBlocks.add(tileEntity);
} }
} }
else else
{ {
connectedBlocks[side.ordinal()] = tileEntity; return connectedBlocks.add(tileEntity);
} }
} }
} }
@ -477,14 +468,15 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
{ {
if (this.getColor() == ColorCode.NONE || this.getColor() == ((IColorCoded) tileEntity).getColor()) if (this.getColor() == ColorCode.NONE || this.getColor() == ((IColorCoded) tileEntity).getColor())
{ {
connectedBlocks[side.ordinal()] = tileEntity; return connectedBlocks.add(tileEntity);
} }
} }
else if (tileEntity instanceof ITankContainer) else if (tileEntity instanceof ITankContainer)
{ {
connectedBlocks[side.ordinal()] = tileEntity; return connectedBlocks.add(tileEntity);
} }
} }
return false;
} }
@Override @Override
@ -495,19 +487,17 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
{ {
boolean[] previousConnections = this.renderConnection.clone(); boolean[] previousConnections = this.renderConnection.clone();
this.connectedBlocks = new TileEntity[6]; this.connectedBlocks.clear();
for (int i = 0; i < 6; i++) for (ForgeDirection dir: ForgeDirection.VALID_DIRECTIONS)
{ {
ForgeDirection dir = ForgeDirection.getOrientation(i); TileEntity ent = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
this.validateConnectionSide(this.worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ), dir); this.renderConnection[dir.ordinal()] = this.validateConnectionSide(ent, dir);
this.renderConnection[i] = this.connectedBlocks[i] != null; if (this.renderConnection[dir.ordinal()] && ent instanceof ITankContainer && !(ent instanceof INetworkPipe))
if (this.renderConnection[i] && this.connectedBlocks[i] instanceof ITankContainer && !(this.connectedBlocks[i] instanceof INetworkPipe))
{ {
ITankContainer tankContainer = (ITankContainer) this.connectedBlocks[i]; ITankContainer tankContainer = (ITankContainer) ent;
this.getTileNetwork().addEntity(this.connectedBlocks[i], false); this.getTileNetwork().addTile(ent, false);
/* LITTLE TRICK TO AUTO DRAIN TANKS ON EACH CONNECTION UPDATE */ /* LITTLE TRICK TO AUTO DRAIN TANKS ON EACH CONNECTION UPDATE */
@ -520,9 +510,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
} }
} }
/** /** Only send packet updates if visuallyConnected changed. */
* Only send packet updates if visuallyConnected changed.
*/
if (!Arrays.areEqual(previousConnections, this.renderConnection)) if (!Arrays.areEqual(previousConnections, this.renderConnection))
{ {
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
@ -585,7 +573,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
} }
@Override @Override
public TileEntity[] getNetworkConnections() public List<TileEntity> getNetworkConnections()
{ {
return this.connectedBlocks; return this.connectedBlocks;
} }

View file

@ -93,7 +93,7 @@ public class TileEntityConstructionPump extends TileEntityRunnableMachine implem
} }
@Override @Override
public double getRequest() public double getRequest(ForgeDirection direction)
{ {
return WATTS_PER_TICK; return WATTS_PER_TICK;
} }

View file

@ -138,7 +138,7 @@ public class TileEntityStarterPump extends TileEntityRunnableMachine implements
} }
@Override @Override
public double getRequest() public double getRequest(ForgeDirection side)
{ {
return this.WATTS_PER_TICK; return this.WATTS_PER_TICK;
} }