From 25318e36cf2162d81b4abee330206bdc16d9883a Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Fri, 10 Feb 2017 00:38:09 +0100 Subject: [PATCH] sanitize fluid implementation for #3495 --- .../buildcraft/core/lib/utils/BlockUtils.java | 35 +++++++++++-------- .../buildcraft/core/lib/utils/FluidUtils.java | 9 ++--- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/common/buildcraft/core/lib/utils/BlockUtils.java b/common/buildcraft/core/lib/utils/BlockUtils.java index c780c302..108749db 100644 --- a/common/buildcraft/core/lib/utils/BlockUtils.java +++ b/common/buildcraft/core/lib/utils/BlockUtils.java @@ -224,14 +224,20 @@ public final class BlockUtils { } public static boolean isFullFluidBlock(Block block, World world, int x, int y, int z) { - if (block instanceof IFluidBlock || block instanceof BlockStaticLiquid) { + if (block instanceof IFluidBlock) { + return ((IFluidBlock) block).getFilledPercentage(world, x, y, z) == 1.0f; + } else if (block instanceof BlockStaticLiquid) { return world.getBlockMetadata(x, y, z) == 0; } return false; } public static Fluid getFluid(Block block) { - return FluidRegistry.lookupFluidForBlock(block); + if (block instanceof IFluidBlock) { + return ((IFluidBlock) block).getFluid(); + } else { + return FluidRegistry.lookupFluidForBlock(block); + } } public static FluidStack drainBlock(World world, int x, int y, int z, boolean doDrain) { @@ -239,18 +245,17 @@ public final class BlockUtils { } public static FluidStack drainBlock(Block block, World world, int x, int y, int z, boolean doDrain) { - Fluid fluid = FluidRegistry.lookupFluidForBlock(block); + if (block instanceof IFluidBlock) { + IFluidBlock fluidBlock = (IFluidBlock) block; + if (!fluidBlock.canDrain(world, x, y, z)) { + return null; + } + return fluidBlock.drain(world, x, y, z, doDrain); + } else { + Fluid fluid = getFluid(block); - if (fluid != null && FluidRegistry.isFluidRegistered(fluid)) { - int meta = world.getBlockMetadata(x, y, z); - - if (block instanceof IFluidBlock) { - IFluidBlock fluidBlock = (IFluidBlock) block; - if (!fluidBlock.canDrain(world, x, y, z)) { - return null; - } - return fluidBlock.drain(world, x, y, z, doDrain); - } else { + if (fluid != null && FluidRegistry.isFluidRegistered(fluid)) { + int meta = world.getBlockMetadata(x, y, z); if (meta != 0) { return null; } @@ -260,9 +265,9 @@ public final class BlockUtils { } return new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME); + } else { + return null; } - } else { - return null; } } diff --git a/common/buildcraft/core/lib/utils/FluidUtils.java b/common/buildcraft/core/lib/utils/FluidUtils.java index bda8da0f..e8326f20 100644 --- a/common/buildcraft/core/lib/utils/FluidUtils.java +++ b/common/buildcraft/core/lib/utils/FluidUtils.java @@ -28,10 +28,11 @@ public final class FluidUtils { if (b != null) { if (b instanceof IFluidBlock && ((IFluidBlock) b).getFluid() != null) { return new FluidStack(((IFluidBlock) b).getFluid(), 1000); - } else if (b == Blocks.lava) { - return new FluidStack(FluidRegistry.getFluid("lava"), 1000); - } else if (b == Blocks.water) { - return new FluidStack(FluidRegistry.getFluid("water"), 1000); + } else { + Fluid f = FluidRegistry.lookupFluidForBlock(b); + if (f != null && FluidRegistry.isFluidRegistered(f)) { + return new FluidStack(f, 1000); + } } } }