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 */ * @return FluidStack that contains the fluid drained from the network */
FluidStack drain(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doDrain); 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 */ /** Fluid tank that represents the entire network */
FluidTank getTank(); 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.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -13,7 +12,8 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; 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.fluid.prefab.BlockFluidNetwork;
import resonantinduction.mechanical.render.MechanicalBlockRenderingHandler; import resonantinduction.mechanical.render.MechanicalBlockRenderingHandler;
import universalelectricity.api.vector.Vector3; import universalelectricity.api.vector.Vector3;
@ -128,10 +128,10 @@ public class BlockPipe extends BlockFluidNetwork
TileEntity entity = world.getBlockTileEntity(x, y, z); TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TilePipe) if (entity instanceof TilePipe)
{ {
FluidTankInfo tank = ((TilePipe) entity).getTankInfo()[0]; FluidTank tank = ((TilePipe) entity).getTank();
if (tank != null && tank.fluid != null && tank.fluid.getFluid() != null && tank.fluid.amount > 0) 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); 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 class ItemBlockFluidContainer extends ItemBlock
{ {
public ItemBlockFluidContainer(int id) public ItemBlockFluidContainer(int id)
{ {
super(id); super(id);
this.setMaxDamage(0); this.setMaxDamage(0);
this.setHasSubtypes(true); this.setHasSubtypes(true);
} }
@Override @Override
public int getMetadata(int damage) public int getMetadata(int damage)
{ {
return damage; return damage;
} }
@Override @Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
{ {
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid")) if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{ {
FluidStack fluid = FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid")); FluidStack fluid = FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid"));
if (fluid != null) if (fluid != null)
{ {
list.add("Fluid: " + fluid.getFluid().getLocalizedName()); list.add("Fluid: " + fluid.getFluid().getLocalizedName());
list.add("Volume: " + UnitDisplay.getDisplay(fluid.amount, Unit.LITER, UnitPrefix.MILLI)); list.add("Volume: " + UnitDisplay.getDisplay(fluid.amount, Unit.LITER, UnitPrefix.MILLI));
} }
} }
} }
public static ItemStack getWrenchedItem(World world, Vector3 vec) public static ItemStack getWrenchedItem(World world, Vector3 vec)
{ {
TileEntity entity = vec.getTileEntity(world); TileEntity entity = vec.getTileEntity(world);
if (entity instanceof TileTank && ((TileTank) entity).getTankInfo() != null && ((TileTank) entity).getTankInfo()[0] != null) if (entity instanceof TileTank && ((TileTank) entity).getTank() != null && ((TileTank) entity).getTank().getFluid() != null)
{ {
ItemStack itemStack = new ItemStack(Mechanical.blockTank); ItemStack itemStack = new ItemStack(Mechanical.blockTank);
FluidStack stack = ((TileTank) entity).getTankInfo()[0].fluid; FluidStack stack = ((TileTank) entity).getTank().getFluid();
if (itemStack.getTagCompound() == null) if (itemStack.getTagCompound() == null)
{ {
itemStack.setTagCompound(new NBTTagCompound()); itemStack.setTagCompound(new NBTTagCompound());
} }
if (stack != null) if (stack != null)
{ {
((TileTank) entity).drain(ForgeDirection.UNKNOWN, stack.amount, true); ((TileTank) entity).drain(ForgeDirection.UNKNOWN, stack.amount, true);
itemStack.getTagCompound().setCompoundTag("fluid", stack.writeToNBT(new NBTTagCompound())); itemStack.getTagCompound().setCompoundTag("fluid", stack.writeToNBT(new NBTTagCompound()));
} }
return itemStack; return itemStack;
} }
return null; return null;
} }
@Override @Override
public void onUpdate(ItemStack itemStack, World par2World, Entity entity, int par4, boolean par5) public void onUpdate(ItemStack itemStack, World par2World, Entity entity, int par4, boolean par5)
{ {
if (entity instanceof EntityPlayer) if (entity instanceof EntityPlayer)
{ {
EntityPlayer player = (EntityPlayer) entity; EntityPlayer player = (EntityPlayer) entity;
if (itemStack.getTagCompound() != null && !player.capabilities.isCreativeMode && itemStack.getTagCompound().hasKey("fluid")) if (itemStack.getTagCompound() != null && !player.capabilities.isCreativeMode && itemStack.getTagCompound().hasKey("fluid"))
{ {
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, 0)); player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, 0));
} }
} }
} }
@Override @Override
public int getItemStackLimit(ItemStack stack) public int getItemStackLimit(ItemStack stack)
{ {
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid")) if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{ {
return 1; return 1;
} }
return this.maxStackSize; return this.maxStackSize;
} }
@Override @Override
public String getUnlocalizedName(ItemStack itemStack) public String getUnlocalizedName(ItemStack itemStack)
{ {
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage(); return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage();
} }
@Override @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) 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))) if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, (metadata / FluidContainerMaterial.spacing)))
{ {
TileEntity tile = world.getBlockTileEntity(x, y, z); TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFluidNetwork) if (tile instanceof TileFluidNetwork)
{ {
((TileFluidNetwork) tile).setSubID(stack.getItemDamage()); ((TileFluidNetwork) tile).setSubID(stack.getItemDamage());
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid")) if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{ {
((TileFluidNetwork) tile).fill(ForgeDirection.UNKNOWN, FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid")), true); ((TileFluidNetwork) tile).fill(ForgeDirection.UNKNOWN, FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid")), true);
} }
} }
return true; return true;
} }
return false; 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) if (mat == FluidContainerMaterial.WOOD || mat == FluidContainerMaterial.STONE)
{ {
FluidStack liquid = tile.getTank().getFluid(); FluidStack liquid = tile.getTank().getFluid();
int cap = tile.getTankInfo()[0].capacity; int cap = tile.getTank().getCapacity();
// FluidStack liquid = new FluidStack(FluidRegistry.WATER, cap); // FluidStack liquid = new FluidStack(FluidRegistry.WATER, cap);
if (liquid != null && liquid.amount > 100) 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.Fluid;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler; 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.ITileConnector;
import resonantinduction.core.tilenetwork.ITileNetwork;
import resonantinduction.mechanical.fluid.network.NetworkPipes; import resonantinduction.mechanical.fluid.network.NetworkPipes;
import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork; import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
import universalelectricity.api.vector.Vector3; import universalelectricity.api.vector.Vector3;
@ -15,181 +15,148 @@ import calclavia.lib.utility.FluidHelper;
import dark.lib.helpers.ColorCode; import dark.lib.helpers.ColorCode;
import dark.lib.helpers.ColorCode.IColorCoded; 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 */ /** gets the current color mark of the pipe */
@Override @Override
public ColorCode getColor() public ColorCode getColor()
{ {
return EnumPipeType.getColorCode(this.colorID); return EnumPipeType.getColorCode(this.colorID);
} }
/** sets the current color mark of the pipe */ /** sets the current color mark of the pipe */
@Override @Override
public boolean setColor(Object cc) public boolean setColor(Object cc)
{ {
if (!worldObj.isRemote) if (!worldObj.isRemote)
{ {
int p = this.colorID; int p = this.colorID;
this.colorID = EnumPipeType.getUpdatedID(colorID, ColorCode.get(cc)); this.colorID = EnumPipeType.getUpdatedID(colorID, ColorCode.get(cc));
return p != this.colorID; return p != this.colorID;
} }
return false; return false;
} }
@Override @Override
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side) public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{ {
int meta = new Vector3(this).getBlockMetadata(this.worldObj); int meta = new Vector3(this).getBlockMetadata(this.worldObj);
if (meta < FluidContainerMaterial.values().length) if (meta < FluidContainerMaterial.values().length)
{ {
FluidContainerMaterial pipeMat = FluidContainerMaterial.values()[meta]; FluidContainerMaterial pipeMat = FluidContainerMaterial.values()[meta];
if (pipeMat == FluidContainerMaterial.WOOD || pipeMat == FluidContainerMaterial.STONE) if (pipeMat == FluidContainerMaterial.WOOD || pipeMat == FluidContainerMaterial.STONE)
{ {
if (side == ForgeDirection.UP) if (side == ForgeDirection.UP)
{ {
return; return;
} }
} }
} }
if (tileEntity instanceof TilePipe) if (tileEntity instanceof TilePipe)
{ {
int metaOther = new Vector3(tileEntity).getBlockMetadata(this.worldObj); int metaOther = new Vector3(tileEntity).getBlockMetadata(this.worldObj);
if (meta < FluidContainerMaterial.values().length && metaOther < FluidContainerMaterial.values().length) if (meta < FluidContainerMaterial.values().length && metaOther < FluidContainerMaterial.values().length)
{ {
FluidContainerMaterial pipeMat = FluidContainerMaterial.values()[meta]; FluidContainerMaterial pipeMat = FluidContainerMaterial.values()[meta];
FluidContainerMaterial pipeMatOther = FluidContainerMaterial.values()[metaOther]; FluidContainerMaterial pipeMatOther = FluidContainerMaterial.values()[metaOther];
// Same pipe types can connect // Same pipe types can connect
if (pipeMat == pipeMatOther) if (pipeMat == pipeMatOther)
{ {
this.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this); this.getNetwork().merge(((IFluidPipe) tileEntity).getNetwork());
connectedBlocks.add(tileEntity); connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true); setRenderSide(side, true);
} }
else if ((pipeMat == FluidContainerMaterial.WOOD || pipeMat == FluidContainerMaterial.STONE) && (pipeMatOther == FluidContainerMaterial.WOOD || pipeMatOther == FluidContainerMaterial.STONE)) 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 // Wood and stone pipes can connect to each other but not other pipe types since
// they are more like a trough than a pipe // they are more like a trough than a pipe
this.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this); this.getNetwork().merge(((IFluidPipe) tileEntity).getNetwork());
connectedBlocks.add(tileEntity); connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true); setRenderSide(side, true);
} }
else if (pipeMat != FluidContainerMaterial.WOOD && pipeMat != FluidContainerMaterial.STONE && pipeMatOther != FluidContainerMaterial.WOOD && pipeMatOther != FluidContainerMaterial.STONE && pipeMat != FluidContainerMaterial.GLASS && pipeMatOther != FluidContainerMaterial.GLASS) 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 * 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 * for glass which only works with itself at the moment
*/ */
this.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this); this.getNetwork().merge(((IFluidPipe) tileEntity).getNetwork());
connectedBlocks.add(tileEntity); connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true); setRenderSide(side, true);
} }
} }
} }
else if (tileEntity instanceof IFluidHandler) else if (tileEntity instanceof IFluidHandler)
{ {
connectedBlocks.add(tileEntity); connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true); setRenderSide(side, true);
this.getTileNetwork().addTank(side.getOpposite(), (IFluidHandler) tileEntity); }
} else if (tileEntity instanceof ITileConnector && ((ITileConnector) tileEntity).canTileConnect(Connection.FLUIDS, side.getOpposite()))
else if (tileEntity instanceof ITileConnector && ((ITileConnector) tileEntity).canTileConnect(Connection.FLUIDS, side.getOpposite())) {
{ connectedBlocks[side.ordinal()] = tileEntity;
connectedBlocks.add(tileEntity); setRenderSide(side, true);
setRenderSide(side, true); }
}
} }
@Override @Override
public double getMaxPressure(ForgeDirection side) public PipeNetwork getNetwork()
{ {
int meta = this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord); if (!(this.network instanceof PipeNetwork))
if (meta < FluidContainerMaterial.values().length) {
{ this.setNetwork(new PipeNetwork(this));
return FluidContainerMaterial.values()[meta].maxPressure; }
} return (PipeNetwork) this.network;
return 350; }
}
@Override @Override
public NetworkPipes getTileNetwork() public void setNetwork(IFluidNetwork network)
{ {
if (!(this.network instanceof NetworkPipes)) if (network instanceof PipeNetwork)
{ {
this.setTileNetwork(new NetworkPipes(this)); this.network = (PipeNetwork) network;
} }
return (NetworkPipes) this.network; }
}
@Override @Override
public void setTileNetwork(ITileNetwork network) public void sendTankUpdate(int index)
{ {
if (network instanceof NetworkPipes) if (this.getBlockMetadata() == FluidContainerMaterial.WOOD.ordinal() || this.getBlockMetadata() == FluidContainerMaterial.STONE.ordinal())
{ {
this.network = (NetworkPipes) network; super.sendTankUpdate(index);
} }
} }
@Override @Override
public int getMaxFlowRate(FluidStack stack, ForgeDirection side) public boolean canDrain(ForgeDirection from, Fluid fluid)
{ {
if (stack != null) return false;
{ }
return this.calculateFlowRate(stack, 40, 20);
}
return BlockPipe.waterFlowRate;
}
/** @Override
* Calculates flow rate based on viscosity & temp of the fluid as all other factors are know public int getPressureIn(ForgeDirection side)
* {
* @param fluid - fluidStack return this.getMaxPressure();
* @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 @Override
public boolean onOverPressure(Boolean damageAllowed) public void onWrongPressure(ForgeDirection side, int pressure)
{ {
if (damageAllowed) // TODO Auto-generated method stub
{
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 @Override
public void sendTankUpdate(int index) public int getMaxPressure()
{ {
if (this.getBlockMetadata() == FluidContainerMaterial.WOOD.ordinal() || this.getBlockMetadata() == FluidContainerMaterial.STONE.ordinal()) // TODO Auto-generated method stub
{ return 0;
super.sendTankUpdate(index); }
}
}
@Override @Override
public boolean canDrain(ForgeDirection from, Fluid fluid) public int getMaxFlowRate()
{ {
return false; // TODO Auto-generated method stub
} return 0;
}
} }

View file

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

View file

@ -1,11 +1,8 @@
package resonantinduction.mechanical.fluid.pump; package resonantinduction.mechanical.fluid.pump;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -15,11 +12,10 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.IReadOut.EnumTools;
import resonantinduction.api.fluid.IDrain; import resonantinduction.api.fluid.IDrain;
import resonantinduction.api.fluid.INetworkPipe; import resonantinduction.api.fluid.IFluidPipe;
import resonantinduction.core.tilenetwork.ITileConnector; 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.Vector3;
import universalelectricity.api.vector.VectorHelper; import universalelectricity.api.vector.VectorHelper;
@ -87,16 +83,16 @@ public class TileConstructionPump extends TilePump implements IFluidHandler, ITi
ignoreList = new ArrayList<IDrain>(); 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) 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; break;
} }
} }
@ -170,26 +166,4 @@ public class TileConstructionPump extends TilePump implements IFluidHandler, ITi
super.invalidate(); 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) public int getComparatorInputOverride(World world, int x, int y, int z, int par5)
{ {
TileTank tileEntity = (TileTank) world.getBlockTileEntity(x, y, z); 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; return 0;
} }

View file

@ -27,7 +27,7 @@ public class RenderTank extends TileEntitySpecialRenderer
@Override @Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8) 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); 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.glTranslatef((float) x, (float) y, (float) z);
GL11.glScalef(1.01F, 1.01F, 1.01F); 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.glCallList(displayList[(int) ((float) liquid.amount / (float) (cap) * (RenderFluidHelper.DISPLAY_STAGES - 1))]);
GL11.glPopAttrib(); 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.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import resonantinduction.api.fluid.INetworkFluidPart; import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.core.tilenetwork.INetworkPart; import resonantinduction.api.fluid.IFluidPart;
import resonantinduction.core.tilenetwork.ITileNetwork;
import resonantinduction.mechanical.fluid.network.NetworkFluidContainers;
import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork; import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
public class TileTank extends TileFluidNetwork public class TileTank extends TileFluidNetwork
{ {
public TileTank() public TileTank()
{ {
super(BlockTank.tankVolume); super(BlockTank.tankVolume);
} }
@Override @Override
public NetworkFluidContainers getTileNetwork() public TankNetwork getNetwork()
{ {
if (!(this.network instanceof NetworkFluidContainers)) if (!(this.network instanceof TankNetwork))
{ {
this.setTileNetwork(new NetworkFluidContainers(this)); this.setNetwork(new TankNetwork(this));
} }
return (NetworkFluidContainers) this.network; return (TankNetwork) this.network;
} }
@Override @Override
public void setTileNetwork(ITileNetwork network) public void setNetwork(IFluidNetwork network)
{ {
if (network instanceof NetworkFluidContainers) if (network instanceof TankNetwork)
{ {
this.network = (NetworkFluidContainers) network; this.network = (TankNetwork) network;
} }
} }
@Override @Override
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side) public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{ {
if (!this.worldObj.isRemote) if (!this.worldObj.isRemote)
{ {
if (tileEntity instanceof TileTank) if (tileEntity instanceof TileTank)
{ {
if (this.canTileConnect(Connection.NETWORK, side.getOpposite())) if (this.canTileConnect(Connection.NETWORK, side.getOpposite()))
{ {
this.getTileNetwork().mergeNetwork(((INetworkFluidPart) tileEntity).getTileNetwork(), (INetworkPart) tileEntity); this.getNetwork().merge(((IFluidPart) tileEntity).getNetwork());
this.setRenderSide(side, true); this.setRenderSide(side, true);
connectedBlocks.add(tileEntity); connectedBlocks[side.ordinal()] = tileEntity;
} }
} }
} }
} }
} }