Updated most things to use the new network code

This commit is contained in:
DarkGuardsman 2014-01-13 01:13:23 -05:00
parent 6002f9d744
commit 329429ae3b
14 changed files with 863 additions and 727 deletions

View file

@ -33,6 +33,15 @@ public interface IFluidNetwork extends INetwork<IFluidNetwork, IFluidPart, IFlui
* @return FluidStack that contains the fluid drained from the network */
FluidStack drain(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doDrain);
/** Called to remove fluid from a network, not supported by all networks
*
* @param source - part that is receiving the fluid for the network
* @param from - direction of this connection
* @param resource - fluid stack that is being filled into the network
* @param doDrain - true causes the action to be taken, false simulates the action
* @return FluidStack that contains the fluid drained from the network */
FluidStack drain(IFluidPart source, ForgeDirection from, int resource, boolean doDrain);
/** Fluid tank that represents the entire network */
FluidTank getTank();

View file

@ -0,0 +1,225 @@
package resonantinduction.mechanical.fluid.network;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.api.fluid.IFluidPart;
import universalelectricity.api.net.IConnector;
import universalelectricity.core.net.ConnectionPathfinder;
import universalelectricity.core.net.Network;
public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandler> implements IFluidNetwork
{
protected FluidTank tank;
protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1];
public FluidNetwork()
{
}
public FluidNetwork(IFluidPart... parts)
{
for (IFluidPart part : parts)
{
this.addConnector(part);
}
}
@Override
public void reconstruct()
{
// TODO Auto-generated method stub
}
public void rebuildTank()
{
if (this.getTank() != null)
{
this.tankInfo[0] = this.getTank().getInfo();
}
else
{
this.tankInfo[0] = null;
}
}
@Override
public int fill(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doFill)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public FluidStack drain(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doDrain)
{
// TODO Auto-generated method stub
return null;
}
@Override
public FluidStack drain(IFluidPart source, ForgeDirection from, int resource, boolean doDrain)
{
// TODO Auto-generated method stub
return null;
}
@Override
public boolean canUpdate()
{
// TODO Auto-generated method stub
return false;
}
@Override
public boolean continueUpdate()
{
// TODO Auto-generated method stub
return false;
}
@Override
public void update()
{
// TODO Auto-generated method stub
}
@Override
public IFluidNetwork merge(IFluidNetwork network)
{
FluidNetwork newNetwork = null;
if (network != null && network.getClass().equals(this.getClass()) && network != this)
{
try
{
newNetwork = this.getClass().newInstance();
newNetwork.getConnectors().addAll(this.getConnectors());
newNetwork.getConnectors().addAll(network.getConnectors());
network.getConnectors().clear();
network.getNodes().clear();
this.getConnectors().clear();
this.getNodes().clear();
newNetwork.reconstruct();
}
catch (Exception e)
{
e.printStackTrace();
}
}
return newNetwork;
}
@Override
public void split(IFluidPart splitPoint)
{
this.removeConnector(splitPoint);
this.reconstruct();
/** Loop through the connected blocks and attempt to see if there are connections between the
* two points elsewhere. */
Object[] connectedBlocks = splitPoint.getConnections();
for (int i = 0; i < connectedBlocks.length; i++)
{
Object connectedBlockA = connectedBlocks[i];
if (connectedBlockA instanceof IFluidPart)
{
for (int ii = 0; ii < connectedBlocks.length; ii++)
{
final Object connectedBlockB = connectedBlocks[ii];
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof IFluidPart)
{
ConnectionPathfinder finder = new ConnectionPathfinder((IFluidPart) connectedBlockB, splitPoint);
finder.findNodes((IFluidPart) connectedBlockA);
if (finder.results.size() <= 0)
{
try
{
/** The connections A and B are not connected anymore. Give them both
* a new common network. */
IFluidNetwork newNetwork = this.getClass().newInstance();
for (IConnector node : finder.closedSet)
{
if (node != splitPoint && node instanceof IFluidPart)
{
newNetwork.addConnector((IFluidPart) node);
}
}
newNetwork.reconstruct();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}
}
}
@Override
public void split(IFluidPart connectorA, IFluidPart connectorB)
{
this.reconstruct();
/** Check if connectorA connects with connectorB. */
ConnectionPathfinder finder = new ConnectionPathfinder(connectorB);
finder.findNodes(connectorA);
if (finder.results.size() <= 0)
{
/** The connections A and B are not connected anymore. Give them both a new common
* network. */
IFluidNetwork newNetwork;
try
{
newNetwork = this.getClass().newInstance();
for (IConnector node : finder.closedSet)
{
if (node instanceof IFluidPart)
{
newNetwork.addConnector((IFluidPart) node);
}
}
newNetwork.reconstruct();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
@Override
public FluidTank getTank()
{
return this.tank;
}
@Override
public FluidTankInfo[] getTankInfo()
{
return tankInfo;
}
}

View file

@ -1,26 +0,0 @@
package resonantinduction.mechanical.fluid.network;
import net.minecraftforge.fluids.FluidStack;
public class FluidPressurePack implements Cloneable
{
public FluidStack liquidStack;
public double pressure;
public FluidPressurePack(FluidStack liquidStack, double voltage)
{
this.liquidStack = liquidStack;
this.pressure = voltage;
}
@Override
public FluidPressurePack clone()
{
return new FluidPressurePack(this.liquidStack, this.pressure);
}
public boolean isEqual(FluidPressurePack packet)
{
return this.liquidStack.isFluidEqual(packet.liquidStack) && this.pressure == packet.pressure;
}
}

View file

@ -3,7 +3,6 @@ package resonantinduction.mechanical.fluid.pipe;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@ -13,7 +12,8 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import resonantinduction.mechanical.fluid.prefab.BlockFluidNetwork;
import resonantinduction.mechanical.render.MechanicalBlockRenderingHandler;
import universalelectricity.api.vector.Vector3;
@ -128,10 +128,10 @@ public class BlockPipe extends BlockFluidNetwork
TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TilePipe)
{
FluidTankInfo tank = ((TilePipe) entity).getTankInfo()[0];
if (tank != null && tank.fluid != null && tank.fluid.getFluid() != null && tank.fluid.amount > 0)
FluidTank tank = ((TilePipe) entity).getTank();
if (tank != null && tank.getFluid() != null)
{
((TilePipe) entity).getTileNetwork().drainNetworkTank(world, FluidHelper.fillBlock(world, new Vector3(x, y, z), tank.fluid, true), true);
FluidHelper.fillBlock(world, new Vector3(x, y, z), tank.getFluid(), true);
}
}
super.breakBlock(world, x, y, z, par5, par6);

View file

@ -24,102 +24,102 @@ import universalelectricity.api.vector.Vector3;
public class ItemBlockFluidContainer extends ItemBlock
{
public ItemBlockFluidContainer(int id)
{
super(id);
this.setMaxDamage(0);
this.setHasSubtypes(true);
}
public ItemBlockFluidContainer(int id)
{
super(id);
this.setMaxDamage(0);
this.setHasSubtypes(true);
}
@Override
public int getMetadata(int damage)
{
return damage;
}
@Override
public int getMetadata(int damage)
{
return damage;
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
{
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
FluidStack fluid = FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid"));
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
{
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
FluidStack fluid = FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid"));
if (fluid != null)
{
list.add("Fluid: " + fluid.getFluid().getLocalizedName());
list.add("Volume: " + UnitDisplay.getDisplay(fluid.amount, Unit.LITER, UnitPrefix.MILLI));
}
}
}
if (fluid != null)
{
list.add("Fluid: " + fluid.getFluid().getLocalizedName());
list.add("Volume: " + UnitDisplay.getDisplay(fluid.amount, Unit.LITER, UnitPrefix.MILLI));
}
}
}
public static ItemStack getWrenchedItem(World world, Vector3 vec)
{
TileEntity entity = vec.getTileEntity(world);
if (entity instanceof TileTank && ((TileTank) entity).getTankInfo() != null && ((TileTank) entity).getTankInfo()[0] != null)
{
ItemStack itemStack = new ItemStack(Mechanical.blockTank);
FluidStack stack = ((TileTank) entity).getTankInfo()[0].fluid;
public static ItemStack getWrenchedItem(World world, Vector3 vec)
{
TileEntity entity = vec.getTileEntity(world);
if (entity instanceof TileTank && ((TileTank) entity).getTank() != null && ((TileTank) entity).getTank().getFluid() != null)
{
ItemStack itemStack = new ItemStack(Mechanical.blockTank);
FluidStack stack = ((TileTank) entity).getTank().getFluid();
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
if (stack != null)
{
((TileTank) entity).drain(ForgeDirection.UNKNOWN, stack.amount, true);
itemStack.getTagCompound().setCompoundTag("fluid", stack.writeToNBT(new NBTTagCompound()));
}
return itemStack;
}
return null;
}
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
if (stack != null)
{
((TileTank) entity).drain(ForgeDirection.UNKNOWN, stack.amount, true);
itemStack.getTagCompound().setCompoundTag("fluid", stack.writeToNBT(new NBTTagCompound()));
}
return itemStack;
}
return null;
}
@Override
public void onUpdate(ItemStack itemStack, World par2World, Entity entity, int par4, boolean par5)
{
if (entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) entity;
@Override
public void onUpdate(ItemStack itemStack, World par2World, Entity entity, int par4, boolean par5)
{
if (entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) entity;
if (itemStack.getTagCompound() != null && !player.capabilities.isCreativeMode && itemStack.getTagCompound().hasKey("fluid"))
{
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, 0));
}
}
}
if (itemStack.getTagCompound() != null && !player.capabilities.isCreativeMode && itemStack.getTagCompound().hasKey("fluid"))
{
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, 0));
}
}
}
@Override
public int getItemStackLimit(ItemStack stack)
{
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
return 1;
}
return this.maxStackSize;
}
@Override
public int getItemStackLimit(ItemStack stack)
{
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
return 1;
}
return this.maxStackSize;
}
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage();
}
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage();
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, (metadata / FluidContainerMaterial.spacing)))
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFluidNetwork)
{
((TileFluidNetwork) tile).setSubID(stack.getItemDamage());
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
((TileFluidNetwork) tile).fill(ForgeDirection.UNKNOWN, FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid")), true);
}
}
return true;
}
return false;
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, (metadata / FluidContainerMaterial.spacing)))
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFluidNetwork)
{
((TileFluidNetwork) tile).setSubID(stack.getItemDamage());
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
((TileFluidNetwork) tile).fill(ForgeDirection.UNKNOWN, FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid")), true);
}
}
return true;
}
return false;
}
}

View file

@ -0,0 +1,15 @@
package resonantinduction.mechanical.fluid.pipe;
import resonantinduction.api.fluid.IFluidPipe;
import resonantinduction.mechanical.fluid.network.FluidNetwork;
/** @author DarkGuardsman */
public class PipeNetwork extends FluidNetwork
{
//TODO implements pressure for future hydraulic machines
public PipeNetwork(IFluidPipe... pipes)
{
super(pipes);
}
}

View file

@ -47,7 +47,7 @@ public class RenderPipe extends TileEntitySpecialRenderer
if (mat == FluidContainerMaterial.WOOD || mat == FluidContainerMaterial.STONE)
{
FluidStack liquid = tile.getTank().getFluid();
int cap = tile.getTankInfo()[0].capacity;
int cap = tile.getTank().getCapacity();
// FluidStack liquid = new FluidStack(FluidRegistry.WATER, cap);
if (liquid != null && liquid.amount > 100)

View file

@ -5,9 +5,9 @@ import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.fluid.INetworkPipe;
import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.api.fluid.IFluidPipe;
import resonantinduction.core.tilenetwork.ITileConnector;
import resonantinduction.core.tilenetwork.ITileNetwork;
import resonantinduction.mechanical.fluid.network.NetworkPipes;
import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
import universalelectricity.api.vector.Vector3;
@ -15,181 +15,148 @@ import calclavia.lib.utility.FluidHelper;
import dark.lib.helpers.ColorCode;
import dark.lib.helpers.ColorCode.IColorCoded;
public class TilePipe extends TileFluidNetwork implements IColorCoded, INetworkPipe
public class TilePipe extends TileFluidNetwork implements IColorCoded, IFluidPipe
{
/** gets the current color mark of the pipe */
@Override
public ColorCode getColor()
{
return EnumPipeType.getColorCode(this.colorID);
}
/** gets the current color mark of the pipe */
@Override
public ColorCode getColor()
{
return EnumPipeType.getColorCode(this.colorID);
}
/** sets the current color mark of the pipe */
@Override
public boolean setColor(Object cc)
{
if (!worldObj.isRemote)
{
int p = this.colorID;
this.colorID = EnumPipeType.getUpdatedID(colorID, ColorCode.get(cc));
return p != this.colorID;
}
return false;
}
/** sets the current color mark of the pipe */
@Override
public boolean setColor(Object cc)
{
if (!worldObj.isRemote)
{
int p = this.colorID;
this.colorID = EnumPipeType.getUpdatedID(colorID, ColorCode.get(cc));
return p != this.colorID;
}
return false;
}
@Override
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
int meta = new Vector3(this).getBlockMetadata(this.worldObj);
if (meta < FluidContainerMaterial.values().length)
{
FluidContainerMaterial pipeMat = FluidContainerMaterial.values()[meta];
if (pipeMat == FluidContainerMaterial.WOOD || pipeMat == FluidContainerMaterial.STONE)
{
if (side == ForgeDirection.UP)
{
return;
}
}
}
if (tileEntity instanceof TilePipe)
{
int metaOther = new Vector3(tileEntity).getBlockMetadata(this.worldObj);
if (meta < FluidContainerMaterial.values().length && metaOther < FluidContainerMaterial.values().length)
{
FluidContainerMaterial pipeMat = FluidContainerMaterial.values()[meta];
FluidContainerMaterial pipeMatOther = FluidContainerMaterial.values()[metaOther];
// Same pipe types can connect
if (pipeMat == pipeMatOther)
{
this.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
setRenderSide(side, true);
}
else if ((pipeMat == FluidContainerMaterial.WOOD || pipeMat == FluidContainerMaterial.STONE) && (pipeMatOther == FluidContainerMaterial.WOOD || pipeMatOther == FluidContainerMaterial.STONE))
{
// Wood and stone pipes can connect to each other but not other pipe types since
// they are more like a trough than a pipe
this.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
setRenderSide(side, true);
}
else if (pipeMat != FluidContainerMaterial.WOOD && pipeMat != FluidContainerMaterial.STONE && pipeMatOther != FluidContainerMaterial.WOOD && pipeMatOther != FluidContainerMaterial.STONE && pipeMat != FluidContainerMaterial.GLASS && pipeMatOther != FluidContainerMaterial.GLASS)
{
/*
* 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
*/
this.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
setRenderSide(side, true);
}
}
}
else if (tileEntity instanceof IFluidHandler)
{
connectedBlocks.add(tileEntity);
setRenderSide(side, true);
this.getTileNetwork().addTank(side.getOpposite(), (IFluidHandler) tileEntity);
}
else if (tileEntity instanceof ITileConnector && ((ITileConnector) tileEntity).canTileConnect(Connection.FLUIDS, side.getOpposite()))
{
connectedBlocks.add(tileEntity);
setRenderSide(side, true);
}
@Override
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
int meta = new Vector3(this).getBlockMetadata(this.worldObj);
if (meta < FluidContainerMaterial.values().length)
{
FluidContainerMaterial pipeMat = FluidContainerMaterial.values()[meta];
if (pipeMat == FluidContainerMaterial.WOOD || pipeMat == FluidContainerMaterial.STONE)
{
if (side == ForgeDirection.UP)
{
return;
}
}
}
if (tileEntity instanceof TilePipe)
{
int metaOther = new Vector3(tileEntity).getBlockMetadata(this.worldObj);
if (meta < FluidContainerMaterial.values().length && metaOther < FluidContainerMaterial.values().length)
{
FluidContainerMaterial pipeMat = FluidContainerMaterial.values()[meta];
FluidContainerMaterial pipeMatOther = FluidContainerMaterial.values()[metaOther];
// Same pipe types can connect
if (pipeMat == pipeMatOther)
{
this.getNetwork().merge(((IFluidPipe) tileEntity).getNetwork());
connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true);
}
else if ((pipeMat == FluidContainerMaterial.WOOD || pipeMat == FluidContainerMaterial.STONE) && (pipeMatOther == FluidContainerMaterial.WOOD || pipeMatOther == FluidContainerMaterial.STONE))
{
// Wood and stone pipes can connect to each other but not other pipe types since
// they are more like a trough than a pipe
this.getNetwork().merge(((IFluidPipe) tileEntity).getNetwork());
connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true);
}
else if (pipeMat != FluidContainerMaterial.WOOD && pipeMat != FluidContainerMaterial.STONE && pipeMatOther != FluidContainerMaterial.WOOD && pipeMatOther != FluidContainerMaterial.STONE && pipeMat != FluidContainerMaterial.GLASS && pipeMatOther != FluidContainerMaterial.GLASS)
{
/*
* 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
*/
this.getNetwork().merge(((IFluidPipe) tileEntity).getNetwork());
connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true);
}
}
}
else if (tileEntity instanceof IFluidHandler)
{
connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true);
}
else if (tileEntity instanceof ITileConnector && ((ITileConnector) tileEntity).canTileConnect(Connection.FLUIDS, side.getOpposite()))
{
connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true);
}
}
}
@Override
public double getMaxPressure(ForgeDirection side)
{
int meta = this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if (meta < FluidContainerMaterial.values().length)
{
return FluidContainerMaterial.values()[meta].maxPressure;
}
return 350;
}
@Override
public PipeNetwork getNetwork()
{
if (!(this.network instanceof PipeNetwork))
{
this.setNetwork(new PipeNetwork(this));
}
return (PipeNetwork) this.network;
}
@Override
public NetworkPipes getTileNetwork()
{
if (!(this.network instanceof NetworkPipes))
{
this.setTileNetwork(new NetworkPipes(this));
}
return (NetworkPipes) this.network;
}
@Override
public void setNetwork(IFluidNetwork network)
{
if (network instanceof PipeNetwork)
{
this.network = (PipeNetwork) network;
}
}
@Override
public void setTileNetwork(ITileNetwork network)
{
if (network instanceof NetworkPipes)
{
this.network = (NetworkPipes) network;
}
}
@Override
public void sendTankUpdate(int index)
{
if (this.getBlockMetadata() == FluidContainerMaterial.WOOD.ordinal() || this.getBlockMetadata() == FluidContainerMaterial.STONE.ordinal())
{
super.sendTankUpdate(index);
}
}
@Override
public int getMaxFlowRate(FluidStack stack, ForgeDirection side)
{
if (stack != null)
{
return this.calculateFlowRate(stack, 40, 20);
}
return BlockPipe.waterFlowRate;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return false;
}
/**
* Calculates flow rate based on viscosity & temp of the fluid as all other factors are know
*
* @param fluid - fluidStack
* @param temp = tempature of the fluid
* @param pressure - pressure difference of were the fluid is flowing too.
* @return flow rate in mili-Buckets
*/
public int calculateFlowRate(FluidStack fluid, float pressure, float temp)
{
// TODO recalculate this based on pipe material for friction
if (fluid != null & fluid.getFluid() != null)
{
float f = .012772f * pressure;
f = f / (8 * (fluid.getFluid().getViscosity() / 1000));
return (int) (f * 1000);
}
return BlockPipe.waterFlowRate;
}
@Override
public int getPressureIn(ForgeDirection side)
{
return this.getMaxPressure();
}
@Override
public boolean onOverPressure(Boolean damageAllowed)
{
if (damageAllowed)
{
if (this.tank.getFluid() != null && this.tank.getFluid() != null)
{
this.getTileNetwork().drainNetworkTank(this.worldObj, FluidHelper.fillBlock(this.worldObj, new Vector3(this), this.tank.getFluid(), true), true);
}
else
{
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, yCoord, 0, 0);
}
return true;
}
return false;
}
@Override
public void onWrongPressure(ForgeDirection side, int pressure)
{
// TODO Auto-generated method stub
}
@Override
public void sendTankUpdate(int index)
{
if (this.getBlockMetadata() == FluidContainerMaterial.WOOD.ordinal() || this.getBlockMetadata() == FluidContainerMaterial.STONE.ordinal())
{
super.sendTankUpdate(index);
}
}
@Override
public int getMaxPressure()
{
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return false;
}
@Override
public int getMaxFlowRate()
{
// TODO Auto-generated method stub
return 0;
}
}

View file

@ -4,7 +4,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
@ -17,14 +16,11 @@ import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import resonantinduction.api.fluid.FluidMasterList;
import resonantinduction.api.fluid.INetworkFluidPart;
import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.api.fluid.IFluidPart;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.tilenetwork.INetworkPart;
import resonantinduction.core.tilenetwork.ITileNetwork;
import resonantinduction.mechanical.Mechanical;
import resonantinduction.mechanical.fluid.network.NetworkFluidTiles;
import resonantinduction.mechanical.fluid.pipe.FluidContainerMaterial;
import resonantinduction.mechanical.fluid.network.FluidNetwork;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.PacketHandler;
@ -34,404 +30,363 @@ import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class TileFluidNetwork extends TileEntityFluidDevice implements INetworkFluidPart, IPacketReceiver
public class TileFluidNetwork extends TileEntityFluidDevice implements IFluidPart, IPacketReceiver
{
public static int refreshRate = 10;
protected FluidTank tank;
protected FluidTankInfo[] internalTanksInfo = new FluidTankInfo[1];
protected List<TileEntity> connectedBlocks = new ArrayList<TileEntity>();
protected int heat = 0, maxHeat = 20000;
protected int damage = 0, maxDamage = 1000;
protected int colorID = 0;
protected int tankCap;
protected FluidStack prevStack = null;
protected NetworkFluidTiles network;
public static int refreshRate = 10;
protected FluidTank tank;
protected FluidTankInfo[] internalTanksInfo = new FluidTankInfo[1];
protected Object[] connectedBlocks = new Object[6];
protected int heat = 0, maxHeat = 20000;
protected int damage = 0, maxDamage = 1000;
protected int colorID = 0;
protected int tankCap;
protected FluidStack prevStack = null;
protected IFluidNetwork network;
public static final int PACKET_DESCRIPTION = Mechanical.contentRegistry.getNextPacketID();
public static final int PACKET_RENDER = Mechanical.contentRegistry.getNextPacketID();
public static final int PACKET_TANK = Mechanical.contentRegistry.getNextPacketID();
public static final int PACKET_DESCRIPTION = Mechanical.contentRegistry.getNextPacketID();
public static final int PACKET_RENDER = Mechanical.contentRegistry.getNextPacketID();
public static final int PACKET_TANK = Mechanical.contentRegistry.getNextPacketID();
/** Bitmask **/
public byte renderSides = 0b0;
/** Bitmask **/
public byte renderSides = 0b0;
public TileFluidNetwork()
{
this(1);
}
public TileFluidNetwork()
{
this(1);
}
public TileFluidNetwork(int tankCap)
{
if (tankCap <= 0)
{
tankCap = 1;
}
this.tankCap = tankCap;
this.tank = new FluidTank(this.tankCap * FluidContainerRegistry.BUCKET_VOLUME);
this.internalTanksInfo[0] = this.tank.getInfo();
}
public TileFluidNetwork(int tankCap)
{
if (tankCap <= 0)
{
tankCap = 1;
}
this.tankCap = tankCap;
this.tank = new FluidTank(this.tankCap * FluidContainerRegistry.BUCKET_VOLUME);
this.internalTanksInfo[0] = this.tank.getInfo();
}
public FluidTank getTank()
{
if (tank == null)
{
this.tank = new FluidTank(this.tankCap * FluidContainerRegistry.BUCKET_VOLUME);
this.internalTanksInfo[0] = this.tank.getInfo();
}
return tank;
}
public FluidTank getTank()
{
if (tank == null)
{
this.tank = new FluidTank(this.tankCap * FluidContainerRegistry.BUCKET_VOLUME);
this.internalTanksInfo[0] = this.tank.getInfo();
}
return tank;
}
@Override
public void initiate()
{
super.initiate();
this.refresh();
}
@Override
public void initiate()
{
super.initiate();
this.refresh();
}
@Override
public void updateEntity()
{
super.updateEntity();
@Override
public void updateEntity()
{
super.updateEntity();
if (!worldObj.isRemote)
{
if (ticks % TileFluidNetwork.refreshRate == 0)
{
if (this.getTank().getFluid() == null && this.prevStack == null)
{
// Do nothing
}
else if ((this.getTank().getFluid() == null && this.prevStack != null) || (this.getTank().getFluid() != null && this.prevStack == null) || (this.getTank().getFluid().amount != this.prevStack.amount))
{
this.sendTankUpdate(0);
}
if (!worldObj.isRemote)
{
if (ticks % TileFluidNetwork.refreshRate == 0)
{
if (this.getTank().getFluid() == null && this.prevStack == null)
{
// Do nothing
}
else if ((this.getTank().getFluid() == null && this.prevStack != null) || (this.getTank().getFluid() != null && this.prevStack == null) || (this.getTank().getFluid().amount != this.prevStack.amount))
{
this.sendTankUpdate(0);
}
this.prevStack = this.tank.getFluid();
}
}
}
this.prevStack = this.tank.getFluid();
}
}
}
@Override
public void invalidate()
{
this.getTileNetwork().splitNetwork(this);
super.invalidate();
}
@Override
public void invalidate()
{
this.getNetwork().split(this);
super.invalidate();
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if (this.getTileNetwork() != null && resource != null)
{
return this.getTileNetwork().fillNetworkTank(this, resource, doFill);
}
return 0;
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if (this.getNetwork() != null && resource != null)
{
return this.getNetwork().fill(this, from, resource, doFill);
}
return 0;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
if (this.getTileNetwork() != null && resource != null)
{
if (this.getTileNetwork().getNetworkTank() != null && this.getTileNetwork().getNetworkTank().getFluid() != null && this.getTileNetwork().getNetworkTank().getFluid().isFluidEqual(resource))
{
return this.getTileNetwork().drainNetworkTank(this.worldObj, resource.amount, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
if (this.getNetwork() != null && resource != null)
{
return this.getNetwork().drain(this, from, resource, doDrain);
}
return null;
}
}
return null;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
if (this.getNetwork() != null)
{
return this.getNetwork().drain(this, from, maxDrain, doDrain);
}
return null;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
if (this.getTileNetwork() != null)
{
return this.getTileNetwork().drainNetworkTank(this.worldObj, maxDrain, doDrain);
}
return null;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return true;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return true;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return true;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return true;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return this.getNetwork().getTankInfo();
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return new FluidTankInfo[] { this.getTileNetwork().getNetworkTankInfo() };
}
@Override
public Object[] getConnections()
{
return this.connectedBlocks;
}
@Override
public List<TileEntity> getNetworkConnections()
{
return this.connectedBlocks;
}
public void refresh()
{
if (this.worldObj != null && !this.worldObj.isRemote)
{
byte previousConnections = renderSides;
this.connectedBlocks = new Object[6];
this.renderSides = 0;
@Override
public void refresh()
{
if (this.worldObj != null && !this.worldObj.isRemote)
{
byte previousConnections = renderSides;
this.connectedBlocks.clear();
this.renderSides = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
this.validateConnectionSide(new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj), dir);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
this.validateConnectionSide(new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj), dir);
}
/** Only send packet updates if visuallyConnected changed. */
if (previousConnections != renderSides)
{
this.sendRenderUpdate();
}
}
}
/** Only send packet updates if visuallyConnected changed. */
if (previousConnections != renderSides)
{
this.sendRenderUpdate();
}
}
}
}
/** 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)
{
if (!this.worldObj.isRemote)
{
if (tileEntity instanceof IFluidPart)
{
if (this.canTileConnect(Connection.NETWORK, side.getOpposite()))
{
this.getNetwork().merge(((IFluidPart) tileEntity).getNetwork());
this.setRenderSide(side, true);
connectedBlocks[side.ordinal()] = 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)
{
if (!this.worldObj.isRemote)
{
if (tileEntity instanceof INetworkFluidPart)
{
if (this.canTileConnect(Connection.NETWORK, side.getOpposite()))
{
this.getTileNetwork().mergeNetwork(((INetworkFluidPart) tileEntity).getTileNetwork(), (INetworkPart) tileEntity);
this.setRenderSide(side, true);
connectedBlocks.add(tileEntity);
}
}
}
}
public void setRenderSide(ForgeDirection direction, boolean doRender)
{
if (doRender)
{
renderSides = (byte) (renderSides | (1 << direction.ordinal()));
}
else
{
renderSides = (byte) (renderSides & ~(1 << direction.ordinal()));
public void setRenderSide(ForgeDirection direction, boolean doRender)
{
if (doRender)
{
renderSides = (byte) (renderSides | (1 << direction.ordinal()));
}
else
{
renderSides = (byte) (renderSides & ~(1 << direction.ordinal()));
}
}
}
}
public boolean canRenderSide(ForgeDirection direction)
{
return (renderSides & (1 << direction.ordinal())) != 0;
}
public boolean canRenderSide(ForgeDirection direction)
{
return (renderSides & (1 << direction.ordinal())) != 0;
}
@Override
public IFluidNetwork getNetwork()
{
if (this.network != null)
{
this.network = new FluidNetwork(this);
}
return this.network;
}
@Override
public NetworkFluidTiles getTileNetwork()
{
if (!(this.network instanceof NetworkFluidTiles))
{
this.network = new NetworkFluidTiles(this);
}
return this.network;
}
@Override
public void setNetwork(IFluidNetwork fluidNetwork)
{
this.network = fluidNetwork;
}
@Override
public void setTileNetwork(ITileNetwork fluidNetwork)
{
if (fluidNetwork instanceof NetworkFluidTiles)
{
this.network = (NetworkFluidTiles) fluidNetwork;
}
@Override
public boolean canTileConnect(Connection type, ForgeDirection dir)
{
if (this.damage >= this.maxDamage)
{
return false;
}
return type == Connection.FLUIDS || type == Connection.NETWORK;
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.damage = nbt.getInteger("damage");
this.heat = nbt.getInteger("heat");
this.colorID = nbt.getInteger("subID");
if (nbt.hasKey("stored"))
{
NBTTagCompound tag = nbt.getCompoundTag("stored");
String name = tag.getString("LiquidName");
int amount = nbt.getInteger("Amount");
Fluid fluid = FluidRegistry.getFluid(name);
if (fluid != null)
{
FluidStack liquid = new FluidStack(fluid, amount);
this.getTank().setFluid(liquid);
internalTanksInfo[0] = this.getTank().getInfo();
}
}
else
{
this.getTank().readFromNBT(nbt.getCompoundTag("FluidTank"));
internalTanksInfo[0] = this.getTank().getInfo();
}
}
@Override
public FluidTankInfo[] getTankInfo()
{
if (this.internalTanksInfo == null)
{
this.internalTanksInfo = new FluidTankInfo[] { this.getTank().getInfo() };
}
return this.internalTanksInfo;
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("damage", this.damage);
nbt.setInteger("heat", this.heat);
nbt.setInteger("subID", this.colorID);
nbt.setCompoundTag("FluidTank", this.getTank().writeToNBT(new NBTTagCompound()));
}
@Override
public int fillTankContent(int index, FluidStack stack, boolean doFill)
{
if (index == 0)
{
int p = this.getTank().getFluid() != null ? this.getTank().getFluid().amount : 0;
int fill = this.getTank().fill(stack, doFill);
if (p != fill && doFill)
{
this.internalTanksInfo[index] = this.getTank().getInfo();
}
return fill;
}
return 0;
}
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
if (this.worldObj.isRemote)
{
int readInt = data.readInt();
@Override
public FluidStack drainTankContent(int index, int volume, boolean doDrain)
{
if (index == 0)
{
FluidStack prev = this.getTank().getFluid();
FluidStack stack = this.getTank().drain(volume, doDrain);
if (prev != null && (stack == null || prev.amount != stack.amount) && doDrain)
{
this.internalTanksInfo[index] = this.getTank().getInfo();
}
return stack;
}
return null;
}
if (readInt == PACKET_DESCRIPTION)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
this.tank = new FluidTank(data.readInt());
this.getTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
this.internalTanksInfo[0] = this.getTank().getInfo();
}
else if (readInt == PACKET_RENDER)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
}
else if (readInt == PACKET_TANK)
{
this.tank = new FluidTank(data.readInt());
this.getTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
this.internalTanksInfo[0] = this.getTank().getInfo();
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
@Override
public boolean canTileConnect(Connection type, ForgeDirection dir)
{
if (this.damage >= this.maxDamage)
{
return false;
}
return type == Connection.FLUIDS || type == Connection.NETWORK;
}
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_TILE.getPacket(this, PACKET_DESCRIPTION, this.colorID, this.renderSides, this.getTank().getCapacity(), this.getTank().writeToNBT(new NBTTagCompound()));
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.damage = nbt.getInteger("damage");
this.heat = nbt.getInteger("heat");
this.colorID = nbt.getInteger("subID");
if (nbt.hasKey("stored"))
{
NBTTagCompound tag = nbt.getCompoundTag("stored");
String name = tag.getString("LiquidName");
int amount = nbt.getInteger("Amount");
Fluid fluid = FluidRegistry.getFluid(name);
if (fluid != null)
{
FluidStack liquid = new FluidStack(fluid, amount);
this.getTank().setFluid(liquid);
internalTanksInfo[0] = this.getTank().getInfo();
}
}
else
{
this.getTank().readFromNBT(nbt.getCompoundTag("FluidTank"));
internalTanksInfo[0] = this.getTank().getInfo();
}
}
public void sendRenderUpdate()
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, PACKET_RENDER, this.colorID, this.renderSides));
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("damage", this.damage);
nbt.setInteger("heat", this.heat);
nbt.setInteger("subID", this.colorID);
nbt.setCompoundTag("FluidTank", this.getTank().writeToNBT(new NBTTagCompound()));
}
public void sendTankUpdate(int index)
{
if (this.getTank() != null && index == 0)
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, PACKET_TANK, this.getTank().getCapacity(), this.getTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
}
}
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
if (this.worldObj.isRemote)
{
int readInt = data.readInt();
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
{
if (tool == EnumTools.PIPE_GUAGE)
{
return "Volume: " + this.getNetwork().getTank().getFluidAmount();
}
return null;
}
if (readInt == PACKET_DESCRIPTION)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
this.tank = new FluidTank(data.readInt());
this.getTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
this.internalTanksInfo[0] = this.getTank().getInfo();
}
else if (readInt == PACKET_RENDER)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
}
else if (readInt == PACKET_TANK)
{
this.tank = new FluidTank(data.readInt());
this.getTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
this.internalTanksInfo[0] = this.getTank().getInfo();
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
@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);
}
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_TILE.getPacket(this, PACKET_DESCRIPTION, this.colorID, this.renderSides, this.getTank().getCapacity(), this.getTank().writeToNBT(new NBTTagCompound()));
}
public int getSubID()
{
return this.colorID;
}
public void sendRenderUpdate()
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, PACKET_RENDER, this.colorID, this.renderSides));
}
public void setSubID(int id)
{
this.colorID = id;
}
public void sendTankUpdate(int index)
{
if (this.getTank() != null && index == 0)
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, PACKET_TANK, this.getTank().getCapacity(), this.getTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
}
}
public static boolean canRenderSide(byte renderSides, ForgeDirection direction)
{
return (renderSides & (1 << direction.ordinal())) != 0;
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
{
if (tool == EnumTools.PIPE_GUAGE)
{
return "Volume: " + this.getTileNetwork().getNetworkTank().getFluidAmount();
}
return null;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
@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;
}
public void setSubID(int id)
{
this.colorID = id;
}
public static boolean canRenderSide(byte renderSides, ForgeDirection direction)
{
return (renderSides & (1 << direction.ordinal())) != 0;
}
@Override
public FluidTank getInternalTank()
{
return this.tank;
}
}

View file

@ -1,11 +1,8 @@
package resonantinduction.mechanical.fluid.pump;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Map.Entry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
@ -15,11 +12,10 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.IReadOut.EnumTools;
import resonantinduction.api.fluid.IDrain;
import resonantinduction.api.fluid.INetworkPipe;
import resonantinduction.api.fluid.IFluidPipe;
import resonantinduction.core.tilenetwork.ITileConnector;
import resonantinduction.mechanical.fluid.network.NetworkFluidTiles;
import resonantinduction.mechanical.fluid.pipe.PipeNetwork;
import universalelectricity.api.vector.Vector3;
import universalelectricity.api.vector.VectorHelper;
@ -87,16 +83,16 @@ public class TileConstructionPump extends TilePump implements IFluidHandler, ITi
ignoreList = new ArrayList<IDrain>();
}
if (inputTile instanceof INetworkPipe && ((INetworkPipe) inputTile).getTileNetwork() instanceof NetworkFluidTiles)
if (inputTile instanceof IFluidPipe && ((IFluidPipe) inputTile).getNetwork() instanceof PipeNetwork)
{
if (outputTile instanceof IFluidHandler)
{
for (Entry<IFluidHandler, EnumSet<ForgeDirection>> entry : ((NetworkFluidTiles) ((INetworkPipe) inputTile).getTileNetwork()).connctedFluidHandlers.entrySet())
for (IFluidHandler fluidHandler : ((PipeNetwork) ((IFluidPipe) inputTile).getNetwork()).getNodes())
{
if (entry.getKey() instanceof IDrain && !ignoreList.contains(entry.getKey()))
if (fluidHandler instanceof IDrain && !ignoreList.contains(fluidHandler))
{
drain = (IDrain) entry.getKey();
drain = (IDrain) fluidHandler;
break;
}
}
@ -170,26 +166,4 @@ public class TileConstructionPump extends TilePump implements IFluidHandler, ITi
super.invalidate();
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
{
if (tool == EnumTools.PIPE_GUAGE)
{
TileEntity inputTile = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), getFacing(true));
if (inputTile instanceof INetworkPipe && ((INetworkPipe) inputTile).getTileNetwork() instanceof NetworkFluidTiles)
{
int count = 0;
for (Entry<IFluidHandler, EnumSet<ForgeDirection>> entry : ((NetworkFluidTiles) ((INetworkPipe) inputTile).getTileNetwork()).connctedFluidHandlers.entrySet())
{
if (entry.getKey() instanceof IDrain)
{
count++;
}
}
return "Drains conencted to input : " + count;
}
}
return null;
}
}

View file

@ -73,9 +73,9 @@ public class BlockTank extends BlockFluidNetwork
public int getComparatorInputOverride(World world, int x, int y, int z, int par5)
{
TileTank tileEntity = (TileTank) world.getBlockTileEntity(x, y, z);
if (tileEntity != null && tileEntity.getTileNetwork().getNetworkTankInfo().fluid != null)
if (tileEntity != null && tileEntity.getNetwork().getTank().getFluid() != null)
{
return 15 * (tileEntity.getTileNetwork().getNetworkTankInfo().fluid.amount / tileEntity.getTileNetwork().getNetworkTankInfo().capacity);
return 15 * (tileEntity.getNetwork().getTank().getFluidAmount() / tileEntity.getNetwork().getTank().getCapacity());
}
return 0;
}

View file

@ -27,7 +27,7 @@ public class RenderTank extends TileEntitySpecialRenderer
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8)
{
FluidStack liquid = tileEntity instanceof TileTank ? ((TileTank) tileEntity).getTankInfo()[0].fluid : null;
FluidStack liquid = tileEntity instanceof TileTank ? ((TileTank) tileEntity).getTank().getFluid(): null;
this.renderTank(tileEntity, x, y, z, 0, liquid);
}
@ -54,7 +54,7 @@ public class RenderTank extends TileEntitySpecialRenderer
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glScalef(1.01F, 1.01F, 1.01F);
int cap = tileEntity instanceof TileTank ? ((TileTank) tileEntity).getTankInfo()[0].capacity : liquid.amount;
int cap = tileEntity instanceof TileTank ? ((TileTank) tileEntity).getTank().getCapacity() : liquid.amount;
GL11.glCallList(displayList[(int) ((float) liquid.amount / (float) (cap) * (RenderFluidHelper.DISPLAY_STAGES - 1))]);
GL11.glPopAttrib();

View file

@ -0,0 +1,19 @@
package resonantinduction.mechanical.fluid.tank;
import resonantinduction.mechanical.fluid.network.FluidNetwork;
/** Network that handles connected tanks
*
* @author DarkGuardsman */
public class TankNetwork extends FluidNetwork
{
public TankNetwork()
{
}
public TankNetwork(TileTank... tanks)
{
super(tanks);
}
}

View file

@ -2,52 +2,50 @@ package resonantinduction.mechanical.fluid.tank;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.api.fluid.INetworkFluidPart;
import resonantinduction.core.tilenetwork.INetworkPart;
import resonantinduction.core.tilenetwork.ITileNetwork;
import resonantinduction.mechanical.fluid.network.NetworkFluidContainers;
import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.api.fluid.IFluidPart;
import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
public class TileTank extends TileFluidNetwork
{
public TileTank()
{
super(BlockTank.tankVolume);
}
public TileTank()
{
super(BlockTank.tankVolume);
}
@Override
public NetworkFluidContainers getTileNetwork()
{
if (!(this.network instanceof NetworkFluidContainers))
{
this.setTileNetwork(new NetworkFluidContainers(this));
}
return (NetworkFluidContainers) this.network;
}
@Override
public TankNetwork getNetwork()
{
if (!(this.network instanceof TankNetwork))
{
this.setNetwork(new TankNetwork(this));
}
return (TankNetwork) this.network;
}
@Override
public void setTileNetwork(ITileNetwork network)
{
if (network instanceof NetworkFluidContainers)
{
this.network = (NetworkFluidContainers) network;
}
}
@Override
public void setNetwork(IFluidNetwork network)
{
if (network instanceof TankNetwork)
{
this.network = (TankNetwork) network;
}
}
@Override
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (!this.worldObj.isRemote)
{
if (tileEntity instanceof TileTank)
{
if (this.canTileConnect(Connection.NETWORK, side.getOpposite()))
{
this.getTileNetwork().mergeNetwork(((INetworkFluidPart) tileEntity).getTileNetwork(), (INetworkPart) tileEntity);
this.setRenderSide(side, true);
connectedBlocks.add(tileEntity);
}
}
}
}
@Override
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (!this.worldObj.isRemote)
{
if (tileEntity instanceof TileTank)
{
if (this.canTileConnect(Connection.NETWORK, side.getOpposite()))
{
this.getNetwork().merge(((IFluidPart) tileEntity).getNetwork());
this.setRenderSide(side, true);
connectedBlocks[side.ordinal()] = tileEntity;
}
}
}
}
}