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

@ -55,10 +55,10 @@ public class ItemBlockFluidContainer extends ItemBlock
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)
if (entity instanceof TileTank && ((TileTank) entity).getTank() != null && ((TileTank) entity).getTank().getFluid() != null)
{
ItemStack itemStack = new ItemStack(Mechanical.blockTank);
FluidStack stack = ((TileTank) entity).getTankInfo()[0].fluid;
FluidStack stack = ((TileTank) entity).getTank().getFluid();
if (itemStack.getTagCompound() == null)
{

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,7 +15,7 @@ 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
@ -62,16 +62,16 @@ public class TilePipe extends TileFluidNetwork implements IColorCoded, INetworkP
// Same pipe types can connect
if (pipeMat == pipeMatOther)
{
this.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
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.getTileNetwork().mergeNetwork(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
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)
@ -80,102 +80,42 @@ public class TilePipe extends TileFluidNetwork implements IColorCoded, INetworkP
* 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);
this.getNetwork().merge(((IFluidPipe) tileEntity).getNetwork());
connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true);
}
}
}
else if (tileEntity instanceof IFluidHandler)
{
connectedBlocks.add(tileEntity);
connectedBlocks[side.ordinal()] = 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);
connectedBlocks[side.ordinal()] = tileEntity;
setRenderSide(side, true);
}
}
@Override
public double getMaxPressure(ForgeDirection side)
public PipeNetwork getNetwork()
{
int meta = this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if (meta < FluidContainerMaterial.values().length)
if (!(this.network instanceof PipeNetwork))
{
return FluidContainerMaterial.values()[meta].maxPressure;
this.setNetwork(new PipeNetwork(this));
}
return 350;
return (PipeNetwork) this.network;
}
@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
public void setTileNetwork(ITileNetwork network)
{
if (network instanceof NetworkPipes)
{
this.network = (NetworkPipes) network;
}
}
@Override
public int getMaxFlowRate(FluidStack stack, ForgeDirection side)
{
if (stack != null)
{
return this.calculateFlowRate(stack, 40, 20);
}
return BlockPipe.waterFlowRate;
}
/**
* 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 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
@ -192,4 +132,31 @@ public class TilePipe extends TileFluidNetwork implements IColorCoded, INetworkP
{
return false;
}
@Override
public int getPressureIn(ForgeDirection side)
{
return this.getMaxPressure();
}
@Override
public void onWrongPressure(ForgeDirection side, int pressure)
{
// TODO Auto-generated method stub
}
@Override
public int getMaxPressure()
{
// TODO Auto-generated method stub
return 0;
}
@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,18 +30,18 @@ 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 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 NetworkFluidTiles network;
protected IFluidNetwork network;
public static final int PACKET_DESCRIPTION = Mechanical.contentRegistry.getNextPacketID();
public static final int PACKET_RENDER = Mechanical.contentRegistry.getNextPacketID();
@ -113,16 +109,16 @@ public abstract class TileFluidNetwork extends TileEntityFluidDevice implements
@Override
public void invalidate()
{
this.getTileNetwork().splitNetwork(this);
this.getNetwork().split(this);
super.invalidate();
}
@Override
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;
}
@ -130,13 +126,9 @@ public abstract class TileFluidNetwork extends TileEntityFluidDevice implements
@Override
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.getTileNetwork().drainNetworkTank(this.worldObj, resource.amount, doDrain);
}
return this.getNetwork().drain(this, from, resource, doDrain);
}
return null;
}
@ -144,9 +136,9 @@ public abstract class TileFluidNetwork extends TileEntityFluidDevice implements
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
if (this.getTileNetwork() != null)
if (this.getNetwork() != null)
{
return this.getTileNetwork().drainNetworkTank(this.worldObj, maxDrain, doDrain);
return this.getNetwork().drain(this, from, maxDrain, doDrain);
}
return null;
}
@ -166,22 +158,21 @@ public abstract class TileFluidNetwork extends TileEntityFluidDevice implements
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return new FluidTankInfo[] { this.getTileNetwork().getNetworkTankInfo() };
return this.getNetwork().getTankInfo();
}
@Override
public List<TileEntity> getNetworkConnections()
public Object[] getConnections()
{
return this.connectedBlocks;
}
@Override
public void refresh()
{
if (this.worldObj != null && !this.worldObj.isRemote)
{
byte previousConnections = renderSides;
this.connectedBlocks.clear();
this.connectedBlocks = new Object[6];
this.renderSides = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
@ -198,23 +189,21 @@ public abstract class TileFluidNetwork extends TileEntityFluidDevice implements
}
/**
* Checks to make sure the connection is valid to the tileEntity
/** Checks to make sure the connection is valid to the tileEntity
*
* @param tileEntity - the tileEntity being checked
* @param side - side the connection is too
*/
* @param side - side the connection is too */
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (!this.worldObj.isRemote)
{
if (tileEntity instanceof INetworkFluidPart)
if (tileEntity instanceof IFluidPart)
{
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);
connectedBlocks.add(tileEntity);
connectedBlocks[side.ordinal()] = tileEntity;
}
}
}
@ -239,65 +228,19 @@ public abstract class TileFluidNetwork extends TileEntityFluidDevice implements
}
@Override
public NetworkFluidTiles getTileNetwork()
public IFluidNetwork getNetwork()
{
if (!(this.network instanceof NetworkFluidTiles))
if (this.network != null)
{
this.network = new NetworkFluidTiles(this);
this.network = new FluidNetwork(this);
}
return this.network;
}
@Override
public void setTileNetwork(ITileNetwork fluidNetwork)
public void setNetwork(IFluidNetwork fluidNetwork)
{
if (fluidNetwork instanceof NetworkFluidTiles)
{
this.network = (NetworkFluidTiles) fluidNetwork;
}
}
@Override
public FluidTankInfo[] getTankInfo()
{
if (this.internalTanksInfo == null)
{
this.internalTanksInfo = new FluidTankInfo[] { this.getTank().getInfo() };
}
return this.internalTanksInfo;
}
@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 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;
this.network = fluidNetwork;
}
@Override
@ -407,7 +350,7 @@ public abstract class TileFluidNetwork extends TileEntityFluidDevice implements
{
if (tool == EnumTools.PIPE_GUAGE)
{
return "Volume: " + this.getTileNetwork().getNetworkTank().getFluidAmount();
return "Volume: " + this.getNetwork().getTank().getFluidAmount();
}
return null;
}
@ -434,4 +377,16 @@ public abstract class TileFluidNetwork extends TileEntityFluidDevice implements
return (renderSides & (1 << direction.ordinal())) != 0;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
@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,10 +2,8 @@ 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
@ -16,21 +14,21 @@ public class TileTank extends TileFluidNetwork
}
@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
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;
}
}
@ -43,9 +41,9 @@ public class TileTank extends TileFluidNetwork
{
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);
connectedBlocks.add(tileEntity);
connectedBlocks[side.ordinal()] = tileEntity;
}
}
}