sanitize fluid implementation for #3495
This commit is contained in:
parent
dc7b112033
commit
25318e36cf
2 changed files with 25 additions and 19 deletions
|
@ -224,14 +224,20 @@ public final class BlockUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFullFluidBlock(Block block, World world, int x, int y, int z) {
|
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 world.getBlockMetadata(x, y, z) == 0;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Fluid getFluid(Block block) {
|
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) {
|
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) {
|
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)) {
|
if (fluid != null && FluidRegistry.isFluidRegistered(fluid)) {
|
||||||
int meta = world.getBlockMetadata(x, y, z);
|
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 (meta != 0) {
|
if (meta != 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -260,9 +265,9 @@ public final class BlockUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
|
return new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,11 @@ public final class FluidUtils {
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
if (b instanceof IFluidBlock && ((IFluidBlock) b).getFluid() != null) {
|
if (b instanceof IFluidBlock && ((IFluidBlock) b).getFluid() != null) {
|
||||||
return new FluidStack(((IFluidBlock) b).getFluid(), 1000);
|
return new FluidStack(((IFluidBlock) b).getFluid(), 1000);
|
||||||
} else if (b == Blocks.lava) {
|
} else {
|
||||||
return new FluidStack(FluidRegistry.getFluid("lava"), 1000);
|
Fluid f = FluidRegistry.lookupFluidForBlock(b);
|
||||||
} else if (b == Blocks.water) {
|
if (f != null && FluidRegistry.isFluidRegistered(f)) {
|
||||||
return new FluidStack(FluidRegistry.getFluid("water"), 1000);
|
return new FluidStack(f, 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue