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;
@ -214,10 +219,14 @@ public class TileGrate extends TileAdvanced implements IFluidHandler
* @return Amount filled. * @return Amount filled.
*/ */
public int tryFill(int amount, int tries) public int tryFill(int amount, int tries)
{
int filled = 0;
if (amount >= FluidContainerRegistry.BUCKET_VOLUME)
{ {
for (int i = 0; i < tries; i++) for (int i = 0; i < tries; i++)
{ {
ComparableVector next = this.workingNodes.poll(); ComparableVector next = workingNodes.poll();
if (next == null) if (next == null)
{ {
@ -231,8 +240,7 @@ public class TileGrate extends TileAdvanced implements IFluidHandler
return 0; return 0;
} }
int filled = FluidUtility.fillBlock(TileGrate.this.worldObj, next.position, new FluidStack(fluidType, amount), true); filled += FluidUtility.fillBlock(TileGrate.this.worldObj, next.position, new FluidStack(fluidType, amount), true);
amount -= filled;
if (filled > 0) if (filled > 0)
{ {
@ -240,8 +248,9 @@ public class TileGrate extends TileAdvanced implements IFluidHandler
return filled; return filled;
} }
} }
}
return 0; return filled;
} }
/** /**