From c20acfc473d87d9fbb0661fc1ac1577bf20e0256 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Tue, 9 Jul 2013 23:44:59 -0400 Subject: [PATCH] added to fluid Helper --- .../core/hydraulic/helpers/FluidHelper.java | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/src/minecraft/dark/core/hydraulic/helpers/FluidHelper.java b/src/minecraft/dark/core/hydraulic/helpers/FluidHelper.java index 367b9f47..ce0985ee 100644 --- a/src/minecraft/dark/core/hydraulic/helpers/FluidHelper.java +++ b/src/minecraft/dark/core/hydraulic/helpers/FluidHelper.java @@ -4,6 +4,7 @@ import universalelectricity.core.vector.Vector3; import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidBlock; @@ -24,7 +25,11 @@ public class FluidHelper /** Gets a fluid from blockID */ public static Fluid getFluidFromBlockID(int id) { - if (id == Block.waterStill.blockID || id == Block.waterMoving.blockID) + if (Block.blocksList[id] instanceof IFluidBlock) + { + return ((IFluidBlock) Block.blocksList[id]).getFluid(); + } + else if (id == Block.waterStill.blockID || id == Block.waterMoving.blockID) { return FluidRegistry.getFluid("water"); } @@ -32,19 +37,59 @@ public class FluidHelper { return FluidRegistry.getFluid("lava"); } - else if (Block.blocksList[id] instanceof IFluidBlock) - { - return ((IFluidBlock) Block.blocksList[id]).getFluid(); - } return null; } public static FluidStack getStack(FluidStack stack, int amount) { - if(stack != null) + if (stack != null) { return new FluidStack(stack.getFluid(), amount); } return stack; } + + public static FluidStack drainBlock(World world, Vector3 vector, boolean doDrain) + { + Block block = Block.blocksList[vector.getBlockID(world)]; + if (block != null) + { + if (block instanceof IFluidBlock && ((IFluidBlock) block).canDrain(world, vector.intX(), vector.intY(), vector.intZ())) + { + return ((IFluidBlock) block).drain(world, vector.intX(), vector.intY(), vector.intZ(), doDrain); + } + else if (block.blockID == Block.waterStill.blockID && vector.getBlockMetadata(world) == 0) + { + if (doDrain) + { + vector.setBlock(world, 0); + } + return new FluidStack(FluidRegistry.getFluid("water"), FluidContainerRegistry.BUCKET_VOLUME); + } + else if (block.blockID == Block.lavaStill.blockID && vector.getBlockMetadata(world) == 0) + { + if (doDrain) + { + vector.setBlock(world, 0); + } + return new FluidStack(FluidRegistry.getFluid("lava"), FluidContainerRegistry.BUCKET_VOLUME); + } + + } + return null; + } + + public static boolean isFillable(World world, Vector3 node) + { + Block block = Block.blocksList[node.getBlockID(world)]; + if ((block.blockID == Block.waterStill.blockID || block.blockID == Block.waterMoving.blockID) && node.getBlockMetadata(world) != 0) + { + return true; + } + else if ((block.blockID == Block.lavaStill.blockID || block.blockID == Block.lavaMoving.blockID) && node.getBlockMetadata(world) != 0) + { + return true; + } + return false; + } }