Cleared out errors but pipes & tanks don't work just yet
This commit is contained in:
parent
329429ae3b
commit
c5335008ec
5 changed files with 87 additions and 663 deletions
|
@ -9,105 +9,102 @@ import net.minecraftforge.fluids.IFluidHandler;
|
|||
import resonantinduction.api.IReadOut;
|
||||
import resonantinduction.api.fluid.IFluidPipe;
|
||||
import resonantinduction.core.tilenetwork.ITileConnector;
|
||||
import resonantinduction.mechanical.fluid.network.NetworkPipes;
|
||||
import resonantinduction.mechanical.fluid.prefab.TileEntityFluidDevice;
|
||||
import calclavia.lib.utility.HelperMethods;
|
||||
|
||||
public class TileReleaseValve extends TileEntityFluidDevice implements ITileConnector, IReadOut
|
||||
{
|
||||
public TileEntity[] connected = new TileEntity[6];
|
||||
public TileEntity[] connected = new TileEntity[6];
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (this.ticks % 10 == 0)
|
||||
{
|
||||
this.refresh();
|
||||
if (!this.worldObj.isRemote && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
|
||||
{
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (connected[dir.ordinal()] instanceof IFluidHandler && !(connected[dir.ordinal()] instanceof IFluidPipe))
|
||||
{
|
||||
IFluidHandler drainedTank = (IFluidHandler) connected[dir.ordinal()];
|
||||
FluidStack stack = drainedTank.drain(dir.getOpposite(), FluidContainerRegistry.BUCKET_VOLUME, false);
|
||||
if (stack != null && stack.amount > 0)
|
||||
{
|
||||
IFluidPipe inputPipe = this.findValidPipe(stack);
|
||||
if (inputPipe != null)
|
||||
{
|
||||
int ammountFilled = ((NetworkPipes) inputPipe.getNetwork()).addFluidToNetwork((TileEntity) drainedTank, stack, true);
|
||||
drainedTank.drain(dir.getOpposite(), ammountFilled, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.ticks % 10 == 0)
|
||||
{
|
||||
this.refresh();
|
||||
if (!this.worldObj.isRemote && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
|
||||
{
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (connected[dir.ordinal()] instanceof IFluidHandler && !(connected[dir.ordinal()] instanceof IFluidPipe))
|
||||
{
|
||||
IFluidHandler drainedTank = (IFluidHandler) connected[dir.ordinal()];
|
||||
FluidStack stack = drainedTank.drain(dir.getOpposite(), FluidContainerRegistry.BUCKET_VOLUME, false);
|
||||
if (stack != null && stack.amount > 0)
|
||||
{
|
||||
IFluidPipe inputPipe = this.findValidPipe(stack);
|
||||
if (inputPipe != null)
|
||||
{
|
||||
int ammountFilled = inputPipe.getNetwork().fill(inputPipe, dir, stack, true);
|
||||
drainedTank.drain(dir.getOpposite(), ammountFilled, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** used to find a valid pipe for filling of the liquid type */
|
||||
public IFluidPipe findValidPipe(FluidStack stack)
|
||||
{
|
||||
// find normal color selective pipe first
|
||||
for (int i = 0; i < connected.length; i++)
|
||||
{
|
||||
TileEntity tile = connected[i];
|
||||
if (tile instanceof IFluidPipe && ((IFluidPipe) tile).fill(ForgeDirection.getOrientation(i), stack, false) > 0)
|
||||
{
|
||||
return (IFluidPipe) tile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/** used to find a valid pipe for filling of the liquid type */
|
||||
public IFluidPipe findValidPipe(FluidStack stack)
|
||||
{
|
||||
// find normal color selective pipe first
|
||||
for (int i = 0; i < connected.length; i++)
|
||||
{
|
||||
TileEntity tile = connected[i];
|
||||
if (tile instanceof IFluidPipe && ((IFluidPipe) tile).fill(ForgeDirection.getOrientation(i), stack, false) > 0)
|
||||
{
|
||||
return (IFluidPipe) tile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects info about the surrounding 6 tiles and orders them into drain-able(ITankContainer)
|
||||
* and fill-able(TileEntityPipes) instances
|
||||
*/
|
||||
public void refresh()
|
||||
{
|
||||
// cleanup
|
||||
this.connected = HelperMethods.getSurroundingTileEntities(this);
|
||||
// read surroundings
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tileEntity = connected[dir.ordinal()];
|
||||
if (tileEntity instanceof ITileConnector)
|
||||
{
|
||||
if (this.canTileConnect(Connection.FLUIDS, dir.getOpposite()))
|
||||
{
|
||||
this.connected[dir.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof IFluidHandler)
|
||||
{
|
||||
this.connected[dir.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Collects info about the surrounding 6 tiles and orders them into drain-able(ITankContainer)
|
||||
* and fill-able(TileEntityPipes) instances */
|
||||
public void refresh()
|
||||
{
|
||||
// cleanup
|
||||
this.connected = HelperMethods.getSurroundingTileEntities(this);
|
||||
// read surroundings
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tileEntity = connected[dir.ordinal()];
|
||||
if (tileEntity instanceof ITileConnector)
|
||||
{
|
||||
if (this.canTileConnect(Connection.FLUIDS, dir.getOpposite()))
|
||||
{
|
||||
this.connected[dir.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof IFluidHandler)
|
||||
{
|
||||
this.connected[dir.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTileConnect(Connection type, ForgeDirection dir)
|
||||
{
|
||||
return type == Connection.FLUIDS;
|
||||
}
|
||||
@Override
|
||||
public boolean canTileConnect(Connection type, ForgeDirection dir)
|
||||
{
|
||||
return type == Connection.FLUIDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
|
||||
{
|
||||
// TODO maybe debug on # of connected units of input/output
|
||||
String output = "";
|
||||
if (!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
|
||||
{
|
||||
output += "Open";
|
||||
}
|
||||
else
|
||||
{
|
||||
output += "Closed";
|
||||
}
|
||||
return output;
|
||||
}
|
||||
@Override
|
||||
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
|
||||
{
|
||||
// TODO maybe debug on # of connected units of input/output
|
||||
String output = "";
|
||||
if (!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
|
||||
{
|
||||
output += "Open";
|
||||
}
|
||||
else
|
||||
{
|
||||
output += "Closed";
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
package resonantinduction.mechanical.fluid.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import resonantinduction.api.fluid.INetworkFluidPart;
|
||||
import resonantinduction.core.tilenetwork.INetworkPart;
|
||||
import resonantinduction.core.tilenetwork.prefab.NetworkUpdateHandler;
|
||||
import calclavia.lib.utility.FluidHelper;
|
||||
|
||||
/**
|
||||
* Basically the same as network Fluid tiles class with the only difference being in how it stores
|
||||
* the fluid. When it goes to sort the fluid it will use the fluid properties to adjust its position
|
||||
* in the over all tank. Eg water goes down air goes up.
|
||||
*
|
||||
* @author DarkGuardsman
|
||||
*/
|
||||
public class NetworkFluidContainers extends NetworkFluidTiles
|
||||
{
|
||||
static
|
||||
{
|
||||
NetworkUpdateHandler.registerNetworkClass("FluidContainers", NetworkFluidContainers.class);
|
||||
}
|
||||
|
||||
public NetworkFluidContainers()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public NetworkFluidContainers(INetworkPart... parts)
|
||||
{
|
||||
super(parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
this.cleanUpMembers();
|
||||
|
||||
if (this.getNetworkTank() == null || this.getNetworkTank().getFluid() == null)
|
||||
{
|
||||
super.save();
|
||||
return;
|
||||
}
|
||||
FluidStack fillStack = this.getNetworkTank().getFluid().copy();
|
||||
|
||||
int lowestY = 255, highestY = 0;
|
||||
|
||||
if (this.getNetworkTank().getFluid() != null && this.getMembers().size() > 0)
|
||||
{
|
||||
for (INetworkPart part : this.getMembers())
|
||||
{
|
||||
if (part instanceof IFluidHandler)
|
||||
{
|
||||
((INetworkFluidPart) part).drainTankContent(0, Integer.MAX_VALUE, true);
|
||||
}
|
||||
if (part instanceof TileEntity && ((TileEntity) part).yCoord < lowestY)
|
||||
{
|
||||
lowestY = ((TileEntity) part).yCoord;
|
||||
}
|
||||
if (part instanceof TileEntity && ((TileEntity) part).yCoord > highestY)
|
||||
{
|
||||
highestY = ((TileEntity) part).yCoord;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO change this to use hydraulics to not only place fluid at the lowest but as well
|
||||
// not move it to another side if there is no path there threw fluid
|
||||
for (int y = lowestY; y <= highestY; y++)
|
||||
{
|
||||
/** List of parts for this Y level */
|
||||
List<INetworkFluidPart> parts = new ArrayList<INetworkFluidPart>();
|
||||
|
||||
/* Grab all parts that share this Y level */
|
||||
for (INetworkPart part : this.getMembers())
|
||||
{
|
||||
if (part instanceof INetworkFluidPart && ((TileEntity) part).yCoord == y)
|
||||
{
|
||||
parts.add((INetworkFluidPart) part);
|
||||
}
|
||||
}
|
||||
if (!parts.isEmpty())
|
||||
{
|
||||
/*
|
||||
* Div out the volume for this level. TODO change this to use a percent system
|
||||
* for even filling
|
||||
*/
|
||||
int fillvolume = Math.abs(fillStack.amount / parts.size());
|
||||
|
||||
/* Fill all tanks on this level */
|
||||
for (INetworkFluidPart part : parts)
|
||||
{
|
||||
part.drainTankContent(0, Integer.MAX_VALUE, true);
|
||||
fillStack.amount -= part.fillTankContent(0, FluidHelper.getStack(fillStack, fillvolume), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (fillStack == null || fillStack.amount <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,317 +0,0 @@
|
|||
package resonantinduction.mechanical.fluid.network;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import resonantinduction.api.fluid.INetworkFluidPart;
|
||||
import resonantinduction.core.tilenetwork.INetworkPart;
|
||||
import resonantinduction.core.tilenetwork.ITileNetwork;
|
||||
import resonantinduction.core.tilenetwork.prefab.NetworkTileEntities;
|
||||
import resonantinduction.core.tilenetwork.prefab.NetworkUpdateHandler;
|
||||
import resonantinduction.mechanical.fluid.FluidCraftingHandler;
|
||||
import calclavia.lib.utility.FluidHelper;
|
||||
|
||||
public class NetworkFluidTiles extends NetworkTileEntities
|
||||
{
|
||||
/** Fluid Tanks that are connected to the network but not part of the network's main body */
|
||||
public HashMap<IFluidHandler, EnumSet<ForgeDirection>> connctedFluidHandlers = new HashMap<IFluidHandler, EnumSet<ForgeDirection>>();
|
||||
/** Collective storage tank of all fluid tile that make up this networks main body */
|
||||
protected FluidTank sharedTank;
|
||||
protected FluidTankInfo sharedTankInfo;
|
||||
|
||||
/** Has the collective tank been loaded yet */
|
||||
protected boolean loadedLiquids = false;
|
||||
|
||||
static
|
||||
{
|
||||
NetworkUpdateHandler.registerNetworkClass("FluidTiles", NetworkFluidTiles.class);
|
||||
}
|
||||
|
||||
public NetworkFluidTiles()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public NetworkFluidTiles(INetworkPart... parts)
|
||||
{
|
||||
super(parts);
|
||||
}
|
||||
|
||||
/** Gets the collective tank of the network */
|
||||
public FluidTank getNetworkTank()
|
||||
{
|
||||
if (this.sharedTank == null)
|
||||
{
|
||||
this.sharedTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
||||
this.getNetworkTankInfo();
|
||||
}
|
||||
return this.sharedTank;
|
||||
}
|
||||
|
||||
public FluidTankInfo getNetworkTankInfo()
|
||||
{
|
||||
if (this.sharedTankInfo == null)
|
||||
{
|
||||
this.sharedTankInfo = this.getNetworkTank().getInfo();
|
||||
}
|
||||
return this.sharedTankInfo;
|
||||
}
|
||||
|
||||
public int fillNetworkTank(TileEntity source, FluidStack stack, boolean doFill)
|
||||
{
|
||||
if (!this.loadedLiquids)
|
||||
{
|
||||
this.load();
|
||||
this.loadedLiquids = true;
|
||||
}
|
||||
if (!source.worldObj.isRemote && this.getNetworkTank() != null && stack != null)
|
||||
{
|
||||
int p = this.getNetworkTank().getFluidAmount();
|
||||
int r = this.getNetworkTank().fill(stack, doFill);
|
||||
// System.out.println((world.isRemote ? "Client" : "Server") + " Network Fill: B:" + p +
|
||||
// " A:" + this.getNetworkTank().getFluidAmount());
|
||||
if (doFill)
|
||||
{
|
||||
if (p != this.getNetworkTank().getFluidAmount())
|
||||
{
|
||||
this.sharedTankInfo = this.getNetworkTank().getInfo();
|
||||
this.save();
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public FluidStack drainNetworkTank(World world, int volume, boolean doDrain)
|
||||
{
|
||||
|
||||
if (!this.loadedLiquids)
|
||||
{
|
||||
this.load();
|
||||
this.loadedLiquids = true;
|
||||
}
|
||||
FluidStack before = this.getNetworkTank().getFluid();
|
||||
if (!world.isRemote && this.getNetworkTank() != null && before != null)
|
||||
{
|
||||
FluidStack drain = this.getNetworkTank().drain(volume, doDrain);
|
||||
FluidStack after = this.getNetworkTank().getFluid();
|
||||
// System.out.println((doDrain ? "" : "Fake") + " Network Drain for " + volume + " B:" +
|
||||
// (before != null ? before.amount : 0) + " A:" + (after != null ? after.amount : 0) +
|
||||
// " D:" + (drain != null ? drain.amount : 0));
|
||||
if (doDrain)
|
||||
{
|
||||
// Has the tank changed any. If yes then update all info and do a client update
|
||||
if (!before.isFluidEqual(after) || (before != null && after != null && before.amount != after.amount))
|
||||
{
|
||||
this.sharedTankInfo = this.getNetworkTank().getInfo();
|
||||
this.save();
|
||||
/*
|
||||
* TODO do a client update from the network rather than each pipe updating
|
||||
* itself.
|
||||
* This will save on packet size but will increase the CPU load of the client
|
||||
* since the client
|
||||
* will need to do network calculations
|
||||
*/
|
||||
}
|
||||
}
|
||||
return drain;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
this.cleanUpMembers();
|
||||
if (this.getNetworkTank().getFluid() != null && this.getMembers().size() > 0)
|
||||
{
|
||||
FluidStack stack = this.getNetworkTank().getFluid() == null ? null : this.getNetworkTank().getFluid().copy();
|
||||
int membersFilled = 0;
|
||||
|
||||
for (INetworkPart par : this.getMembers())
|
||||
{
|
||||
// UPDATE FILL VOLUME
|
||||
int fillVol = stack == null ? 0 : (stack.amount / (this.getMembers().size() - membersFilled));
|
||||
|
||||
if (par instanceof INetworkFluidPart)
|
||||
{
|
||||
// EMPTY TANK
|
||||
((INetworkFluidPart) par).drainTankContent(0, Integer.MAX_VALUE, true);
|
||||
// FILL TANK
|
||||
if (stack != null)
|
||||
{
|
||||
stack.amount -= ((INetworkFluidPart) par).fillTankContent(0, FluidHelper.getStack(stack, fillVol), true);
|
||||
membersFilled++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
FluidStack stack = null;
|
||||
this.cleanUpMembers();
|
||||
for (INetworkPart par : this.getMembers())
|
||||
{
|
||||
if (par instanceof INetworkFluidPart)
|
||||
{
|
||||
if (((INetworkFluidPart) par).getTankInfo()[0] != null && ((INetworkFluidPart) par).getTankInfo()[0].fluid != null)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
stack = ((INetworkFluidPart) par).getTankInfo()[0].fluid.copy();
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.amount += ((INetworkFluidPart) par).getTankInfo()[0].fluid.amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stack != null && stack.amount > 0)
|
||||
{
|
||||
this.getNetworkTank().setFluid(stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getNetworkTank().setFluid(null);
|
||||
}
|
||||
this.loadedLiquids = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeTile(TileEntity ent)
|
||||
{
|
||||
return super.removeTile(ent) || this.connctedFluidHandlers.remove(ent) != null;
|
||||
}
|
||||
|
||||
/** Checks too see if the tileEntity is part of or connected too the network */
|
||||
public boolean isConnected(TileEntity tileEntity)
|
||||
{
|
||||
return this.connctedFluidHandlers.containsKey(tileEntity);
|
||||
}
|
||||
|
||||
public void addTank(ForgeDirection side, IFluidHandler tank)
|
||||
{
|
||||
if (this.connctedFluidHandlers.containsKey(tank))
|
||||
{
|
||||
EnumSet<ForgeDirection> d = this.connctedFluidHandlers.get(tank);
|
||||
d.add(side);
|
||||
this.connctedFluidHandlers.put(tank, d);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnumSet<ForgeDirection> d = EnumSet.noneOf(ForgeDirection.class);
|
||||
d.add(side);
|
||||
this.connctedFluidHandlers.put(tank, d);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preMergeProcessing(ITileNetwork mergingNetwork, INetworkPart mergePoint)
|
||||
{
|
||||
if (mergingNetwork instanceof NetworkFluidTiles)
|
||||
{
|
||||
if (!((NetworkFluidTiles) mergingNetwork).loadedLiquids)
|
||||
{
|
||||
((NetworkFluidTiles) mergingNetwork).load();
|
||||
}
|
||||
if (!this.loadedLiquids)
|
||||
{
|
||||
this.load();
|
||||
}
|
||||
}
|
||||
return super.preMergeProcessing(mergingNetwork, mergePoint);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mergeDo(ITileNetwork network)
|
||||
{
|
||||
ITileNetwork newNetwork = NetworkUpdateHandler.createNewNetwork(NetworkUpdateHandler.getID(this.getClass()));
|
||||
if (newNetwork != null)
|
||||
{
|
||||
if (newNetwork instanceof NetworkFluidTiles)
|
||||
{
|
||||
FluidStack one = this.getNetworkTank().getFluid();
|
||||
FluidStack two = ((NetworkFluidTiles) network).getNetworkTank().getFluid();
|
||||
|
||||
this.getNetworkTank().setFluid(null);
|
||||
((NetworkFluidTiles) network).getNetworkTank().setFluid(null);
|
||||
|
||||
((NetworkFluidTiles) newNetwork).getNetworkTank().setFluid(FluidCraftingHandler.mergeFluidStacks(one, two));
|
||||
((NetworkFluidTiles) newNetwork).sharedTankInfo = ((NetworkFluidTiles) newNetwork).getNetworkTank().getInfo();
|
||||
}
|
||||
newNetwork.getMembers().addAll(this.getMembers());
|
||||
newNetwork.getMembers().addAll(network.getMembers());
|
||||
newNetwork.onCreated();
|
||||
newNetwork.save();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("[NetworkFluidTiles] Failed to merge network due to the new network returned null");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUpMembers()
|
||||
{
|
||||
Iterator<INetworkPart> it = this.getMembers().iterator();
|
||||
int capacity = 0;
|
||||
while (it.hasNext())
|
||||
{
|
||||
INetworkPart part = it.next();
|
||||
if (!this.isValidMember(part))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
part.setTileNetwork(this);
|
||||
if (part instanceof INetworkFluidPart && ((INetworkFluidPart) part).getTankInfo()[0] != null)
|
||||
{
|
||||
capacity += ((INetworkFluidPart) part).getTankInfo()[0].capacity;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.getNetworkTank().setCapacity(capacity);
|
||||
this.sharedTankInfo = this.getNetworkTank().getInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidMember(INetworkPart part)
|
||||
{
|
||||
return super.isValidMember(part) && part instanceof INetworkFluidPart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "FluidNetwork[" + this.hashCode() + "|parts:" + this.getMembers().size() + "]";
|
||||
}
|
||||
|
||||
public String getNetworkFluid()
|
||||
{
|
||||
if (this.getNetworkTank() != null && this.getNetworkTank().getFluid() != null && this.getNetworkTank().getFluid().getFluid() != null)
|
||||
{
|
||||
int cap = this.getNetworkTank().getCapacity() / FluidContainerRegistry.BUCKET_VOLUME;
|
||||
int vol = this.getNetworkTank().getFluid() != null ? (this.getNetworkTank().getFluid().amount / FluidContainerRegistry.BUCKET_VOLUME) : 0;
|
||||
String name = this.getNetworkTank().getFluid().getFluid().getLocalizedName();
|
||||
return String.format("%d/%d %S Stored", vol, cap, name);
|
||||
}
|
||||
return ("Empty");
|
||||
}
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
package resonantinduction.mechanical.fluid.network;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import resonantinduction.api.fluid.INetworkPipe;
|
||||
import resonantinduction.core.tilenetwork.INetworkPart;
|
||||
import resonantinduction.core.tilenetwork.prefab.NetworkUpdateHandler;
|
||||
import calclavia.lib.utility.FluidHelper;
|
||||
|
||||
/**
|
||||
* Extension on the fluid container network to provide a more advanced reaction to fluid passing
|
||||
* threw each pipe. As well this doubled as a pressure network for those machines that support the
|
||||
* use of pressure.
|
||||
*
|
||||
* @author Rseifert
|
||||
*/
|
||||
public class NetworkPipes extends NetworkFluidTiles
|
||||
{
|
||||
private boolean processingRequest;
|
||||
public float pressureProduced;
|
||||
|
||||
static
|
||||
{
|
||||
NetworkUpdateHandler.registerNetworkClass("FluidPipes", NetworkPipes.class);
|
||||
}
|
||||
|
||||
public NetworkPipes()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public NetworkPipes(INetworkPart... parts)
|
||||
{
|
||||
super(parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fillNetworkTank(TileEntity source, FluidStack stack, boolean doFill)
|
||||
{
|
||||
int netFill = this.addFluidToNetwork(source, stack, doFill);
|
||||
if (netFill > 0)
|
||||
{
|
||||
return netFill;
|
||||
}
|
||||
return super.fillNetworkTank(source, stack, doFill);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds FLuid to this network from one of the connected Pipes
|
||||
*
|
||||
* @param source - Were this liquid came from
|
||||
* @param stack - LiquidStack to be sent
|
||||
* @param doFill - actually fill the tank or just check numbers
|
||||
* @return the amount of liquid consumed from the init stack
|
||||
*/
|
||||
public int addFluidToNetwork(TileEntity source, FluidStack stack, boolean doFill)
|
||||
{
|
||||
return this.addFluidToNetwork(source, stack, doFill, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds FLuid to this network from one of the connected Pipes
|
||||
*
|
||||
* @param source - Were this liquid came from
|
||||
* @param stack - LiquidStack to be sent
|
||||
* @param doFill - actually fill the tank or just check numbers
|
||||
* @param allowStore - allows the network to store this liquid in the pipes
|
||||
* @return the amount of liquid consumed from the init stack
|
||||
*/
|
||||
public int addFluidToNetwork(TileEntity source, FluidStack sta, boolean doFill, boolean allowStore)
|
||||
{
|
||||
int used = 0;
|
||||
FluidStack stack = sta.copy();
|
||||
|
||||
if (!this.processingRequest && stack != null)
|
||||
{
|
||||
this.processingRequest = true;
|
||||
if (stack.amount > this.getMaxFlow(stack))
|
||||
{
|
||||
stack = FluidHelper.getStack(stack, this.getMaxFlow(stack));
|
||||
}
|
||||
|
||||
/* Secondary fill target if the main target is not found */
|
||||
IFluidHandler tankToFill = null;
|
||||
int mostFill = 0;
|
||||
ForgeDirection fillDir = ForgeDirection.UNKNOWN;
|
||||
|
||||
boolean found = false;
|
||||
|
||||
/* FIND THE FILL TARGET FROM THE LIST OF FLUID RECIEVERS */
|
||||
for (Entry<IFluidHandler, EnumSet<ForgeDirection>> entry : this.connctedFluidHandlers.entrySet())
|
||||
{
|
||||
IFluidHandler tankContainer = entry.getKey();
|
||||
if (tankContainer instanceof TileEntity && tankContainer != source && !(tankContainer instanceof INetworkPipe))
|
||||
{
|
||||
for (ForgeDirection dir : entry.getValue())
|
||||
{
|
||||
if (tankContainer.canFill(dir, sta.getFluid()))
|
||||
{
|
||||
int fill = tankContainer.fill(dir, stack, false);
|
||||
|
||||
if (fill > mostFill)
|
||||
{
|
||||
tankToFill = tankContainer;
|
||||
mostFill = fill;
|
||||
fillDir = dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}// End of tank finder
|
||||
if (tankToFill != null)
|
||||
{
|
||||
// TODO set up a list of tanks to actually fill rather than one at a time
|
||||
used = tankToFill.fill(fillDir, stack, doFill);
|
||||
// System.out.println("Seconday Target " + used + doFill);
|
||||
}
|
||||
}
|
||||
this.processingRequest = false;
|
||||
return used;
|
||||
}
|
||||
|
||||
/** Gets the flow rate of the system using the lowest flow rate */
|
||||
public int getMaxFlow(FluidStack stack)
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
|
||||
/** Updates after the pressure has changed a good bit */
|
||||
public void onPresureChange()
|
||||
{
|
||||
this.cleanUpMembers();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,15 +3,12 @@ package resonantinduction.mechanical.fluid.pipe;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import resonantinduction.api.fluid.IFluidNetwork;
|
||||
import resonantinduction.api.fluid.IFluidPipe;
|
||||
import resonantinduction.core.tilenetwork.ITileConnector;
|
||||
import resonantinduction.mechanical.fluid.network.NetworkPipes;
|
||||
import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import calclavia.lib.utility.FluidHelper;
|
||||
import dark.lib.helpers.ColorCode;
|
||||
import dark.lib.helpers.ColorCode.IColorCoded;
|
||||
|
||||
|
|
Loading…
Reference in a new issue