Added clockwise set and get methods for IMechanical
This commit is contained in:
parent
1e5319c4de
commit
20dcbce5c5
16 changed files with 725 additions and 652 deletions
|
@ -8,7 +8,7 @@ import universalelectricity.api.net.IConnector;
|
|||
* that each part can only support one fluid tank internally
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IFluidPart extends IConnector<IFluidNetwork>, IFluidHandler
|
||||
public interface IFluidConnector extends IConnector<IFluidNetwork>, IFluidHandler
|
||||
{
|
||||
/** FluidTank that the network will have access to fill or drain */
|
||||
public FluidTank getInternalTank();
|
|
@ -10,7 +10,7 @@ import universalelectricity.api.net.INetwork;
|
|||
/** Interface version of the fluid network.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IFluidNetwork extends INetwork<IFluidNetwork, IFluidPart, IFluidHandler>
|
||||
public interface IFluidNetwork extends INetwork<IFluidNetwork, IFluidConnector, IFluidHandler>
|
||||
{
|
||||
/** Called to build the network when something changes such as addition of a pipe */
|
||||
void reconstruct();
|
||||
|
@ -22,7 +22,7 @@ public interface IFluidNetwork extends INetwork<IFluidNetwork, IFluidPart, IFlui
|
|||
* @param resource - fluid stack that is being filled into the network
|
||||
* @param doFill - true causes the action to be taken, false simulates the action
|
||||
* @return amount of fluid filled into the network */
|
||||
int fill(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doFill);
|
||||
int fill(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doFill);
|
||||
|
||||
/** Called to remove fluid from a network, not supported by all networks
|
||||
*
|
||||
|
@ -31,7 +31,7 @@ public interface IFluidNetwork extends INetwork<IFluidNetwork, IFluidPart, IFlui
|
|||
* @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, FluidStack resource, boolean doDrain);
|
||||
FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain);
|
||||
|
||||
/** Called to remove fluid from a network, not supported by all networks
|
||||
*
|
||||
|
@ -40,7 +40,7 @@ public interface IFluidNetwork extends INetwork<IFluidNetwork, IFluidPart, IFlui
|
|||
* @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);
|
||||
FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain);
|
||||
|
||||
/** Fluid tank that represents the entire network */
|
||||
FluidTank getTank();
|
||||
|
|
|
@ -3,7 +3,7 @@ package resonantinduction.api.fluid;
|
|||
/** Applied to tiles that are pipes and support pressure
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IFluidPipe extends IFluidPart, IPressureInput
|
||||
public interface IFluidPipe extends IFluidConnector, IPressureInput
|
||||
{
|
||||
/** Max pressure this pipe can support */
|
||||
int getMaxPressure();
|
||||
|
|
|
@ -113,4 +113,16 @@ public class TileGenerator extends TileElectrical implements IMechanical
|
|||
nbt.setBoolean("isInversed", isInversed);
|
||||
nbt.setFloat("torqueRatio", torqueRatio);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClockwise()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(boolean isClockwise)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,313 +11,326 @@ 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 resonantinduction.api.fluid.IFluidConnector;
|
||||
import universalelectricity.api.net.IConnector;
|
||||
import universalelectricity.core.net.ConnectionPathfinder;
|
||||
import universalelectricity.core.net.Network;
|
||||
import universalelectricity.core.net.NetworkTickHandler;
|
||||
import calclavia.lib.utility.FluidUtility;
|
||||
|
||||
public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandler> implements IFluidNetwork
|
||||
public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnector, IFluidHandler> implements IFluidNetwork
|
||||
{
|
||||
protected FluidTank tank = new FluidTank(0);
|
||||
protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1];
|
||||
protected boolean reloadTanks = false;
|
||||
protected long ticks = 0;
|
||||
protected FluidTank tank = new FluidTank(0);
|
||||
protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1];
|
||||
protected boolean reloadTanks = false;
|
||||
protected long ticks = 0;
|
||||
|
||||
public FluidNetwork()
|
||||
{
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
public FluidNetwork()
|
||||
{
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
if (this.reloadTanks)
|
||||
{
|
||||
this.reloadTanks();
|
||||
}
|
||||
this.tank = new FluidTank(0);
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
{
|
||||
part.setNetwork(this);
|
||||
this.buildPart(part);
|
||||
}
|
||||
this.rebuildTank();
|
||||
this.reloadTanks();
|
||||
}
|
||||
@Override
|
||||
public void addConnector(IFluidConnector connector)
|
||||
{
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
super.addConnector(connector);
|
||||
}
|
||||
|
||||
public void buildPart(IFluidPart part)
|
||||
{
|
||||
FluidTank tank = part.getInternalTank();
|
||||
if (tank != null)
|
||||
{
|
||||
this.tank.setCapacity(this.tank.getCapacity() + tank.getCapacity());
|
||||
if (this.tank.getFluid() == null)
|
||||
{
|
||||
this.tank.setFluid(tank.getFluid());
|
||||
}
|
||||
else if (this.tank.getFluid().isFluidEqual(tank.getFluid()))
|
||||
{
|
||||
this.tank.getFluid().amount += tank.getFluidAmount();
|
||||
}
|
||||
else if (this.tank.getFluid() != null)
|
||||
{
|
||||
//TODO cause a mixing event
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
if (this.reloadTanks)
|
||||
{
|
||||
this.reloadTanks();
|
||||
}
|
||||
this.tank = new FluidTank(0);
|
||||
for (IFluidConnector part : this.getConnectors())
|
||||
{
|
||||
part.setNetwork(this);
|
||||
this.buildPart(part);
|
||||
}
|
||||
this.rebuildHandler();
|
||||
this.reloadTanks();
|
||||
}
|
||||
|
||||
public void rebuildTank()
|
||||
{
|
||||
if (this.getTank() != null)
|
||||
{
|
||||
this.tankInfo[0] = this.getTank().getInfo();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tankInfo[0] = null;
|
||||
}
|
||||
this.reloadTanks = true;
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
public void buildPart(IFluidConnector part)
|
||||
{
|
||||
FluidTank tank = part.getInternalTank();
|
||||
if (tank != null)
|
||||
{
|
||||
this.tank.setCapacity(this.tank.getCapacity() + tank.getCapacity());
|
||||
if (this.tank.getFluid() == null)
|
||||
{
|
||||
this.tank.setFluid(tank.getFluid());
|
||||
}
|
||||
else if (this.tank.getFluid().isFluidEqual(tank.getFluid()))
|
||||
{
|
||||
this.tank.getFluid().amount += tank.getFluidAmount();
|
||||
}
|
||||
else if (this.tank.getFluid() != null)
|
||||
{
|
||||
// TODO cause a mixing event
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
int prev = this.getTank().getFluidAmount();
|
||||
int fill = this.getTank().fill(resource, doFill);
|
||||
if (prev != this.getTank().getFluidAmount())
|
||||
{
|
||||
this.rebuildTank();
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
public void rebuildHandler()
|
||||
{
|
||||
if (this.getTank() != null)
|
||||
{
|
||||
this.tankInfo[0] = this.getTank().getInfo();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tankInfo[0] = null;
|
||||
}
|
||||
this.reloadTanks = true;
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
if (resource != null && resource.isFluidEqual(this.getTank().getFluid()))
|
||||
{
|
||||
FluidStack before = this.getTank().getFluid();
|
||||
FluidStack drain = this.getTank().drain(resource.amount, doDrain);
|
||||
if (before != this.getTank().getFluid() || this.getTank().getFluid() == null || this.getTank().getFluid().amount != before.amount)
|
||||
{
|
||||
this.rebuildTank();
|
||||
}
|
||||
@Override
|
||||
public int fill(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
int prev = this.getTank().getFluidAmount();
|
||||
int fill = this.getTank().fill(resource, doFill);
|
||||
if (prev != this.getTank().getFluidAmount())
|
||||
{
|
||||
this.rebuildHandler();
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
|
||||
return drain;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
if (resource != null && resource.isFluidEqual(this.getTank().getFluid()))
|
||||
{
|
||||
FluidStack before = this.getTank().getFluid();
|
||||
FluidStack drain = this.getTank().drain(resource.amount, doDrain);
|
||||
if (before != this.getTank().getFluid() || this.getTank().getFluid() == null || this.getTank().getFluid().amount != before.amount)
|
||||
{
|
||||
this.rebuildHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(IFluidPart source, ForgeDirection from, int resource, boolean doDrain)
|
||||
{
|
||||
if (this.getTank().getFluid() != null)
|
||||
{
|
||||
return this.drain(source, from, FluidUtility.getStack(this.getTank().getFluid(), resource), doDrain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return drain;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return this.reloadTanks;
|
||||
}
|
||||
@Override
|
||||
public FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain)
|
||||
{
|
||||
if (this.getTank().getFluid() != null)
|
||||
{
|
||||
return this.drain(source, from, FluidUtility.getStack(this.getTank().getFluid(), resource), doDrain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueUpdate()
|
||||
{
|
||||
return this.reloadTanks;
|
||||
}
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return this.reloadTanks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
this.ticks++;
|
||||
if (ticks >= Long.MAX_VALUE - 10)
|
||||
{
|
||||
ticks = 1;
|
||||
}
|
||||
if (this.reloadTanks && ticks % 10 == 0)
|
||||
{
|
||||
this.reloadTanks();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean continueUpdate()
|
||||
{
|
||||
return this.reloadTanks;
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onWorldSave(Save event)
|
||||
{
|
||||
this.reloadTanks();
|
||||
}
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
this.ticks++;
|
||||
if (ticks >= Long.MAX_VALUE - 10)
|
||||
{
|
||||
ticks = 1;
|
||||
}
|
||||
if (this.reloadTanks && ticks % 10 == 0)
|
||||
{
|
||||
this.reloadTanks();
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadTanks()
|
||||
{
|
||||
this.reloadTanks = false;
|
||||
FluidStack stack = this.getTank().getFluid();
|
||||
this.fillTankSet(stack != null ? stack.copy() : null, this.getConnectors());
|
||||
}
|
||||
@ForgeSubscribe
|
||||
public void onWorldSave(Save event)
|
||||
{
|
||||
this.reloadTanks();
|
||||
}
|
||||
|
||||
public void fillTankSet(FluidStack stack, Set<IFluidPart> tankList)
|
||||
{
|
||||
int parts = tankList.size();
|
||||
for (IFluidPart part : tankList)
|
||||
{
|
||||
part.getInternalTank().setFluid(null);
|
||||
if (stack != null)
|
||||
{
|
||||
int fillPer = (stack.amount / parts) + (stack.amount % parts);
|
||||
stack.amount -= part.getInternalTank().fill(FluidUtility.getStack(stack, fillPer), true);
|
||||
part.onFluidChanged();
|
||||
if (parts > 1)
|
||||
parts--;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void reloadTanks()
|
||||
{
|
||||
this.reloadTanks = false;
|
||||
FluidStack stack = this.getTank().getFluid();
|
||||
this.fillTankSet(stack != null ? stack.copy() : null, this.getConnectors());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidNetwork merge(IFluidNetwork network)
|
||||
{
|
||||
FluidNetwork newNetwork = null;
|
||||
if (network != null && network.getClass().isAssignableFrom(this.getClass()) && network != this)
|
||||
{
|
||||
public void fillTankSet(FluidStack stack, Set<IFluidConnector> tankList)
|
||||
{
|
||||
int parts = tankList.size();
|
||||
for (IFluidConnector part : tankList)
|
||||
{
|
||||
part.getInternalTank().setFluid(null);
|
||||
if (stack != null)
|
||||
{
|
||||
int fillPer = (stack.amount / parts) + (stack.amount % parts);
|
||||
stack.amount -= part.getInternalTank().fill(FluidUtility.getStack(stack, fillPer), true);
|
||||
part.onFluidChanged();
|
||||
if (parts > 1)
|
||||
parts--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
newNetwork = this.getClass().newInstance();
|
||||
@Override
|
||||
public IFluidNetwork merge(IFluidNetwork network)
|
||||
{
|
||||
FluidNetwork newNetwork = null;
|
||||
if (network != null && network.getClass().isAssignableFrom(this.getClass()) && network != this)
|
||||
{
|
||||
|
||||
newNetwork.getConnectors().addAll(this.getConnectors());
|
||||
newNetwork.getConnectors().addAll(network.getConnectors());
|
||||
try
|
||||
{
|
||||
newNetwork = this.getClass().newInstance();
|
||||
|
||||
network.getConnectors().clear();
|
||||
network.getNodes().clear();
|
||||
this.getConnectors().clear();
|
||||
this.getNodes().clear();
|
||||
newNetwork.getConnectors().addAll(this.getConnectors());
|
||||
newNetwork.getConnectors().addAll(network.getConnectors());
|
||||
|
||||
newNetwork.reconstruct();
|
||||
network.getConnectors().clear();
|
||||
network.getNodes().clear();
|
||||
this.getConnectors().clear();
|
||||
this.getNodes().clear();
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
newNetwork.reconstruct();
|
||||
|
||||
}
|
||||
return newNetwork;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void split(IFluidPart splitPoint)
|
||||
{
|
||||
this.removeConnector(splitPoint);
|
||||
this.reconstruct();
|
||||
}
|
||||
return newNetwork;
|
||||
}
|
||||
|
||||
/** Loop through the connected blocks and attempt to see if there are connections between the
|
||||
* two points elsewhere. */
|
||||
Object[] connectedBlocks = splitPoint.getConnections();
|
||||
@Override
|
||||
public void split(IFluidConnector splitPoint)
|
||||
{
|
||||
this.removeConnector(splitPoint);
|
||||
this.reconstruct();
|
||||
|
||||
for (int i = 0; i < connectedBlocks.length; i++)
|
||||
{
|
||||
Object connectedBlockA = connectedBlocks[i];
|
||||
/**
|
||||
* Loop through the connected blocks and attempt to see if there are connections between the
|
||||
* two points elsewhere.
|
||||
*/
|
||||
Object[] connectedBlocks = splitPoint.getConnections();
|
||||
|
||||
if (connectedBlockA instanceof IFluidPart)
|
||||
{
|
||||
for (int ii = 0; ii < connectedBlocks.length; ii++)
|
||||
{
|
||||
final Object connectedBlockB = connectedBlocks[ii];
|
||||
for (int i = 0; i < connectedBlocks.length; i++)
|
||||
{
|
||||
Object connectedBlockA = connectedBlocks[i];
|
||||
|
||||
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof IFluidPart)
|
||||
{
|
||||
ConnectionPathfinder finder = new ConnectionPathfinder((IFluidPart) connectedBlockB, splitPoint);
|
||||
finder.findNodes((IFluidPart) connectedBlockA);
|
||||
if (connectedBlockA instanceof IFluidConnector)
|
||||
{
|
||||
for (int ii = 0; ii < connectedBlocks.length; ii++)
|
||||
{
|
||||
final Object connectedBlockB = connectedBlocks[ii];
|
||||
|
||||
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();
|
||||
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof IFluidConnector)
|
||||
{
|
||||
ConnectionPathfinder finder = new ConnectionPathfinder((IFluidConnector) connectedBlockB, splitPoint);
|
||||
finder.findNodes((IFluidConnector) connectedBlockA);
|
||||
|
||||
for (IConnector node : finder.closedSet)
|
||||
{
|
||||
if (node != splitPoint && node instanceof IFluidPart)
|
||||
{
|
||||
newNetwork.addConnector((IFluidPart) node);
|
||||
}
|
||||
}
|
||||
newNetwork.reconstruct();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
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 IFluidConnector)
|
||||
{
|
||||
newNetwork.addConnector((IFluidConnector) 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);
|
||||
@Override
|
||||
public void split(IFluidConnector connectorA, IFluidConnector connectorB)
|
||||
{
|
||||
this.reconstruct();
|
||||
|
||||
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();
|
||||
/** Check if connectorA connects with connectorB. */
|
||||
ConnectionPathfinder finder = new ConnectionPathfinder(connectorB);
|
||||
finder.findNodes(connectorA);
|
||||
|
||||
for (IConnector node : finder.closedSet)
|
||||
{
|
||||
if (node instanceof IFluidPart)
|
||||
{
|
||||
newNetwork.addConnector((IFluidPart) node);
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
||||
newNetwork.reconstruct();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (IConnector node : finder.closedSet)
|
||||
{
|
||||
if (node instanceof IFluidConnector)
|
||||
{
|
||||
newNetwork.addConnector((IFluidConnector) node);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTank getTank()
|
||||
{
|
||||
if (this.tank == null)
|
||||
{
|
||||
this.tank = new FluidTank(0);
|
||||
}
|
||||
return this.tank;
|
||||
}
|
||||
newNetwork.reconstruct();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo()
|
||||
{
|
||||
return tankInfo;
|
||||
}
|
||||
@Override
|
||||
public FluidTank getTank()
|
||||
{
|
||||
if (this.tank == null)
|
||||
{
|
||||
this.tank = new FluidTank(0);
|
||||
}
|
||||
return this.tank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return super.toString() + " Vol:" + this.tank.getFluidAmount();
|
||||
}
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo()
|
||||
{
|
||||
return tankInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return super.toString() + " Vol:" + this.tank.getFluidAmount();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import resonantinduction.api.fluid.IFluidPart;
|
||||
import resonantinduction.api.fluid.IFluidConnector;
|
||||
import resonantinduction.api.fluid.IFluidPipe;
|
||||
import resonantinduction.mechanical.fluid.network.FluidNetwork;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
@ -17,97 +17,99 @@ import calclavia.lib.utility.FluidUtility;
|
|||
/** @author DarkGuardsman */
|
||||
public class PipeNetwork extends FluidNetwork
|
||||
{
|
||||
public HashMap<IFluidHandler, EnumSet<ForgeDirection>> connectionMap = new HashMap<IFluidHandler, EnumSet<ForgeDirection>>();
|
||||
public HashMap<IFluidHandler, EnumSet<ForgeDirection>> connectionMap = new HashMap<IFluidHandler, EnumSet<ForgeDirection>>();
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
System.out.println("PipeNetwork:" + this.toString());
|
||||
System.out.println("FluidVol: " + this.getTank().getFluidAmount());
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
System.out.println("PipeNetwork:" + this.toString());
|
||||
System.out.println("FluidVol: " + this.getTank().getFluidAmount());
|
||||
|
||||
super.update();
|
||||
//Slight delay to allow visual effect to take place before draining the pipe's internal tank
|
||||
if (this.ticks % 2 == 0 && this.getTank().getFluidAmount() > 0)
|
||||
{
|
||||
FluidStack stack = this.getTank().getFluid().copy();
|
||||
int count = this.connectionMap.size();
|
||||
for (Entry<IFluidHandler, EnumSet<ForgeDirection>> entry : this.connectionMap.entrySet())
|
||||
{
|
||||
int sideCount = entry.getValue().size();
|
||||
for (ForgeDirection dir : entry.getValue())
|
||||
{
|
||||
int volPer = (stack.amount / count) + (stack.amount % count);
|
||||
int volPerSide = (volPer / sideCount) + (volPer % count);
|
||||
int maxFill = 1000;
|
||||
TileEntity entity = new Vector3((TileEntity) entry.getKey()).modifyPositionFromSide(dir).getTileEntity(((TileEntity) entry.getKey()).worldObj);
|
||||
if (entity instanceof IFluidPipe)
|
||||
{
|
||||
maxFill = ((IFluidPipe) entity).getMaxFlowRate();
|
||||
}
|
||||
stack.amount -= entry.getKey().fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, maxFill)), true);
|
||||
if (sideCount > 1)
|
||||
--sideCount;
|
||||
if (volPer <= 0)
|
||||
break;
|
||||
}
|
||||
if (count > 1)
|
||||
count--;
|
||||
if (stack == null || stack.amount <= 0)
|
||||
break;
|
||||
}
|
||||
this.getTank().setFluid(stack);
|
||||
//TODO check for change before rebuilding
|
||||
this.rebuildTank();
|
||||
}
|
||||
}
|
||||
super.update();
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// Slight delay to allow visual effect to take place before draining the pipe's internal
|
||||
// tank
|
||||
if (this.ticks % 2 == 0 && this.getTank().getFluidAmount() > 0)
|
||||
{
|
||||
FluidStack stack = this.getTank().getFluid().copy();
|
||||
int count = this.connectionMap.size();
|
||||
for (Entry<IFluidHandler, EnumSet<ForgeDirection>> entry : this.connectionMap.entrySet())
|
||||
{
|
||||
int sideCount = entry.getValue().size();
|
||||
for (ForgeDirection dir : entry.getValue())
|
||||
{
|
||||
int volPer = (stack.amount / count) + (stack.amount % count);
|
||||
int volPerSide = (volPer / sideCount) + (volPer % count);
|
||||
int maxFill = 1000;
|
||||
TileEntity entity = new Vector3((TileEntity) entry.getKey()).modifyPositionFromSide(dir).getTileEntity(((TileEntity) entry.getKey()).worldObj);
|
||||
if (entity instanceof IFluidPipe)
|
||||
{
|
||||
maxFill = ((IFluidPipe) entity).getMaxFlowRate();
|
||||
}
|
||||
stack.amount -= entry.getKey().fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, maxFill)), true);
|
||||
if (sideCount > 1)
|
||||
--sideCount;
|
||||
if (volPer <= 0)
|
||||
break;
|
||||
}
|
||||
if (count > 1)
|
||||
count--;
|
||||
if (stack == null || stack.amount <= 0)
|
||||
break;
|
||||
}
|
||||
this.getTank().setFluid(stack);
|
||||
// TODO check for change before rebuilding
|
||||
this.rebuildHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueUpdate()
|
||||
{
|
||||
return this.getConnectors().size() > 0;
|
||||
}
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
this.connectionMap.clear();
|
||||
super.reconstruct();
|
||||
}
|
||||
@Override
|
||||
public boolean continueUpdate()
|
||||
{
|
||||
return true;// this.getConnectors().size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildPart(IFluidPart part)
|
||||
{
|
||||
super.buildPart(part);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (part.getConnections()[i] instanceof IFluidHandler && !(part.getConnections()[i] instanceof IFluidPipe))
|
||||
{
|
||||
EnumSet<ForgeDirection> set = this.connectionMap.get(part.getConnections()[i]);
|
||||
if (set == null)
|
||||
{
|
||||
set = EnumSet.noneOf(ForgeDirection.class);
|
||||
}
|
||||
set.add(ForgeDirection.getOrientation(i).getOpposite());
|
||||
this.connectionMap.put((IFluidHandler) part.getConnections()[i], set);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
this.connectionMap.clear();
|
||||
super.reconstruct();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void buildPart(IFluidConnector part)
|
||||
{
|
||||
super.buildPart(part);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (part.getConnections()[i] instanceof IFluidHandler && !(part.getConnections()[i] instanceof IFluidPipe))
|
||||
{
|
||||
EnumSet<ForgeDirection> set = this.connectionMap.get(part.getConnections()[i]);
|
||||
if (set == null)
|
||||
{
|
||||
set = EnumSet.noneOf(ForgeDirection.class);
|
||||
}
|
||||
set.add(ForgeDirection.getOrientation(i).getOpposite());
|
||||
this.connectionMap.put((IFluidHandler) part.getConnections()[i], set);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(IFluidPart source, ForgeDirection from, int resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import net.minecraftforge.fluids.FluidTank;
|
|||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import resonantinduction.api.IReadOut;
|
||||
import resonantinduction.api.fluid.IFluidNetwork;
|
||||
import resonantinduction.api.fluid.IFluidPart;
|
||||
import resonantinduction.api.fluid.IFluidConnector;
|
||||
import resonantinduction.core.ResonantInduction;
|
||||
import resonantinduction.mechanical.Mechanical;
|
||||
import resonantinduction.mechanical.fluid.network.FluidNetwork;
|
||||
|
@ -28,331 +28,322 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileFluidNetwork extends TileEntityFluidDevice implements IFluidPart, IPacketReceiverWithID, IReadOut
|
||||
/**
|
||||
* A prefab class for tiles that use the fluid network.
|
||||
*
|
||||
* @author DarkCow
|
||||
*
|
||||
*/
|
||||
public abstract class TileFluidNetwork<N extends FluidNetwork> extends TileEntityFluidDevice implements IFluidConnector, IPacketReceiverWithID, IReadOut
|
||||
{
|
||||
public static int refreshRate = 10;
|
||||
protected FluidTank tank = new FluidTank(1 * FluidContainerRegistry.BUCKET_VOLUME);
|
||||
protected Object[] connectedBlocks = new Object[6];
|
||||
protected int colorID = 0;
|
||||
public static int refreshRate = 10;
|
||||
protected FluidTank tank = new FluidTank(1 * FluidContainerRegistry.BUCKET_VOLUME);
|
||||
protected Object[] connectedBlocks = new Object[6];
|
||||
protected int colorID = 0;
|
||||
|
||||
/** Copy of the tank's content last time it updated */
|
||||
protected FluidStack prevStack = null;
|
||||
/** Copy of the tank's content last time it updated */
|
||||
protected FluidStack prevStack = null;
|
||||
|
||||
/** Network used to link all parts together */
|
||||
protected IFluidNetwork network;
|
||||
/** Network used to link all parts together */
|
||||
protected N network;
|
||||
|
||||
public static final int PACKET_DESCRIPTION = 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_DESCRIPTION = Mechanical.contentRegistry.getNextPacketID();
|
||||
public static final int PACKET_RENDER = Mechanical.contentRegistry.getNextPacketID();
|
||||
public static final int PACKET_TANK = Mechanical.contentRegistry.getNextPacketID();
|
||||
|
||||
/** Bitmask that handles connections for the renderer **/
|
||||
public byte renderSides = 0b0;
|
||||
/** Bitmask that handles connections for the renderer **/
|
||||
public byte renderSides = 0b0;
|
||||
|
||||
/** Tells the tank that on next update to check if it should update the client render data */
|
||||
public boolean updateFluidRender = false;
|
||||
/** Tells the tank that on next update to check if it should update the client render data */
|
||||
public boolean updateFluidRender = false;
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
super.initiate();
|
||||
this.refresh();
|
||||
}
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
super.initiate();
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (this.updateFluidRender && ticks % TileFluidNetwork.refreshRate == 0)
|
||||
{
|
||||
if (!FluidUtility.matchExact(prevStack, this.getInternalTank().getFluid()))
|
||||
{
|
||||
this.sendTankUpdate();
|
||||
}
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (this.updateFluidRender && ticks % TileFluidNetwork.refreshRate == 0)
|
||||
{
|
||||
if (!FluidUtility.matchExact(prevStack, this.getInternalTank().getFluid()))
|
||||
{
|
||||
this.sendTankUpdate();
|
||||
}
|
||||
|
||||
this.prevStack = this.tank.getFluid();
|
||||
this.updateFluidRender = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.prevStack = this.tank.getFluid();
|
||||
this.updateFluidRender = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFluidChanged()
|
||||
{
|
||||
this.updateFluidRender = true;
|
||||
}
|
||||
@Override
|
||||
public void onFluidChanged()
|
||||
{
|
||||
this.updateFluidRender = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
this.getNetwork().split(this);
|
||||
super.invalidate();
|
||||
}
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
this.getNetwork().split(this);
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (this.getNetwork() != null && resource != null)
|
||||
{
|
||||
return this.getNetwork().fill(this, from, resource, doFill);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (this.getNetwork() != null && resource != null)
|
||||
{
|
||||
return this.getNetwork().fill(this, from, resource, doFill);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
if (this.getNetwork() != null && resource != null)
|
||||
{
|
||||
return this.getNetwork().drain(this, from, resource, doDrain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
if (this.getNetwork() != null && resource != null)
|
||||
{
|
||||
return this.getNetwork().drain(this, from, resource, doDrain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
if (this.getNetwork() != null)
|
||||
{
|
||||
return this.getNetwork().drain(this, from, maxDrain, doDrain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
if (this.getNetwork() != null)
|
||||
{
|
||||
return this.getNetwork().drain(this, from, maxDrain, doDrain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
||||
{
|
||||
return this.getNetwork().getTankInfo();
|
||||
}
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
||||
{
|
||||
return this.getNetwork().getTankInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
{
|
||||
return this.connectedBlocks;
|
||||
}
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
{
|
||||
return this.connectedBlocks;
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
{
|
||||
if (this.worldObj != null && !this.worldObj.isRemote)
|
||||
{
|
||||
byte previousConnections = renderSides;
|
||||
this.connectedBlocks = new Object[6];
|
||||
this.renderSides = 0;
|
||||
public void refresh()
|
||||
{
|
||||
if (this.worldObj != null && !this.worldObj.isRemote)
|
||||
{
|
||||
byte previousConnections = renderSides;
|
||||
this.connectedBlocks = new Object[6];
|
||||
this.renderSides = 0;
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
this.validateConnectionSide(new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj), dir);
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
this.validateConnectionSide(new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj), dir);
|
||||
|
||||
}
|
||||
/** Only send packet updates if visuallyConnected changed. */
|
||||
if (previousConnections != renderSides)
|
||||
{
|
||||
this.sendRenderUpdate();
|
||||
this.getNetwork().reconstruct();
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Only send packet updates if visuallyConnected changed. */
|
||||
if (previousConnections != renderSides)
|
||||
{
|
||||
this.sendRenderUpdate();
|
||||
this.getNetwork().reconstruct();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** 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)
|
||||
{
|
||||
this.getNetwork().merge(((IFluidPart) tileEntity).getNetwork());
|
||||
this.setRenderSide(side, true);
|
||||
connectedBlocks[side.ordinal()] = 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
|
||||
*/
|
||||
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (tileEntity instanceof IFluidConnector)
|
||||
{
|
||||
this.getNetwork().merge(((IFluidConnector) tileEntity).getNetwork());
|
||||
this.setRenderSide(side, true);
|
||||
connectedBlocks[side.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setRenderSide(ForgeDirection direction, boolean doRender)
|
||||
{
|
||||
if (doRender)
|
||||
{
|
||||
renderSides = (byte) (renderSides | (1 << direction.ordinal()));
|
||||
}
|
||||
else
|
||||
{
|
||||
renderSides = (byte) (renderSides & ~(1 << direction.ordinal()));
|
||||
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)
|
||||
{
|
||||
return (renderSides & (1 << direction.ordinal())) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidNetwork getNetwork()
|
||||
{
|
||||
if (this.network != null)
|
||||
{
|
||||
this.network = new FluidNetwork();
|
||||
this.network.addConnector(this);
|
||||
}
|
||||
return this.network;
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
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.getInternalTank().setFluid(liquid);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getInternalTank().readFromNBT(nbt.getCompoundTag("FluidTank"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(IFluidNetwork fluidNetwork)
|
||||
{
|
||||
this.network = fluidNetwork;
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setInteger("subID", this.colorID);
|
||||
nbt.setCompoundTag("FluidTank", this.getInternalTank().writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
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.getInternalTank().setFluid(liquid);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getInternalTank().readFromNBT(nbt.getCompoundTag("FluidTank"));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
if (id == PACKET_DESCRIPTION)
|
||||
{
|
||||
this.colorID = data.readInt();
|
||||
this.renderSides = data.readByte();
|
||||
this.tank = new FluidTank(data.readInt());
|
||||
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||
return true;
|
||||
}
|
||||
else if (id == PACKET_RENDER)
|
||||
{
|
||||
this.colorID = data.readInt();
|
||||
this.renderSides = data.readByte();
|
||||
return true;
|
||||
}
|
||||
else if (id == PACKET_TANK)
|
||||
{
|
||||
this.tank = new FluidTank(data.readInt());
|
||||
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setInteger("subID", this.colorID);
|
||||
nbt.setCompoundTag("FluidTank", this.getInternalTank().writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
return ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_DESCRIPTION, this, this.colorID, this.renderSides, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
if (id == PACKET_DESCRIPTION)
|
||||
{
|
||||
this.colorID = data.readInt();
|
||||
this.renderSides = data.readByte();
|
||||
this.tank = new FluidTank(data.readInt());
|
||||
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||
return true;
|
||||
}
|
||||
else if (id == PACKET_RENDER)
|
||||
{
|
||||
this.colorID = data.readInt();
|
||||
this.renderSides = data.readByte();
|
||||
return true;
|
||||
}
|
||||
else if (id == PACKET_TANK)
|
||||
{
|
||||
this.tank = new FluidTank(data.readInt());
|
||||
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void sendRenderUpdate()
|
||||
{
|
||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_RENDER, this, this.colorID, this.renderSides));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
return ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_DESCRIPTION, this, this.colorID, this.renderSides, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
public void sendTankUpdate()
|
||||
{
|
||||
if (this.getInternalTank() != null)
|
||||
{
|
||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendRenderUpdate()
|
||||
{
|
||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_RENDER, this, this.colorID, this.renderSides));
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox()
|
||||
{
|
||||
return AxisAlignedBB.getAABBPool().getAABB(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
|
||||
}
|
||||
|
||||
public void sendTankUpdate()
|
||||
{
|
||||
if (this.getInternalTank() != null)
|
||||
{
|
||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
|
||||
}
|
||||
}
|
||||
public int getSubID()
|
||||
{
|
||||
return this.colorID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox()
|
||||
{
|
||||
return AxisAlignedBB.getAABBPool().getAABB(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
|
||||
}
|
||||
public void setSubID(int id)
|
||||
{
|
||||
this.colorID = id;
|
||||
}
|
||||
|
||||
public int getSubID()
|
||||
{
|
||||
return this.colorID;
|
||||
}
|
||||
public static boolean canRenderSide(byte renderSides, ForgeDirection direction)
|
||||
{
|
||||
return (renderSides & (1 << direction.ordinal())) != 0;
|
||||
}
|
||||
|
||||
public void setSubID(int id)
|
||||
{
|
||||
this.colorID = id;
|
||||
}
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canRenderSide(byte renderSides, ForgeDirection direction)
|
||||
{
|
||||
return (renderSides & (1 << direction.ordinal())) != 0;
|
||||
}
|
||||
@Override
|
||||
public FluidTank getInternalTank()
|
||||
{
|
||||
if (this.tank == null)
|
||||
{
|
||||
this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
||||
}
|
||||
return this.tank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTank getInternalTank()
|
||||
{
|
||||
if (this.tank == null)
|
||||
{
|
||||
this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
||||
}
|
||||
return this.tank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
|
||||
{
|
||||
if (tool == EnumTools.PIPE_GUAGE)
|
||||
{
|
||||
return this.getNetwork().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
|
||||
{
|
||||
if (tool == EnumTools.PIPE_GUAGE)
|
||||
{
|
||||
return this.getNetwork().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.Set;
|
|||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import resonantinduction.api.fluid.IFluidPart;
|
||||
import resonantinduction.api.fluid.IFluidConnector;
|
||||
import resonantinduction.mechanical.fluid.network.FluidNetwork;
|
||||
|
||||
/** Network that handles connected tanks
|
||||
|
@ -27,7 +27,7 @@ public class TankNetwork extends FluidNetwork
|
|||
else if (this.getConnectors().size() > 0)
|
||||
{
|
||||
fillStack = fillStack.copy();
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
for (IFluidConnector part : this.getConnectors())
|
||||
{
|
||||
part.getInternalTank().setFluid(null);
|
||||
if (part instanceof TileEntity && ((TileEntity) part).yCoord < lowestY)
|
||||
|
@ -43,13 +43,13 @@ public class TankNetwork extends FluidNetwork
|
|||
//TODO Add path finder to prevent filling when tanks are only connected at the top
|
||||
for (int y = lowestY; y <= highestY; y++)
|
||||
{
|
||||
Set<IFluidPart> parts = new LinkedHashSet<IFluidPart>();
|
||||
Set<IFluidConnector> parts = new LinkedHashSet<IFluidConnector>();
|
||||
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
for (IFluidConnector part : this.getConnectors())
|
||||
{
|
||||
if (part instanceof IFluidPart && ((TileEntity) part).yCoord == y)
|
||||
if (part instanceof IFluidConnector && ((TileEntity) part).yCoord == y)
|
||||
{
|
||||
parts.add((IFluidPart) part);
|
||||
parts.add((IFluidConnector) part);
|
||||
}
|
||||
}
|
||||
if (!parts.isEmpty())
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import resonantinduction.api.fluid.IFluidNetwork;
|
||||
import resonantinduction.api.fluid.IFluidPart;
|
||||
import resonantinduction.api.fluid.IFluidConnector;
|
||||
import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
|
||||
|
||||
public class TileTank extends TileFluidNetwork
|
||||
|
@ -43,7 +43,7 @@ public class TileTank extends TileFluidNetwork
|
|||
{
|
||||
if (tileEntity instanceof TileTank)
|
||||
{
|
||||
this.getNetwork().merge(((IFluidPart) tileEntity).getNetwork());
|
||||
this.getNetwork().merge(((IFluidConnector) tileEntity).getNetwork());
|
||||
this.setRenderSide(side, true);
|
||||
connectedBlocks[side.ordinal()] = tileEntity;
|
||||
}
|
||||
|
|
|
@ -479,4 +479,16 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
return new universalelectricity.api.vector.Vector3(this.x() + direction.offsetX, this.y() + direction.offsetY, this.z() + direction.offsetZ).getTileEntity(this.world()) instanceof IMechanicalConnector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClockwise()
|
||||
{
|
||||
return isClockwise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(boolean isClockwise)
|
||||
{
|
||||
this.isClockwise = isClockwise;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,4 +15,8 @@ public interface IMechanical extends IConnectable
|
|||
* @return Amount of energy that was accepted by the block.
|
||||
*/
|
||||
public long onReceiveEnergy(ForgeDirection from, long torque, float angularVelocity, boolean doReceive);
|
||||
|
||||
public boolean isClockwise();
|
||||
|
||||
public void setRotation(boolean isClockwise);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ public class TileMechanical extends TileAdvanced implements IMechanicalConnector
|
|||
|
||||
private IMechanicalNetwork network;
|
||||
|
||||
private boolean isClockwise = false;
|
||||
|
||||
@Override
|
||||
public long onReceiveEnergy(ForgeDirection from, long torque, float angularVelocity, boolean doReceive)
|
||||
{
|
||||
|
@ -56,4 +58,16 @@ public class TileMechanical extends TileAdvanced implements IMechanicalConnector
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClockwise()
|
||||
{
|
||||
return isClockwise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(boolean isClockwise)
|
||||
{
|
||||
this.isClockwise = isClockwise;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public class BlockGrinderWheel extends BlockRIRotatable implements ITileEntityPr
|
|||
{
|
||||
super("grindingWheel", Settings.getNextBlockID());
|
||||
this.setBlockBounds(0.05f, 0.05f, 0.05f, 0.95f, 0.95f, 0.95f);
|
||||
rotationMask = 0b111111;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -33,7 +33,7 @@ public class RenderGrinderWheel extends TileEntitySpecialRenderer
|
|||
TileGrinderWheel tile = (TileGrinderWheel) t;
|
||||
glPushMatrix();
|
||||
glTranslatef((float) x + 0.5F, (float) y + 0.5f, (float) z + 0.5F);
|
||||
glScalef(0.5f, 0.5f, 0.52f);
|
||||
glScalef(0.5f, 0.5f, 0.515f);
|
||||
glRotatef((float) Math.toDegrees(tile.getNetwork().getRotation()), 0, 0, 1);
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
|
||||
MODEL.renderAll();
|
||||
|
|
|
@ -81,4 +81,16 @@ public class TraitMechanical extends TileMultipart implements IMechanical
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClockwise()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(boolean isClockwise)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,4 +113,16 @@ public class TraitMechanicalConnector extends TileMultipart implements IMechanic
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClockwise()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(boolean isClockwise)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue