Working on improving Fluid networks
Main goal is to support multi tanks per fluid network part.
This commit is contained in:
parent
7f062e6b22
commit
a480b58a59
6 changed files with 185 additions and 21 deletions
|
@ -1,16 +1,24 @@
|
||||||
package dark.api.fluid;
|
package dark.api.fluid;
|
||||||
|
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import net.minecraftforge.fluids.FluidTank;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
import net.minecraftforge.fluids.IFluidTank;
|
import net.minecraftforge.fluids.IFluidTank;
|
||||||
import dark.api.parts.INetworkPart;
|
import dark.api.parts.INetworkPart;
|
||||||
import dark.core.interfaces.ColorCode.IColorCoded;
|
import dark.core.interfaces.ColorCode.IColorCoded;
|
||||||
|
import dark.core.prefab.helpers.Pair;
|
||||||
|
|
||||||
public interface INetworkFluidPart extends IColorCoded, IFluidHandler, INetworkPart
|
public interface INetworkFluidPart extends IColorCoded, IFluidHandler, INetworkPart
|
||||||
{
|
{
|
||||||
|
/** Gets an array of the fluid the tank can take */
|
||||||
|
public int getNumberOfTanks();
|
||||||
|
|
||||||
/** Gets the part's main tank for shared storage */
|
/** Gets the part's main tank for shared storage */
|
||||||
public IFluidTank getTank();
|
public IFluidTank getTank(int index);
|
||||||
|
|
||||||
/** Sets the content of the part's main tank */
|
/** Sets the content of the part's main tank */
|
||||||
public void setTankContent(FluidStack stack);
|
public int fillTankContent(int index, FluidStack stack, boolean doFill);
|
||||||
|
|
||||||
|
public FluidStack drainTankContent(int index, int volume, boolean doDrain);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import dark.api.fluid.AdvancedFluidEvent.FluidMergeEvent;
|
||||||
import dark.api.fluid.INetworkFluidPart;
|
import dark.api.fluid.INetworkFluidPart;
|
||||||
import dark.api.parts.INetworkPart;
|
import dark.api.parts.INetworkPart;
|
||||||
import dark.core.interfaces.ColorCode;
|
import dark.core.interfaces.ColorCode;
|
||||||
|
import dark.core.prefab.FluidSelectiveTank;
|
||||||
import dark.core.prefab.helpers.FluidHelper;
|
import dark.core.prefab.helpers.FluidHelper;
|
||||||
import dark.core.prefab.helpers.Pair;
|
import dark.core.prefab.helpers.Pair;
|
||||||
import dark.core.prefab.tilenetwork.NetworkTileEntities;
|
import dark.core.prefab.tilenetwork.NetworkTileEntities;
|
||||||
|
@ -132,7 +133,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0)
|
if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0)
|
||||||
{
|
{
|
||||||
//TODO change this to percent based system so tiles get volume that they can store
|
//TODO change this to percent based system so tiles get volume that they can store
|
||||||
int volume = this.combinedStorage().getFluid().amount / this.networkMember.size();
|
int vol = this.combinedStorage().getFluid().amount;
|
||||||
int fluid = this.combinedStorage().getFluid().fluidID;
|
int fluid = this.combinedStorage().getFluid().fluidID;
|
||||||
NBTTagCompound tag = this.combinedStorage().getFluid().tag;
|
NBTTagCompound tag = this.combinedStorage().getFluid().tag;
|
||||||
|
|
||||||
|
@ -140,9 +141,27 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
{
|
{
|
||||||
if (par instanceof INetworkFluidPart)
|
if (par instanceof INetworkFluidPart)
|
||||||
{
|
{
|
||||||
|
int fillVolume = this.combinedStorage().getFluid().amount / this.networkMember.size();
|
||||||
INetworkFluidPart part = ((INetworkFluidPart) par);
|
INetworkFluidPart part = ((INetworkFluidPart) par);
|
||||||
part.setTankContent(null);
|
for (int tank = 0; tank < part.getNumberOfTanks(); tank++)
|
||||||
part.setTankContent(new FluidStack(fluid, volume, tag));
|
{
|
||||||
|
if (part.getTank(tank) != null)
|
||||||
|
{
|
||||||
|
if (part.getTank(tank) instanceof FluidSelectiveTank)
|
||||||
|
{
|
||||||
|
if (((FluidSelectiveTank) part.getTank(tank)).canAcceptFluid(FluidRegistry.getFluid(fluid)))
|
||||||
|
{
|
||||||
|
part.drainTankContent(tank, Integer.MAX_VALUE, true);
|
||||||
|
vol -= part.fillTankContent(tank, new FluidStack(fluid, fillVolume, tag), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
part.setTankContent(tank, null);
|
||||||
|
part.setTankContent(tank, new FluidStack(fluid, volume, tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package dark.fluid.common.machines;
|
package dark.fluid.common.machines;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
@ -7,11 +9,13 @@ 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 net.minecraftforge.fluids.IFluidTank;
|
||||||
|
import dark.api.fluid.INetworkFluidPart;
|
||||||
import dark.core.interfaces.ColorCode;
|
import dark.core.interfaces.ColorCode;
|
||||||
import dark.core.interfaces.ColorCode.IColorCoded;
|
import dark.core.prefab.tilenetwork.NetworkTileEntities;
|
||||||
import dark.fluid.common.prefab.TileEntityFluidDevice;
|
import dark.fluid.common.prefab.TileEntityFluidDevice;
|
||||||
|
|
||||||
public class TileEntityBoiler extends TileEntityFluidDevice implements IFluidHandler
|
public class TileEntityBoiler extends TileEntityFluidDevice implements IFluidHandler, INetworkFluidPart
|
||||||
{
|
{
|
||||||
|
|
||||||
public TileEntity[] connectedBlocks = new TileEntity[6];
|
public TileEntity[] connectedBlocks = new TileEntity[6];
|
||||||
|
@ -73,6 +77,10 @@ public class TileEntityBoiler extends TileEntityFluidDevice implements IFluidHan
|
||||||
if (from == ForgeDirection.DOWN)
|
if (from == ForgeDirection.DOWN)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -91,4 +99,87 @@ public class TileEntityBoiler extends TileEntityFluidDevice implements IFluidHan
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ColorCode getColor()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setColor(Object obj)
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TileEntity> getNetworkConnections()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetworkTileEntities getTileNetwork()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTileNetwork(NetworkTileEntities fluidNetwok)
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mergeDamage(String result)
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IFluidTank getTank(int index)
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int fillTankContent(int index, FluidStack stack, boolean doFill)
|
||||||
|
{
|
||||||
|
if (this.getTank(index) != null)
|
||||||
|
{
|
||||||
|
return this.getTank(index).fill(stack, doFill);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidStack drainTankContent(int index, int volume, boolean doDrain)
|
||||||
|
{
|
||||||
|
if (this.getTank(index) != null)
|
||||||
|
{
|
||||||
|
return this.getTank(index).drain(volume, doDrain);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNumberOfTanks()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -294,9 +294,23 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTankContent(FluidStack stack)
|
public int fillTankContent(int index, FluidStack stack, boolean doFill)
|
||||||
{
|
{
|
||||||
this.getTank().setFluid(stack);
|
if (this.getTank() != null)
|
||||||
|
{
|
||||||
|
return this.getTank().fill(stack, doFill);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidStack drainTankContent(int index, int volume, boolean doDrain)
|
||||||
|
{
|
||||||
|
if (this.getTank(index) != null)
|
||||||
|
{
|
||||||
|
return this.getTank(index).drain(volume, doDrain);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRedstoneLevel()
|
public int getRedstoneLevel()
|
||||||
|
@ -332,4 +346,16 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNumberOfTanks()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IFluidTank getTank(int index)
|
||||||
|
{
|
||||||
|
return this.getTank();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ public class BlockPipe extends BlockFM
|
||||||
TileEntity entity = world.getBlockTileEntity(x, y, z);
|
TileEntity entity = world.getBlockTileEntity(x, y, z);
|
||||||
if (entity instanceof TileEntityPipe)
|
if (entity instanceof TileEntityPipe)
|
||||||
{
|
{
|
||||||
IFluidTank tank = ((TileEntityPipe) entity).getTank();
|
IFluidTank tank = ((TileEntityPipe) entity).getTank(0);
|
||||||
if (tank != null && tank.getFluid() != null && tank.getFluid().getFluid() != null && tank.getFluid().amount > 0)
|
if (tank != null && tank.getFluid() != null && tank.getFluid().getFluid() != null && tank.getFluid().amount > 0)
|
||||||
{
|
{
|
||||||
if (tank.getFluid().getFluid().getName().equalsIgnoreCase("water"))
|
if (tank.getFluid().getFluid().getName().equalsIgnoreCase("water"))
|
||||||
|
|
|
@ -414,7 +414,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
|
||||||
@Override
|
@Override
|
||||||
public FluidTankInfo[] getTankInfo(ForgeDirection direction)
|
public FluidTankInfo[] getTankInfo(ForgeDirection direction)
|
||||||
{
|
{
|
||||||
return new FluidTankInfo[] { new FluidTankInfo(this.getTank()) };
|
return new FluidTankInfo[] { new FluidTankInfo(this.getTank(0)) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks to make sure the connection is valid to the tileEntity
|
/** Checks to make sure the connection is valid to the tileEntity
|
||||||
|
@ -567,7 +567,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidTank getTank()
|
public FluidTank getTank(int index)
|
||||||
{
|
{
|
||||||
if (this.fakeTank == null)
|
if (this.fakeTank == null)
|
||||||
{
|
{
|
||||||
|
@ -577,9 +577,23 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTankContent(FluidStack stack)
|
public int fillTankContent(int index, FluidStack stack, boolean doFill)
|
||||||
{
|
{
|
||||||
this.getTank().setFluid(stack);
|
if (this.getTank(index) != null)
|
||||||
|
{
|
||||||
|
return this.getTank(index).fill(stack, doFill);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidStack drainTankContent(int index, int volume, boolean doDrain)
|
||||||
|
{
|
||||||
|
if (this.getTank(index) != null)
|
||||||
|
{
|
||||||
|
return this.getTank(index).drain(volume, doDrain);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -609,4 +623,10 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNumberOfTanks()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue