network changes
This commit is contained in:
parent
f231b67db3
commit
04318b350b
7 changed files with 72 additions and 74 deletions
|
@ -25,6 +25,11 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
|||
{
|
||||
super(color, parts);
|
||||
}
|
||||
@Override
|
||||
public NetworkTileEntities newInstance()
|
||||
{
|
||||
return new NetworkFluidContainers(this.color);
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO change this to place liquids at the bottom first
|
||||
|
@ -153,7 +158,7 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
|||
}
|
||||
|
||||
@Override
|
||||
public void postMergeProcessing(NetworkTileEntities network)
|
||||
public void mergeDo(NetworkTileEntities network)
|
||||
{
|
||||
NetworkFluidContainers newNetwork = new NetworkFluidContainers(this.color);
|
||||
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package dark.core.network.fluid;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
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.NetworkTileEntities;
|
||||
import dark.fluid.api.INetworkFluidPart;
|
||||
import dark.helpers.ConnectionHelper;
|
||||
|
||||
public class NetworkFluidTiles extends NetworkTileEntities
|
||||
{
|
||||
|
@ -38,6 +38,12 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkTileEntities newInstance()
|
||||
{
|
||||
return new NetworkFluidTiles(this.color);
|
||||
}
|
||||
|
||||
public LiquidTank combinedStorage()
|
||||
{
|
||||
if (this.sharedTank == null)
|
||||
|
@ -48,9 +54,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drains the network's collective tank
|
||||
*/
|
||||
/** Drains the network's collective tank */
|
||||
public LiquidStack drainFluidFromSystem(int maxDrain, boolean doDrain)
|
||||
{
|
||||
if (!loadedLiquids)
|
||||
|
@ -99,12 +101,10 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
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
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
int volume = 0, itemID = 0, itemMeta = 0;
|
||||
|
@ -157,9 +157,9 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
}
|
||||
|
||||
@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);
|
||||
return true;
|
||||
|
@ -167,9 +167,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
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)
|
||||
{
|
||||
return this.connectedTanks.contains(tileEntity);
|
||||
|
@ -192,11 +190,9 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
{
|
||||
this.getNetworkMemebers().remove(splitPoint);
|
||||
this.balanceColletiveTank(false);
|
||||
/**
|
||||
* Loop through the connected blocks and attempt to see if there are connections between
|
||||
* the two points elsewhere.
|
||||
*/
|
||||
TileEntity[] connectedBlocks = splitPoint.getNetworkConnections();
|
||||
/** Loop through the connected blocks and attempt to see if there are connections between
|
||||
* the two points elsewhere. */
|
||||
TileEntity[] connectedBlocks = ConnectionHelper.getSurroundingTileEntities((TileEntity) splitPoint);
|
||||
|
||||
for (int i = 0; i < connectedBlocks.length; i++)
|
||||
{
|
||||
|
@ -287,7 +283,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
}
|
||||
|
||||
@Override
|
||||
public void postMergeProcessing(NetworkTileEntities network)
|
||||
public void mergeDo(NetworkTileEntities network)
|
||||
{
|
||||
NetworkFluidTiles newNetwork = new NetworkFluidTiles(this.color);
|
||||
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());
|
||||
|
|
|
@ -42,6 +42,12 @@ public class NetworkPipes extends NetworkFluidTiles
|
|||
{
|
||||
super(color, parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkTileEntities newInstance()
|
||||
{
|
||||
return new NetworkPipes(this.color);
|
||||
}
|
||||
|
||||
public boolean isPartOfNetwork(TileEntity ent)
|
||||
{
|
||||
|
@ -367,7 +373,7 @@ public class NetworkPipes extends NetworkFluidTiles
|
|||
}
|
||||
|
||||
@Override
|
||||
public void postMergeProcessing(NetworkTileEntities network)
|
||||
public void mergeDo(NetworkTileEntities network)
|
||||
{
|
||||
NetworkPipes newNetwork = new NetworkPipes(this.color);
|
||||
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package dark.fluid.common.machines;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
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
|
||||
{
|
||||
/* 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];
|
||||
|
||||
private LiquidTank tank = new LiquidTank(this.getTankSize());
|
||||
|
@ -206,7 +209,7 @@ public class TileEntityTank extends TileEntityFluidDevice implements ITankContai
|
|||
if (((TileEntityTank) tileEntity).getColor() == this.getColor())
|
||||
{
|
||||
this.getTileNetwork().merge(((TileEntityTank) tileEntity).getTileNetwork(), this);
|
||||
connectedBlocks[side.ordinal()] = tileEntity;
|
||||
connectedBlocks.add(tileEntity);
|
||||
}
|
||||
}
|
||||
if(tileEntity instanceof TileEntityComparator)
|
||||
|
@ -224,7 +227,7 @@ public class TileEntityTank extends TileEntityFluidDevice implements ITankContai
|
|||
if (this.worldObj != null && !this.worldObj.isRemote)
|
||||
{
|
||||
int[] previousConnections = this.renderConnection.clone();
|
||||
this.connectedBlocks = new TileEntity[6];
|
||||
this.connectedBlocks.clear();
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
|
@ -272,7 +275,7 @@ public class TileEntityTank extends TileEntityFluidDevice implements ITankContai
|
|||
}
|
||||
|
||||
@Override
|
||||
public TileEntity[] getNetworkConnections()
|
||||
public List<TileEntity> getNetworkConnections()
|
||||
{
|
||||
return this.connectedBlocks;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package dark.fluid.common.pipes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
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 */
|
||||
protected LiquidTank fakeTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME);
|
||||
/* 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 IPipeExtention[] subEntities = new IPipeExtention[6];
|
||||
/* RANDOM INSTANCE USED BY THE UPDATE TICK */
|
||||
|
@ -60,7 +62,9 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
|
||||
public enum PacketID
|
||||
{
|
||||
PIPE_CONNECTIONS, EXTENTION_CREATE, EXTENTION_UPDATE;
|
||||
PIPE_CONNECTIONS,
|
||||
EXTENTION_CREATE,
|
||||
EXTENTION_UPDATE;
|
||||
}
|
||||
|
||||
@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()
|
||||
{
|
||||
|
||||
|
@ -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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a tile entity from NBT.
|
||||
*/
|
||||
/** Reads a tile entity from NBT. */
|
||||
@Override
|
||||
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
|
||||
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)
|
||||
{
|
||||
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
|
||||
public ColorCode getColor()
|
||||
{
|
||||
|
@ -335,9 +329,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
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
|
||||
public void setColor(Object cc)
|
||||
{
|
||||
|
@ -364,7 +356,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
{
|
||||
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)
|
||||
|
@ -440,20 +432,18 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
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 side - side the connection is too
|
||||
*/
|
||||
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
|
||||
* @return */
|
||||
public boolean validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
|
||||
{
|
||||
if (!this.worldObj.isRemote && tileEntity != null)
|
||||
{
|
||||
if (this.subEntities[side.ordinal()] != null)
|
||||
{
|
||||
connectedBlocks[side.ordinal()] = null;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (tileEntity instanceof ITileConnector)
|
||||
{
|
||||
|
@ -464,12 +454,13 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
if (((INetworkPipe) tileEntity).getColor() == this.getColor())
|
||||
{
|
||||
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
|
||||
connectedBlocks[side.ordinal()] = tileEntity;
|
||||
return connectedBlocks.add(tileEntity);
|
||||
|
||||
}
|
||||
}
|
||||
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())
|
||||
{
|
||||
connectedBlocks[side.ordinal()] = tileEntity;
|
||||
return connectedBlocks.add(tileEntity);
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof ITankContainer)
|
||||
{
|
||||
connectedBlocks[side.ordinal()] = tileEntity;
|
||||
return connectedBlocks.add(tileEntity);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -495,19 +487,17 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
{
|
||||
|
||||
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);
|
||||
this.validateConnectionSide(this.worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ), dir);
|
||||
TileEntity ent = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
||||
this.renderConnection[dir.ordinal()] = this.validateConnectionSide(ent, dir);
|
||||
|
||||
this.renderConnection[i] = this.connectedBlocks[i] != null;
|
||||
|
||||
if (this.renderConnection[i] && this.connectedBlocks[i] instanceof ITankContainer && !(this.connectedBlocks[i] instanceof INetworkPipe))
|
||||
if (this.renderConnection[dir.ordinal()] && ent instanceof ITankContainer && !(ent instanceof INetworkPipe))
|
||||
{
|
||||
ITankContainer tankContainer = (ITankContainer) this.connectedBlocks[i];
|
||||
this.getTileNetwork().addEntity(this.connectedBlocks[i], false);
|
||||
ITankContainer tankContainer = (ITankContainer) ent;
|
||||
this.getTileNetwork().addTile(ent, false);
|
||||
|
||||
/* 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))
|
||||
{
|
||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||
|
@ -585,7 +573,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
public TileEntity[] getNetworkConnections()
|
||||
public List<TileEntity> getNetworkConnections()
|
||||
{
|
||||
return this.connectedBlocks;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public class TileEntityConstructionPump extends TileEntityRunnableMachine implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getRequest()
|
||||
public double getRequest(ForgeDirection direction)
|
||||
{
|
||||
return WATTS_PER_TICK;
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ public class TileEntityStarterPump extends TileEntityRunnableMachine implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getRequest()
|
||||
public double getRequest(ForgeDirection side)
|
||||
{
|
||||
return this.WATTS_PER_TICK;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue