Revived gutters

This commit is contained in:
Calclavia 2014-03-01 20:26:18 +08:00
parent fee28407d8
commit c6ac81c6a6
13 changed files with 226 additions and 336 deletions

View file

@ -3,9 +3,6 @@ package resonantinduction.archaic.filter;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.IFilterable;
import resonantinduction.api.recipe.MachineRecipes;
@ -44,14 +41,6 @@ public class TileFilter extends TileFilterable implements IFilterable
{
worldObj.spawnParticle("dripWater", xCoord + 0.5, yCoord, zCoord + 0.5, 0, 0, 0);
if (checkBelow.getTileEntity(worldObj) instanceof IFluidHandler)
{
IFluidHandler handler = ((IFluidHandler) checkBelow.getTileEntity(worldObj));
if (handler.fill(ForgeDirection.UP, new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), false) <= 0)
return;
}
/**
* Leak the fluid down.
*/
@ -78,15 +67,7 @@ public class TileFilter extends TileFilterable implements IFilterable
/**
* Add liquid to bottom.
*/
if (checkBelow.getTileEntity(worldObj) instanceof IFluidHandler)
{
IFluidHandler handler = ((IFluidHandler) checkBelow.getTileEntity(worldObj));
handler.fill(ForgeDirection.UP, new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), true);
}
else
{
checkBelow.setBlock(worldObj, Block.waterMoving.blockID);
}
checkBelow.setBlock(worldObj, Block.waterMoving.blockID);
}
}
}

View file

@ -12,7 +12,7 @@ import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import resonantinduction.core.Reference;
import resonantinduction.core.fluid.BlockFluidNetwork;
import resonantinduction.core.fluid.BlockFluidNode;
import resonantinduction.core.render.RIBlockRenderingHandler;
import universalelectricity.api.UniversalElectricity;
import universalelectricity.api.vector.Vector3;
@ -26,7 +26,7 @@ import cpw.mods.fml.relauncher.SideOnly;
*
* @author Darkguardsman
*/
public class BlockGutter extends BlockFluidNetwork
public class BlockGutter extends BlockFluidNode
{
public BlockGutter(int id)
{

View file

@ -3,9 +3,12 @@ package resonantinduction.archaic.fluid.gutter;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.core.fluid.IPressurizedNode;
import resonantinduction.core.fluid.TilePressurizedNode;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.utility.FluidUtility;
import calclavia.lib.utility.WorldUtility;
/**
@ -26,30 +29,55 @@ public class TileGutter extends TilePressurizedNode implements IPressurizedNode
sendTankUpdate();
}
@Override
public void refresh()
{
/**
* Drain block above if it is a fluid.
*/
FluidStack drain = FluidUtility.drainBlock(worldObj, new Vector3(this).translate(0, 1, 0), true);
if (drain != null)
fill(ForgeDirection.UP, drain, true);
super.refresh();
}
@Override
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (!this.worldObj.isRemote)
{
if (tileEntity instanceof TileGutter)
{
getNetwork().merge(((TileGutter) tileEntity).getNetwork());
renderSides = WorldUtility.setEnableSide(renderSides, side, true);
connectedBlocks[side.ordinal()] = tileEntity;
}
else if (tileEntity instanceof IFluidHandler)
if (tileEntity instanceof IFluidHandler)
{
if (tileEntity instanceof TileGutter)
{
getNetwork().merge(((TileGutter) tileEntity).getNetwork());
}
renderSides = WorldUtility.setEnableSide(renderSides, side, true);
connectedBlocks[side.ordinal()] = tileEntity;
}
}
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if (!resource.getFluid().isGaseous())
{
return super.fill(from, resource, doFill);
}
return 0;
}
@Override
public int getPressure(ForgeDirection dir)
{
if (dir == ForgeDirection.UP)
return -3;
if (dir == ForgeDirection.DOWN)
return +3;
@ -59,7 +87,7 @@ public class TileGutter extends TilePressurizedNode implements IPressurizedNode
@Override
public int getMaxFlowRate()
{
return 1;
return 20;
}
@Override

View file

@ -10,7 +10,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import resonantinduction.core.fluid.BlockFluidNetwork;
import resonantinduction.core.fluid.BlockFluidNode;
import resonantinduction.core.render.RIBlockRenderingHandler;
import resonantinduction.mechanical.fluid.pipe.ItemBlockFluidContainer;
import universalelectricity.api.UniversalElectricity;
@ -20,7 +20,7 @@ import calclavia.lib.utility.inventory.InventoryUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockTank extends BlockFluidNetwork
public class BlockTank extends BlockFluidNode
{
public BlockTank(int id)
{

View file

@ -28,19 +28,20 @@ public class TankNetwork extends FluidDistributionetwork
@Override
public void update()
{
final FluidStack totalFluid = getTank().getFluid();
final FluidStack networkTankFluid = getTank().getFluid();
int lowestY = 255, highestY = 0;
if (totalFluid != null && getConnectors().size() > 0)
if (getConnectors().size() > 0)
{
FluidStack distributeFluid = totalFluid.copy();
int totalFluid = networkTankFluid != null ? networkTankFluid.amount : 0;
HashMap<Integer, Integer> heightCount = new HashMap<Integer, Integer>();
PriorityQueue<IFluidDistribution> heightPriorityQueue = new PriorityQueue<IFluidDistribution>(1024, new Comparator()
{
@Override
public int compare(Object a, Object b)
{
if (totalFluid.getFluid().isGaseous())
if (networkTankFluid.getFluid().isGaseous())
return 0;
TileEntity wa = (TileEntity) a;
@ -78,23 +79,23 @@ public class TankNetwork extends FluidDistributionetwork
int yCoord = ((TileEntity) distributeNode).yCoord;
int connectorCount = heightCount.get(yCoord);
if (distributeFluid == null || distributeFluid.amount <= 0)
if (totalFluid <= 0)
{
distributeNode.getInternalTank().setFluid(null);
distributeNode.onFluidChanged();
continue;
}
int fluidPer = distributeFluid.amount / connectorCount;
int fluidPer = totalFluid / connectorCount;
int deltaFluidAmount = fluidPer - distributeNode.getInternalTank().getFluidAmount();
int current = distributeNode.getInternalTank().getFluidAmount();
if (deltaFluidAmount > 0)
{
int filled = distributeNode.getInternalTank().fill(FluidUtility.getStack(distributeFluid, deltaFluidAmount), false);
distributeNode.getInternalTank().fill(FluidUtility.getStack(distributeFluid, deltaFluidAmount / 10), true);
distributeFluid.amount -= current + filled;
int filled = distributeNode.getInternalTank().fill(FluidUtility.getStack(networkTankFluid, deltaFluidAmount), false);
distributeNode.getInternalTank().fill(FluidUtility.getStack(networkTankFluid, deltaFluidAmount / 10), true);
totalFluid -= current + filled;
}
else
{
@ -102,7 +103,7 @@ public class TankNetwork extends FluidDistributionetwork
distributeNode.getInternalTank().drain(Math.abs(deltaFluidAmount / 10), true);
if (drain != null)
distributeFluid.amount -= current - drain.amount;
totalFluid -= current - drain.amount;
}
if (deltaFluidAmount != 0)

View file

@ -116,9 +116,6 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack itemStack)
{
if (!world().isRemote)
System.out.println(getNetwork());
if (itemStack != null && itemStack.getItem() instanceof ItemHandCrank)
{
if (player.isSneaking())
@ -128,10 +125,10 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
getMultiBlock().get().angularVelocity = -getMultiBlock().get().angularVelocity;
player.addChatMessage("Flipped gear to rotate " + (angularVelocity > 0 ? "clockwise" : "anticlockwise") + ".");
}
return true;
}
getMultiBlock().get().manualCrankTime = 10;
world().playSoundEffect(x() + 0.5, y() + 0.5, z() + 0.5, Reference.PREFIX + "gearCrank", 0.5f, 0.9f + world().rand.nextFloat() * 0.2f);
player.addExhaustion(0.01f);

View file

@ -135,16 +135,7 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IPressurize
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
if (!world().isRemote)
{
if (doDrain)
{
markPacket = true;
}
return tank.drain(resource.amount, doDrain);
}
return null;
return drain(from, resource.amount, doDrain);
}
@Override

View file

@ -5,10 +5,12 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import calclavia.lib.prefab.block.BlockTile;
/** @author Calclavia */
public abstract class BlockFluidNetwork extends BlockTile
/**
* @author Calclavia
*/
public abstract class BlockFluidNode extends BlockTile
{
public BlockFluidNetwork(int id, Material material)
public BlockFluidNode(int id, Material material)
{
super(id, material);
}

View file

@ -99,8 +99,7 @@ public abstract class FluidDistributionetwork extends NodeNetwork<FluidDistribut
{
if (resource != null && resource.isFluidEqual(getTank().getFluid()))
{
FluidStack before = this.getTank().getFluid();
FluidStack drain = this.getTank().drain(resource.amount, doDrain);
FluidStack drain = getTank().drain(resource.amount, doDrain);
needsUpdate = true;
NetworkTickHandler.addNetwork(this);
return drain;
@ -111,10 +110,10 @@ public abstract class FluidDistributionetwork extends NodeNetwork<FluidDistribut
public FluidStack drain(IFluidDistribution source, ForgeDirection from, int resource, boolean doDrain)
{
if (getTank().getFluid() != null)
return this.drain(source, from, FluidUtility.getStack(getTank().getFluid(), resource), doDrain);
return null;
FluidStack drain = getTank().drain(resource, doDrain);
needsUpdate = true;
NetworkTickHandler.addNetwork(this);
return drain;
}
public FluidTank getTank()

View file

@ -12,7 +12,7 @@ import universalelectricity.core.net.NodeNetwork;
/**
* The network for pipe fluid transfer. getNodes() is NOT used.
*
* @author DarkGuardsman
* @author Calclavia
*/
public class PressureNetwork extends NodeNetwork<PressureNetwork, IPressurizedNode, IFluidHandler> implements IUpdate
{
@ -26,10 +26,8 @@ public class PressureNetwork extends NodeNetwork<PressureNetwork, IPressurizedNo
{
for (IPressurizedNode connector : getConnectors())
{
calculatePressure((IPressurizedNode) connector);
distribute((IPressurizedNode) connector);
}
}
@ -55,18 +53,23 @@ public class PressureNetwork extends NodeNetwork<PressureNetwork, IPressurizedNo
int minPressure = 0;
int maxPressure = 0;
for (int i = 0; i < 6; i++)
Object[] connections = sourcePipe.getConnections();
if (connections != null)
{
Object obj = sourcePipe.getConnections()[i];
if (obj instanceof IPressure)
for (int i = 0; i < connections.length; i++)
{
int pressure = ((IPressure) obj).getPressure(ForgeDirection.getOrientation(i).getOpposite());
Object obj = connections[i];
minPressure = Math.min(pressure, minPressure);
maxPressure = Math.max(pressure, maxPressure);
totalPressure += pressure;
findCount++;
if (obj instanceof IPressure)
{
int pressure = ((IPressure) obj).getPressure(ForgeDirection.getOrientation(i).getOpposite());
minPressure = Math.min(pressure, minPressure);
maxPressure = Math.max(pressure, maxPressure);
totalPressure += pressure;
findCount++;
}
}
}
@ -127,14 +130,14 @@ public class PressureNetwork extends NodeNetwork<PressureNetwork, IPressurizedNo
{
int amountB = tankB.getFluidAmount();
int quantity = Math.max(pressureA > pressureB ? (pressureA - pressureB) * sourcePipe.getMaxFlowRate() : 0, (amountA - amountB) / 2);
int quantity = Math.max(pressureA > pressureB ? (pressureA - pressureB) * sourcePipe.getMaxFlowRate() : 0, Math.min((amountA - amountB) / 2, sourcePipe.getMaxFlowRate()));
quantity = Math.min(Math.min(quantity, tankB.getCapacity() - amountB), amountA);
if (quantity > 0)
{
FluidStack drainStack = sourcePipe.drain(dir.getOpposite(), quantity, false);
if (drainStack != null)
if (drainStack != null && drainStack.amount > 0)
sourcePipe.drain(dir.getOpposite(), otherPipe.fill(dir, drainStack, true), true);
}
}
@ -198,5 +201,6 @@ public class PressureNetwork extends NodeNetwork<PressureNetwork, IPressurizedNo
public void reconstruct()
{
NetworkTickHandler.addNetwork(this);
super.reconstruct();
}
}

View file

@ -32,27 +32,13 @@ import cpw.mods.fml.relauncher.SideOnly;
*
* @author DarkGuardsman
*/
public abstract class TileFluidDistribution extends TileAdvanced implements IFluidDistribution, IPacketReceiverWithID, IInformation
public abstract class TileFluidDistribution extends TileFluidNode implements IFluidDistribution
{
protected int pressure;
protected FluidTank tank;
protected Object[] connectedBlocks = new Object[6];
protected int colorID = 0;
/** Copy of the tank's content last time it updated */
protected FluidStack prevStack = null;
/** Network used to link all parts together */
protected FluidDistributionetwork network;
public static final int PACKET_DESCRIPTION = 0;
public static final int PACKET_RENDER = 1;
public static final int PACKET_TANK = 2;
/** Bitmask that handles connections for the renderer **/
public byte renderSides = 0;
@Override
public void initiate()
{
@ -152,97 +138,6 @@ public abstract class TileFluidDistribution extends TileAdvanced implements IFlu
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.colorID = nbt.getInteger("subID");
getInternalTank().readFromNBT(nbt.getCompoundTag("FluidTank"));
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("subID", this.colorID);
nbt.setCompoundTag("FluidTank", this.getInternalTank().writeToNBT(new NBTTagCompound()));
}
@Override
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
if (this.worldObj.isRemote)
{
if (id == PACKET_DESCRIPTION)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
this.tank = new FluidTank(data.readInt());
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
return true;
}
else if (id == PACKET_RENDER)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
return true;
}
else if (id == PACKET_TANK)
{
tank = new FluidTank(data.readInt()).readFromNBT(PacketHandler.readNBTTagCompound(data));
pressure = data.readInt();
return true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
return true;
}
return false;
}
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_DESCRIPTION, this, this.colorID, this.renderSides, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound()));
}
public void sendRenderUpdate()
{
if (!this.worldObj.isRemote)
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_RENDER, this, this.colorID, this.renderSides));
}
public void sendTankUpdate()
{
if (!this.worldObj.isRemote)
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, getInternalTank().getCapacity(), getInternalTank().writeToNBT(new NBTTagCompound()), pressure), this.worldObj, new Vector3(this), 60);
}
@Override
public void onFluidChanged()
{
if (!worldObj.isRemote)
{
if (!FluidUtility.matchExact(prevStack, getInternalTank().getFluid()))
{
sendTankUpdate();
prevStack = tank.getFluid() != null ? tank.getFluid().copy() : null;
}
}
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return AxisAlignedBB.getAABBPool().getAABB(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
}
public int getSubID()
{
return this.colorID;
@ -259,22 +154,6 @@ public abstract class TileFluidDistribution extends TileAdvanced implements IFlu
return true;
}
@Override
public FluidTank getInternalTank()
{
if (this.tank == null)
{
this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
}
return this.tank;
}
@Override
public void getInformation(List<String> info)
{
info.add(this.getNetwork().toString());
}
@Override
public IFluidDistribution getInstance(ForgeDirection from)
{

View file

@ -0,0 +1,132 @@
package resonantinduction.core.fluid;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import resonantinduction.core.ResonantInduction;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.network.IPacketReceiverWithID;
import calclavia.lib.network.PacketHandler;
import calclavia.lib.prefab.tile.TileAdvanced;
import calclavia.lib.utility.FluidUtility;
import com.google.common.io.ByteArrayDataInput;
/**
* A prefab class for tiles that use the fluid network.
*
* @author DarkGuardsman
*/
public abstract class TileFluidNode extends TileAdvanced implements IPacketReceiverWithID
{
protected int pressure;
protected FluidTank tank;
protected int colorID = 0;
/** Copy of the tank's content last time it updated */
protected FluidStack prevStack = null;
public static final int PACKET_DESCRIPTION = 0;
public static final int PACKET_RENDER = 1;
public static final int PACKET_TANK = 2;
/** Bitmask that handles connections for the renderer **/
public byte renderSides = 0;
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.colorID = nbt.getInteger("subID");
getInternalTank().readFromNBT(nbt.getCompoundTag("FluidTank"));
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("subID", this.colorID);
nbt.setCompoundTag("FluidTank", getInternalTank().writeToNBT(new NBTTagCompound()));
}
@Override
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
if (this.worldObj.isRemote)
{
if (id == PACKET_DESCRIPTION)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
this.tank = new FluidTank(data.readInt());
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
return true;
}
else if (id == PACKET_RENDER)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
return true;
}
else if (id == PACKET_TANK)
{
tank = new FluidTank(data.readInt()).readFromNBT(PacketHandler.readNBTTagCompound(data));
pressure = data.readInt();
return true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
return true;
}
return false;
}
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_DESCRIPTION, this, this.colorID, this.renderSides, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound()));
}
public void sendRenderUpdate()
{
if (!this.worldObj.isRemote)
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_RENDER, this, this.colorID, this.renderSides));
}
public void sendTankUpdate()
{
if (!this.worldObj.isRemote)
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, getInternalTank().getCapacity(), getInternalTank().writeToNBT(new NBTTagCompound()), pressure), this.worldObj, new Vector3(this), 60);
}
public void onFluidChanged()
{
if (!worldObj.isRemote)
{
if (!FluidUtility.matchExact(prevStack, getInternalTank().getFluid()))
{
sendTankUpdate();
prevStack = tank.getFluid() != null ? tank.getFluid().copy() : null;
}
}
}
public FluidTank getInternalTank()
{
if (this.tank == null)
{
this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
}
return this.tank;
}
}

View file

@ -28,27 +28,13 @@ import cpw.mods.fml.relauncher.SideOnly;
*
* @author DarkGuardsman
*/
public abstract class TilePressurizedNode extends TileAdvanced implements IPressurizedNode, IPacketReceiverWithID
public abstract class TilePressurizedNode extends TileFluidNode implements IPressurizedNode, IPacketReceiverWithID
{
protected int pressure;
protected FluidTank tank;
protected Object[] connectedBlocks = new Object[6];
protected int colorID = 0;
/** Copy of the tank's content last time it updated */
protected FluidStack prevStack = null;
/** Network used to link all parts together */
protected PressureNetwork network;
public static final int PACKET_DESCRIPTION = 0;
public static final int PACKET_RENDER = 1;
public static final int PACKET_TANK = 2;
/** Bitmask that handles connections for the renderer **/
public byte renderSides = 0;
public TilePressurizedNode()
{
getInternalTank().setCapacity(FluidContainerRegistry.BUCKET_VOLUME);
@ -78,22 +64,15 @@ public abstract class TilePressurizedNode extends TileAdvanced implements IPress
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if (!resource.getFluid().isGaseous())
{
int fill = getInternalTank().fill(resource, doFill);
onFluidChanged();
return fill;
}
return 0;
int fill = getInternalTank().fill(resource, doFill);
onFluidChanged();
return fill;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
FluidStack drain = getInternalTank().drain(resource.amount, doDrain);
onFluidChanged();
return drain;
return drain(from, resource.amount, doDrain);
}
@Override
@ -118,7 +97,7 @@ public abstract class TilePressurizedNode extends TileAdvanced implements IPress
public void refresh()
{
if (this.worldObj != null && !this.worldObj.isRemote)
if (!this.worldObj.isRemote)
{
byte previousConnections = renderSides;
connectedBlocks = new Object[6];
@ -126,15 +105,16 @@ public abstract class TilePressurizedNode extends TileAdvanced implements IPress
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
this.validateConnectionSide(new Vector3(this).translate(dir).getTileEntity(worldObj), dir);
validateConnectionSide(new Vector3(this).translate(dir).getTileEntity(worldObj), dir);
}
/** Only send packet updates if visuallyConnected changed. */
if (previousConnections != renderSides)
{
sendRenderUpdate();
getNetwork().reconstruct();
}
getNetwork().reconstruct();
}
}
@ -145,110 +125,7 @@ public abstract class TilePressurizedNode extends TileAdvanced implements IPress
* @param tileEntity - the tileEntity being checked
* @param side - side the connection is too
*/
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (!this.worldObj.isRemote)
{
if (tileEntity instanceof IFluidDistribution)
{
this.getNetwork().merge(((IPressurizedNode) tileEntity).getNetwork());
renderSides = WorldUtility.setEnableSide(renderSides, side, true);
connectedBlocks[side.ordinal()] = tileEntity;
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.colorID = nbt.getInteger("subID");
getInternalTank().readFromNBT(nbt.getCompoundTag("FluidTank"));
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("subID", this.colorID);
nbt.setCompoundTag("FluidTank", this.getInternalTank().writeToNBT(new NBTTagCompound()));
}
@Override
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
if (this.worldObj.isRemote)
{
if (id == PACKET_DESCRIPTION)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
this.tank = new FluidTank(data.readInt());
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
return true;
}
else if (id == PACKET_RENDER)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
return true;
}
else if (id == PACKET_TANK)
{
tank = new FluidTank(data.readInt()).readFromNBT(PacketHandler.readNBTTagCompound(data));
pressure = data.readInt();
return true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
return true;
}
return false;
}
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_DESCRIPTION, this, this.colorID, this.renderSides, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound()));
}
public void sendRenderUpdate()
{
if (!this.worldObj.isRemote)
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_RENDER, this, this.colorID, this.renderSides));
}
public void sendTankUpdate()
{
if (!this.worldObj.isRemote)
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, getInternalTank().getCapacity(), getInternalTank().writeToNBT(new NBTTagCompound()), pressure), this.worldObj, new Vector3(this), 60);
}
@Override
public void onFluidChanged()
{
if (!worldObj.isRemote)
{
if (!FluidUtility.matchExact(prevStack, this.getInternalTank().getFluid()))
{
sendTankUpdate();
}
prevStack = tank.getFluid();
}
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return AxisAlignedBB.getAABBPool().getAABB(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
}
public abstract void validateConnectionSide(TileEntity tileEntity, ForgeDirection side);
public int getSubID()
{
@ -305,5 +182,4 @@ public abstract class TilePressurizedNode extends TileAdvanced implements IPress
{
this.network = network;
}
}