Implemented gravity in pipes when there is no pressure
This commit is contained in:
parent
1a816899d0
commit
e57004a6fd
1 changed files with 228 additions and 214 deletions
|
@ -31,265 +31,279 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode, IPressureNodeProvider> implements IPressureNodeProvider, TSlottedPart, JNormalOcclusion, IHollowConnect
|
public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode, IPressureNodeProvider> implements IPressureNodeProvider, TSlottedPart, JNormalOcclusion, IHollowConnect
|
||||||
{
|
{
|
||||||
protected final FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
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 EvictingList<Integer> averageTankData = new EvictingList<Integer>(20);
|
||||||
private boolean markPacket = true;
|
private boolean markPacket = true;
|
||||||
|
|
||||||
public PartPipe()
|
public PartPipe()
|
||||||
{
|
{
|
||||||
super(null);
|
super(null);
|
||||||
material = EnumPipeMaterial.values()[0];
|
material = EnumPipeMaterial.values()[0];
|
||||||
requiresInsulation = false;
|
requiresInsulation = false;
|
||||||
|
|
||||||
node = new FluidPressureNode(this)
|
node = new FluidPressureNode(this)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void doRecache()
|
public void doRecache()
|
||||||
{
|
{
|
||||||
|
|
||||||
connections.clear();
|
connections.clear();
|
||||||
|
|
||||||
if (world() != null)
|
if (world() != null)
|
||||||
{
|
{
|
||||||
byte previousConnections = getAllCurrentConnections();
|
byte previousConnections = getAllCurrentConnections();
|
||||||
currentConnections = 0;
|
currentConnections = 0;
|
||||||
|
|
||||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
TileEntity tile = position().translate(dir).getTileEntity(world());
|
TileEntity tile = position().translate(dir).getTileEntity(world());
|
||||||
|
|
||||||
if (tile instanceof IFluidHandler)
|
if (tile instanceof IFluidHandler)
|
||||||
{
|
{
|
||||||
if (tile instanceof IPressureNodeProvider)
|
if (tile instanceof IPressureNodeProvider)
|
||||||
{
|
{
|
||||||
FluidPressureNode check = ((IPressureNodeProvider) tile).getNode(FluidPressureNode.class, dir.getOpposite());
|
FluidPressureNode check = ((IPressureNodeProvider) tile).getNode(FluidPressureNode.class, dir.getOpposite());
|
||||||
|
|
||||||
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
|
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
|
||||||
{
|
{
|
||||||
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
|
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
|
||||||
connections.put(check, dir);
|
connections.put(check, dir);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (canConnect(dir, tile))
|
else if (canConnect(dir, tile))
|
||||||
{
|
{
|
||||||
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
|
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
|
||||||
connections.put(tile, dir);
|
connections.put(tile, dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Only send packet updates if visuallyConnected changed. */
|
/** Only send packet updates if visuallyConnected changed. */
|
||||||
if (!world().isRemote && previousConnections != currentConnections)
|
if (!world().isRemote && previousConnections != currentConnections)
|
||||||
{
|
{
|
||||||
sendConnectionUpdate();
|
sendConnectionUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canConnect(ForgeDirection from, Object source)
|
public boolean canConnect(ForgeDirection from, Object source)
|
||||||
{
|
{
|
||||||
if (!isBlockedOnSide(from))
|
if (!isBlockedOnSide(from))
|
||||||
{
|
{
|
||||||
if (source instanceof FluidPressureNode)
|
if (source instanceof FluidPressureNode)
|
||||||
{
|
{
|
||||||
FluidPressureNode otherNode = (FluidPressureNode) source;
|
FluidPressureNode otherNode = (FluidPressureNode) source;
|
||||||
|
|
||||||
if (otherNode.parent instanceof PartPipe)
|
if (otherNode.parent instanceof PartPipe)
|
||||||
{
|
{
|
||||||
PartPipe otherPipe = (PartPipe) otherNode.parent;
|
PartPipe otherPipe = (PartPipe) otherNode.parent;
|
||||||
|
|
||||||
if (!otherPipe.isBlockedOnSide(from.getOpposite()) && getMaterial() == otherPipe.getMaterial())
|
if (!otherPipe.isBlockedOnSide(from.getOpposite()) && getMaterial() == otherPipe.getMaterial())
|
||||||
{
|
{
|
||||||
return getColor() == otherPipe.getColor() || (getColor() == DEFAULT_COLOR || otherPipe.getColor() == DEFAULT_COLOR);
|
return getColor() == otherPipe.getColor() || (getColor() == DEFAULT_COLOR || otherPipe.getColor() == DEFAULT_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.canConnect(from, source) || source instanceof IFluidHandler;
|
return super.canConnect(from, source) || source instanceof IFluidHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public int getPressure(ForgeDirection dir)
|
||||||
|
{
|
||||||
|
if (super.getPressure(dir) <= 0)
|
||||||
|
{
|
||||||
|
if (dir == ForgeDirection.UP)
|
||||||
|
return -2;
|
||||||
|
|
||||||
@Override
|
if (dir == ForgeDirection.DOWN)
|
||||||
public void setMaterial(int i)
|
return +2;
|
||||||
{
|
}
|
||||||
setMaterial(EnumPipeMaterial.values()[i]);
|
return super.getPressure(dir);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMaterial(EnumPipeMaterial material)
|
public void setMaterial(int i)
|
||||||
{
|
{
|
||||||
this.material = material;
|
setMaterial(EnumPipeMaterial.values()[i]);
|
||||||
node.maxFlowRate = getMaterial().maxFlowRate;
|
|
||||||
node.maxPressure = getMaterial().maxPressure;
|
|
||||||
tank.setCapacity(node.maxFlowRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public String getType()
|
|
||||||
{
|
|
||||||
return "resonant_induction_pipe";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void setMaterial(EnumPipeMaterial material)
|
||||||
{
|
{
|
||||||
super.update();
|
this.material = material;
|
||||||
|
node.maxFlowRate = getMaterial().maxFlowRate;
|
||||||
|
node.maxPressure = getMaterial().maxPressure;
|
||||||
|
tank.setCapacity(node.maxFlowRate);
|
||||||
|
}
|
||||||
|
|
||||||
averageTankData.add(tank.getFluidAmount());
|
@Override
|
||||||
|
public String getType()
|
||||||
|
{
|
||||||
|
return "resonant_induction_pipe";
|
||||||
|
}
|
||||||
|
|
||||||
if (!world().isRemote && markPacket)
|
@Override
|
||||||
{
|
public void update()
|
||||||
sendFluidUpdate();
|
{
|
||||||
markPacket = false;
|
super.update();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendFluidUpdate()
|
averageTankData.add(tank.getFluidAmount());
|
||||||
{
|
|
||||||
NBTTagCompound nbt = new NBTTagCompound();
|
|
||||||
|
|
||||||
int averageAmount = 0;
|
if (!world().isRemote && markPacket)
|
||||||
|
{
|
||||||
|
sendFluidUpdate();
|
||||||
|
markPacket = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (averageTankData.size() > 0)
|
public void sendFluidUpdate()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < averageTankData.size(); i++)
|
NBTTagCompound nbt = new NBTTagCompound();
|
||||||
{
|
|
||||||
averageAmount += averageTankData.get(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
averageAmount /= averageTankData.size();
|
int averageAmount = 0;
|
||||||
}
|
|
||||||
|
|
||||||
FluidTank tempTank = tank.getFluid() != null ? new FluidTank(tank.getFluid().getFluid(), averageAmount, tank.getCapacity()) : new FluidTank(tank.getCapacity());
|
if (averageTankData.size() > 0)
|
||||||
tempTank.writeToNBT(nbt);
|
{
|
||||||
tile().getWriteStream(this).writeByte(3).writeInt(tank.getCapacity()).writeNBTTagCompound(nbt);
|
for (int i = 0; i < averageTankData.size(); i++)
|
||||||
}
|
{
|
||||||
|
averageAmount += averageTankData.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
averageAmount /= averageTankData.size();
|
||||||
public void read(MCDataInput packet, int packetID)
|
}
|
||||||
{
|
|
||||||
if (packetID == 3)
|
|
||||||
{
|
|
||||||
tank.setCapacity(packet.readInt());
|
|
||||||
tank.readFromNBT(packet.readNBTTagCompound());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
super.read(packet, packetID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
FluidTank tempTank = tank.getFluid() != null ? new FluidTank(tank.getFluid().getFluid(), averageAmount, tank.getCapacity()) : new FluidTank(tank.getCapacity());
|
||||||
@SideOnly(Side.CLIENT)
|
tempTank.writeToNBT(nbt);
|
||||||
public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass)
|
tile().getWriteStream(this).writeByte(3).writeInt(tank.getCapacity()).writeNBTTagCompound(nbt);
|
||||||
{
|
}
|
||||||
RenderPipe.INSTANCE.render(this, pos.x, pos.y, pos.z, frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ItemStack getItem()
|
public void read(MCDataInput packet, int packetID)
|
||||||
{
|
{
|
||||||
return new ItemStack(Mechanical.itemPipe, 1, getMaterialID());
|
if (packetID == 3)
|
||||||
}
|
{
|
||||||
|
tank.setCapacity(packet.readInt());
|
||||||
|
tank.readFromNBT(packet.readNBTTagCompound());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
super.read(packet, packetID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
@SideOnly(Side.CLIENT)
|
||||||
{
|
public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass)
|
||||||
if (!world().isRemote)
|
{
|
||||||
{
|
RenderPipe.INSTANCE.render(this, pos.x, pos.y, pos.z, frame);
|
||||||
if (doFill)
|
}
|
||||||
{
|
|
||||||
markPacket = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tank.fill(resource, doFill);
|
@Override
|
||||||
}
|
protected ItemStack getItem()
|
||||||
return 0;
|
{
|
||||||
}
|
return new ItemStack(Mechanical.itemPipe, 1, getMaterialID());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||||
{
|
{
|
||||||
return drain(from, resource.amount, doDrain);
|
if (!world().isRemote)
|
||||||
}
|
{
|
||||||
|
if (doFill)
|
||||||
|
{
|
||||||
|
markPacket = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
return tank.fill(resource, doFill);
|
||||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
}
|
||||||
{
|
return 0;
|
||||||
if (!world().isRemote)
|
}
|
||||||
{
|
|
||||||
if (doDrain)
|
|
||||||
{
|
|
||||||
markPacket = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tank.drain(maxDrain, doDrain);
|
@Override
|
||||||
}
|
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||||
return null;
|
{
|
||||||
}
|
return drain(from, resource.amount, doDrain);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canFill(ForgeDirection from, Fluid fluid)
|
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||||
{
|
{
|
||||||
return true;
|
if (!world().isRemote)
|
||||||
}
|
{
|
||||||
|
if (doDrain)
|
||||||
|
{
|
||||||
|
markPacket = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
return tank.drain(maxDrain, doDrain);
|
||||||
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
}
|
||||||
{
|
return null;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
public boolean canFill(ForgeDirection from, Fluid fluid)
|
||||||
{
|
{
|
||||||
return new FluidTankInfo[] { tank.getInfo() };
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidTank getPressureTank()
|
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
||||||
{
|
{
|
||||||
return tank;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawBreaking(RenderBlocks renderBlocks)
|
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
||||||
{
|
{
|
||||||
CCRenderState.reset();
|
return new FluidTankInfo[] { tank.getInfo() };
|
||||||
RenderUtils.renderBlock(sides[6], 0, new Translation(x(), y(), z()), new IconTransformation(ResonantInduction.blockMachinePart.getIcon(0, 0)), null);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(NBTTagCompound nbt)
|
public FluidTank getPressureTank()
|
||||||
{
|
{
|
||||||
super.save(nbt);
|
return tank;
|
||||||
tank.writeToNBT(nbt);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(NBTTagCompound nbt)
|
public void drawBreaking(RenderBlocks renderBlocks)
|
||||||
{
|
{
|
||||||
super.load(nbt);
|
CCRenderState.reset();
|
||||||
tank.readFromNBT(nbt);
|
RenderUtils.renderBlock(sides[6], 0, new Translation(x(), y(), z()), new IconTransformation(ResonantInduction.blockMachinePart.getIcon(0, 0)), null);
|
||||||
node.maxFlowRate = getMaterial().maxFlowRate;
|
}
|
||||||
node.maxPressure = getMaterial().maxPressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFluidChanged()
|
public void save(NBTTagCompound nbt)
|
||||||
{
|
{
|
||||||
}
|
super.save(nbt);
|
||||||
|
tank.writeToNBT(nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
|
super.load(nbt);
|
||||||
|
tank.readFromNBT(nbt);
|
||||||
|
node.maxFlowRate = getMaterial().maxFlowRate;
|
||||||
|
node.maxPressure = getMaterial().maxPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFluidChanged()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue