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];
|
||||||
|
@ -70,7 +74,11 @@ public class TileEntityBoiler extends TileEntityFluidDevice implements IFluidHan
|
||||||
@Override
|
@Override
|
||||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||||
{
|
{
|
||||||
if(from == ForgeDirection.DOWN)
|
if (from == ForgeDirection.DOWN)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand
|
||||||
{
|
{
|
||||||
if (id == 0)
|
if (id == 0)
|
||||||
{
|
{
|
||||||
this.getTank().setFluid(FluidStack.loadFluidStackFromNBT( PacketHandler.instance().readNBTTagCompound(dataStream)));
|
this.getTank().setFluid(FluidStack.loadFluidStackFromNBT(PacketHandler.instance().readNBTTagCompound(dataStream)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -126,7 +126,7 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand
|
||||||
{
|
{
|
||||||
stack = this.getTank().getFluid();
|
stack = this.getTank().getFluid();
|
||||||
}
|
}
|
||||||
return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, stack != null ? 0 : 1, stack != null ? stack.writeToNBT(new NBTTagCompound()) : 1, this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]);
|
return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, stack != null ? 0 : 1, stack != null ? stack.writeToNBT(new NBTTagCompound()) : 1, this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** gets the current color mark of the pipe */
|
/** gets the current color mark of the pipe */
|
||||||
|
@ -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"))
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
|
||||||
((TileEntity) extention).updateEntity();
|
((TileEntity) extention).updateEntity();
|
||||||
if (extention.shouldSendPacket(!this.worldObj.isRemote) && extention.getExtentionPacketData(!this.worldObj.isRemote) != null)
|
if (extention.shouldSendPacket(!this.worldObj.isRemote) && extention.getExtentionPacketData(!this.worldObj.isRemote) != null)
|
||||||
{
|
{
|
||||||
Packet packet = PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.EXTENTION_UPDATE.ordinal(), ForgeDirection.getOrientation(i), extention.getExtentionPacketData(!this.worldObj.isRemote));
|
Packet packet = PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.EXTENTION_UPDATE.ordinal(), ForgeDirection.getOrientation(i), extention.getExtentionPacketData(!this.worldObj.isRemote));
|
||||||
PacketHandler.instance().sendPacketToClients(packet, worldObj, new Vector3(this), 50);
|
PacketHandler.instance().sendPacketToClients(packet, worldObj, new Vector3(this), 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
|
||||||
{
|
{
|
||||||
System.out.println("Handling Packet for Pipe addon");
|
System.out.println("Handling Packet for Pipe addon");
|
||||||
int side = dataStream.readInt();
|
int side = dataStream.readInt();
|
||||||
NBTTagCompound tag = PacketHandler.instance().readNBTTagCompound(dataStream);
|
NBTTagCompound tag = PacketHandler.instance().readNBTTagCompound(dataStream);
|
||||||
this.loadOrCreateSubTile(side, tag);
|
this.loadOrCreateSubTile(side, tag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
|
||||||
@Override
|
@Override
|
||||||
public Packet getDescriptionPacket()
|
public Packet getDescriptionPacket()
|
||||||
{
|
{
|
||||||
return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.PIPE_CONNECTIONS.ordinal(), this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]);
|
return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.PIPE_CONNECTIONS.ordinal(), this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reads a tile entity from NBT. */
|
/** Reads a tile entity from NBT. */
|
||||||
|
@ -317,7 +317,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
|
||||||
if (tag != null && tag.hasKey("id"))
|
if (tag != null && tag.hasKey("id"))
|
||||||
{
|
{
|
||||||
System.out.println("Sending TileEntity to Client");
|
System.out.println("Sending TileEntity to Client");
|
||||||
Packet packet = PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.EXTENTION_CREATE.ordinal(), ForgeDirection.getOrientation(side), tag);
|
Packet packet = PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.EXTENTION_CREATE.ordinal(), ForgeDirection.getOrientation(side), tag);
|
||||||
PacketHandler.instance().sendPacketToClients(packet, this.worldObj, new Vector3(this), 50);
|
PacketHandler.instance().sendPacketToClients(packet, this.worldObj, new Vector3(this), 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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