Moved pipe's pressure node to its own class file
This commit is contained in:
parent
dd9b37e997
commit
3f032cf721
2 changed files with 103 additions and 78 deletions
|
@ -11,6 +11,7 @@ import net.minecraftforge.fluids.FluidStack;
|
|||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import resonant.api.grid.INode;
|
||||
import resonant.lib.type.EvictingList;
|
||||
import resonant.lib.utility.WorldUtility;
|
||||
import resonantinduction.core.ResonantInduction;
|
||||
|
@ -29,12 +30,13 @@ import codechicken.multipart.TSlottedPart;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/** Fluid transport pipe
|
||||
*
|
||||
* @author Calclavia, Darkguardsman */
|
||||
public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode, IPressureNodeProvider> implements IPressureNodeProvider, TSlottedPart, JNormalOcclusion, IHollowConnect
|
||||
{
|
||||
protected final FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
||||
/**
|
||||
* Computes the average fluid for client to render.
|
||||
*/
|
||||
/** Computes the average fluid for client to render. */
|
||||
private EvictingList<Integer> averageTankData = new EvictingList<Integer>(20);
|
||||
private boolean markPacket = true;
|
||||
|
||||
|
@ -43,81 +45,7 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
|
|||
super(null);
|
||||
material = EnumPipeMaterial.values()[0];
|
||||
requiresInsulation = false;
|
||||
|
||||
node = new FluidPressureNode(this)
|
||||
{
|
||||
@Override
|
||||
public void doRecache()
|
||||
{
|
||||
connections.clear();
|
||||
|
||||
if (world() != null)
|
||||
{
|
||||
byte previousConnections = getAllCurrentConnections();
|
||||
currentConnections = 0;
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = position().translate(dir).getTileEntity(world());
|
||||
|
||||
if (tile instanceof IFluidHandler)
|
||||
{
|
||||
if (tile instanceof IPressureNodeProvider)
|
||||
{
|
||||
FluidPressureNode check = (FluidPressureNode) ((IPressureNodeProvider) tile).getNode(FluidPressureNode.class, dir.getOpposite());
|
||||
|
||||
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
|
||||
{
|
||||
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
|
||||
connections.put(check, dir);
|
||||
|
||||
}
|
||||
}
|
||||
else if (canConnect(dir, tile))
|
||||
{
|
||||
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
|
||||
connections.put(tile, dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Only send packet updates if visuallyConnected changed. */
|
||||
if (!world().isRemote && previousConnections != currentConnections)
|
||||
{
|
||||
sendConnectionUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
if (!isBlockedOnSide(from))
|
||||
{
|
||||
if (source instanceof FluidPressureNode)
|
||||
{
|
||||
FluidPressureNode otherNode = (FluidPressureNode) source;
|
||||
|
||||
if (otherNode.parent instanceof PartPipe)
|
||||
{
|
||||
PartPipe otherPipe = (PartPipe) otherNode.parent;
|
||||
|
||||
if (!otherPipe.isBlockedOnSide(from.getOpposite()) && getMaterial() == otherPipe.getMaterial())
|
||||
{
|
||||
return getColor() == otherPipe.getColor() || (getColor() == DEFAULT_COLOR || otherPipe.getColor() == DEFAULT_COLOR);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return super.canConnect(from, source) || source instanceof IFluidHandler;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
node = new PipePressureNode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -156,6 +84,7 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
|
|||
}
|
||||
}
|
||||
|
||||
/** Sends fluid level to the client to be used in the renderer */
|
||||
public void sendFluidUpdate()
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package resonantinduction.mechanical.fluid.pipe;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import resonant.api.grid.INode;
|
||||
import resonant.lib.utility.WorldUtility;
|
||||
import resonantinduction.core.grid.fluid.FluidPressureNode;
|
||||
import resonantinduction.core.grid.fluid.IPressureNodeProvider;
|
||||
|
||||
/** Pressure node for the pipe
|
||||
*
|
||||
* @author Calclavia, Darkguardsman */
|
||||
public class PipePressureNode extends FluidPressureNode
|
||||
{
|
||||
public PipePressureNode(PartPipe parent)
|
||||
{
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public PartPipe pipe()
|
||||
{
|
||||
return (PartPipe) this.parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRecache()
|
||||
{
|
||||
connections.clear();
|
||||
|
||||
if (world() != null)
|
||||
{
|
||||
byte previousConnections = pipe().getAllCurrentConnections();
|
||||
pipe().currentConnections = 0;
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = position().translate(dir).getTileEntity(world());
|
||||
|
||||
if (tile instanceof IFluidHandler)
|
||||
{
|
||||
if (tile instanceof IPressureNodeProvider)
|
||||
{
|
||||
INode check = ((IPressureNodeProvider) tile).getNode(FluidPressureNode.class, dir.getOpposite());
|
||||
|
||||
if (check instanceof FluidPressureNode && canConnect(dir, check) && ((FluidPressureNode) check).canConnect(dir.getOpposite(), this))
|
||||
{
|
||||
pipe().currentConnections = WorldUtility.setEnableSide(pipe().currentConnections, dir, true);
|
||||
connections.put(check, dir);
|
||||
|
||||
}
|
||||
}
|
||||
else if (canConnect(dir, tile))
|
||||
{
|
||||
pipe().currentConnections = WorldUtility.setEnableSide(pipe().currentConnections, dir, true);
|
||||
connections.put(tile, dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Only send packet updates if visuallyConnected changed. */
|
||||
if (!world().isRemote && previousConnections != pipe().currentConnections)
|
||||
{
|
||||
pipe().sendConnectionUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
if (!pipe().isBlockedOnSide(from))
|
||||
{
|
||||
if (source instanceof FluidPressureNode)
|
||||
{
|
||||
FluidPressureNode otherNode = (FluidPressureNode) source;
|
||||
|
||||
if (otherNode.parent instanceof PartPipe)
|
||||
{
|
||||
PartPipe otherPipe = (PartPipe) otherNode.parent;
|
||||
|
||||
if (!otherPipe.isBlockedOnSide(from.getOpposite()) && pipe().getMaterial() == otherPipe.getMaterial())
|
||||
{
|
||||
return pipe().getColor() == otherPipe.getColor() || (pipe().getColor() == pipe().DEFAULT_COLOR || otherPipe.getColor() == pipe().DEFAULT_COLOR);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return super.canConnect(from, source) || source instanceof IFluidHandler;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue