Fixed #409 - Gutter bucket fill and drain

This commit is contained in:
Calclavia 2014-03-11 19:30:07 +08:00
parent dd3e1cc8d4
commit 1e0492eb53
7 changed files with 57 additions and 43 deletions

View file

@ -3,11 +3,8 @@ package resonantinduction.archaic.fluid.gutter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -18,11 +15,11 @@ import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom; import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.IFluidTank;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -205,7 +202,36 @@ public class TileGutter extends TilePressureNode
if (!world().isRemote) if (!world().isRemote)
{ {
return FluidUtility.playerActivatedFluidItem(world(), x(), y(), z(), player, side); ArrayList<IFluidTank> tanks = new ArrayList<IFluidTank>();
synchronized (node.getGrid().getNodes())
{
for (Object check : node.getGrid().getNodes())
{
if (check instanceof PressureNode)
{
tanks.add(((PressureNode) check).parent.getPressureTank());
}
}
}
if (FluidUtility.playerActivatedFluidItem(tanks, player, side))
{
synchronized (node.getGrid().getNodes())
{
for (Object check : node.getGrid().getNodes())
{
if (check instanceof PressureNode)
{
((PressureNode) check).parent.onFluidChanged();
}
}
}
return true;
}
return false;
} }
return true; return true;
@ -241,39 +267,12 @@ public class TileGutter extends TilePressureNode
{ {
if (!resource.getFluid().isGaseous()) if (!resource.getFluid().isGaseous())
{ {
int totalFill = 0; return super.fill(from, resource, doFill);
int trials = 0;
FluidStack fillStack = resource.copy();
// Handle overflow.
do
{
int filled = super.fill(from, fillStack, doFill);
totalFill += filled;
int remain = fillStack.amount - filled;
fillStack.amount -= filled;
node.update(1 / 20f);
trials++;
}
while (fillStack.amount > totalFill && trials < 20);
return totalFill;
} }
return 0; return 0;
} }
@Override
public FluidTank getInternalTank()
{
if (tank == null)
{
tank = new FluidTank(2 * FluidContainerRegistry.BUCKET_VOLUME);
}
return tank;
}
@Override @Override
public boolean canFill(ForgeDirection from, Fluid fluid) public boolean canFill(ForgeDirection from, Fluid fluid)
{ {

View file

@ -271,4 +271,9 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, PressureNode, IPr
node.maxFlowRate = getMaterial().maxFlowRate; node.maxFlowRate = getMaterial().maxFlowRate;
node.maxPressure = getMaterial().maxPressure; node.maxPressure = getMaterial().maxPressure;
} }
@Override
public void onFluidChanged()
{
}
} }

View file

@ -163,4 +163,10 @@ public class TilePump extends TileMechanical implements IPressureNodeProvider, I
return super.getNode(nodeType, from); return super.getNode(nodeType, from);
} }
@Override
public void onFluidChanged()
{
}
} }

View file

@ -69,16 +69,16 @@ public abstract class TileFluidNode extends TileBase implements IPacketReceiverW
{ {
if (id == PACKET_DESCRIPTION) if (id == PACKET_DESCRIPTION)
{ {
this.colorID = data.readInt(); colorID = data.readInt();
this.renderSides = data.readByte(); renderSides = data.readByte();
this.tank = new FluidTank(data.readInt()); tank = new FluidTank(data.readInt());
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data)); getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
return true; return true;
} }
else if (id == PACKET_RENDER) else if (id == PACKET_RENDER)
{ {
this.colorID = data.readInt(); colorID = data.readInt();
this.renderSides = data.readByte(); renderSides = data.readByte();
return true; return true;
} }
else if (id == PACKET_TANK) else if (id == PACKET_TANK)

View file

@ -23,7 +23,6 @@ public abstract class TilePressureNode extends TileFluidNode implements IPressur
public TilePressureNode(Material material) public TilePressureNode(Material material)
{ {
super(material); super(material);
getInternalTank().setCapacity(FluidContainerRegistry.BUCKET_VOLUME);
} }
@Override @Override

View file

@ -6,5 +6,7 @@ import resonantinduction.core.grid.INodeProvider;
public interface IPressureNodeProvider extends INodeProvider, IFluidHandler public interface IPressureNodeProvider extends INodeProvider, IFluidHandler
{ {
FluidTank getPressureTank(); public FluidTank getPressureTank();
public void onFluidChanged();
} }

View file

@ -36,8 +36,11 @@ public class PressureNode extends Node<IPressureNodeProvider, TickingGrid, Objec
@Override @Override
public void update(float deltaTime) public void update(float deltaTime)
{ {
updatePressure(); if (!world().isRemote)
distribute(); {
updatePressure();
distribute();
}
} }
protected void updatePressure() protected void updatePressure()