Grate now buffers enough fluid to fill

This commit is contained in:
Calclavia 2014-02-24 20:25:50 +08:00
parent 1ab181ff3f
commit 10f60b59cc
2 changed files with 32 additions and 23 deletions

View file

@ -26,7 +26,7 @@ public class RenderPump extends TileEntitySpecialRenderer
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5); GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
GL11.glRotatef(90, 0, 1, 0); GL11.glRotatef(-90, 0, 1, 0);
if (tile.worldObj != null) if (tile.worldObj != null)
RenderUtility.rotateBlockBasedOnDirection(tile.getDirection()); RenderUtility.rotateBlockBasedOnDirection(tile.getDirection());

View file

@ -7,8 +7,10 @@ import java.util.PriorityQueue;
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.FluidTankInfo; import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import universalelectricity.api.vector.Vector3; import universalelectricity.api.vector.Vector3;
@ -17,6 +19,7 @@ import calclavia.lib.utility.FluidUtility;
public class TileGrate extends TileAdvanced implements IFluidHandler public class TileGrate extends TileAdvanced implements IFluidHandler
{ {
protected FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
private GratePathfinder gratePath; private GratePathfinder gratePath;
@Override @Override
@ -58,15 +61,17 @@ public class TileGrate extends TileAdvanced implements IFluidHandler
@Override @Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{ {
if (resource != null && resource.amount > 0) tank.fill(resource, doFill);
if (tank.getFluidAmount() > 0)
{ {
if (gratePath == null) if (gratePath == null)
{ {
gratePath = new GratePathfinder(true); gratePath = new GratePathfinder(true);
gratePath.startFill(new Vector3(this), resource.fluidID); gratePath.startFill(new Vector3(this), tank.getFluid().getFluid().getID());
} }
return gratePath.tryFill(resource.amount, 2000); return tank.drain(gratePath.tryFill(tank.getFluidAmount(), 2000), true).amount;
} }
return 0; return 0;
@ -215,33 +220,37 @@ public class TileGrate extends TileAdvanced implements IFluidHandler
*/ */
public int tryFill(int amount, int tries) public int tryFill(int amount, int tries)
{ {
for (int i = 0; i < tries; i++) int filled = 0;
if (amount >= FluidContainerRegistry.BUCKET_VOLUME)
{ {
ComparableVector next = this.workingNodes.poll(); for (int i = 0; i < tries; i++)
if (next == null)
{ {
TileGrate.this.resetPath(); ComparableVector next = workingNodes.poll();
return 0;
}
if (!isConnected(next.position)) if (next == null)
{ {
TileGrate.this.resetPath(); TileGrate.this.resetPath();
return 0; return 0;
} }
int filled = FluidUtility.fillBlock(TileGrate.this.worldObj, next.position, new FluidStack(fluidType, amount), true); if (!isConnected(next.position))
amount -= filled; {
TileGrate.this.resetPath();
return 0;
}
if (filled > 0) filled += FluidUtility.fillBlock(TileGrate.this.worldObj, next.position, new FluidStack(fluidType, amount), true);
{
addNextFill(next); if (filled > 0)
return filled; {
addNextFill(next);
return filled;
}
} }
} }
return 0; return filled;
} }
/** /**