From acb6777ab5ed565d5358cbb38cc8106651c88934 Mon Sep 17 00:00:00 2001 From: LexManos Date: Tue, 16 Jul 2013 21:40:49 -0700 Subject: [PATCH] General code cleanup of Fluid system. Made Fluid icons and associated functions non-sided. --- .../minecraftforge/fluids/BlockFluidBase.java | 301 +++++++++--------- .../fluids/BlockFluidClassic.java | 279 ++++++++-------- .../fluids/BlockFluidFinite.java | 218 ++++++++----- common/net/minecraftforge/fluids/Fluid.java | 219 +++++-------- .../fluids/FluidContainerRegistry.java | 129 ++++---- .../net/minecraftforge/fluids/FluidEvent.java | 47 ++- .../fluids/FluidIdMapPacket.java | 20 +- .../minecraftforge/fluids/FluidRegistry.java | 74 ++--- .../net/minecraftforge/fluids/FluidStack.java | 93 +++--- .../net/minecraftforge/fluids/FluidTank.java | 131 +++++--- .../minecraftforge/fluids/FluidTankInfo.java | 14 +- .../minecraftforge/fluids/IFluidBlock.java | 5 +- .../fluids/IFluidContainerItem.java | 6 +- .../minecraftforge/fluids/IFluidHandler.java | 6 +- .../net/minecraftforge/fluids/IFluidTank.java | 6 +- .../fluids/ItemFluidContainer.java | 102 +++--- .../fluids/RenderBlockFluid.java | 192 ++++++----- .../fluids/TileFluidHandler.java | 40 +-- 18 files changed, 995 insertions(+), 887 deletions(-) diff --git a/common/net/minecraftforge/fluids/BlockFluidBase.java b/common/net/minecraftforge/fluids/BlockFluidBase.java index 529a6b2c2..5aea68e42 100644 --- a/common/net/minecraftforge/fluids/BlockFluidBase.java +++ b/common/net/minecraftforge/fluids/BlockFluidBase.java @@ -21,16 +21,17 @@ import net.minecraft.world.World; * @author King Lemming, OvermindDL1 * */ -public abstract class BlockFluidBase extends Block implements IFluidBlock { - +public abstract class BlockFluidBase extends Block implements IFluidBlock +{ protected final static Map defaultDisplacementIds = new HashMap(); - static { + static + { defaultDisplacementIds.put(Block.doorWood.blockID, false); defaultDisplacementIds.put(Block.doorIron.blockID, false); defaultDisplacementIds.put(Block.signPost.blockID, false); defaultDisplacementIds.put(Block.signWall.blockID, false); - defaultDisplacementIds.put(Block.reed.blockID, false); + defaultDisplacementIds.put(Block.reed.blockID, false); } protected Map displacementIds = new HashMap(); @@ -45,8 +46,8 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock { protected final String fluidName; - public BlockFluidBase(int id, Fluid fluid, Material material) { - + public BlockFluidBase(int id, Fluid fluid, Material material) + { super(id, material); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); this.setTickRandomly(true); @@ -61,43 +62,37 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock { displacementIds.putAll(defaultDisplacementIds); } - public BlockFluidBase setQuantaPerBlock(int quantaPerBlock) { - - if (quantaPerBlock > 16 || quantaPerBlock < 1) { - quantaPerBlock = 8; - } + public BlockFluidBase setQuantaPerBlock(int quantaPerBlock) + { + if (quantaPerBlock > 16 || quantaPerBlock < 1) quantaPerBlock = 8; this.quantaPerBlock = quantaPerBlock; this.quantaPerBlockFloat = quantaPerBlock; return this; } - public BlockFluidBase setDensity(int density) { - - if (density == 0) { - density = 1; - } + public BlockFluidBase setDensity(int density) + { + if (density == 0) density = 1; this.density = density; this.densityDir = density > 0 ? -1 : 1; return this; } - public BlockFluidBase setTickRate(int tickRate) { - - if (tickRate <= 0) { - tickRate = 20; - } + public BlockFluidBase setTickRate(int tickRate) + { + if (tickRate <= 0) tickRate = 20; this.tickRate = tickRate; return this; } - public BlockFluidBase setRenderPass(int renderPass) { - + public BlockFluidBase setRenderPass(int renderPass) + { this.renderPass = renderPass; return this; } - public BlockFluidBase setMaxScaledLight(int maxScaledLight) { - + public BlockFluidBase setMaxScaledLight(int maxScaledLight) + { this.maxScaledLight = maxScaledLight; return this; } @@ -105,22 +100,25 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock { /** * Returns true if the block at (x, y, z) is displaceable. Does not displace the block. */ - public boolean canDisplace(IBlockAccess world, int x, int y, int z) { + public boolean canDisplace(IBlockAccess world, int x, int y, int z) + { + if (world.isAirBlock(x, y, z)) return true; int bId = world.getBlockId(x, y, z); - if (bId == 0) { - return true; - } - if (bId == blockID) { + if (bId == blockID) + { return false; } - if (displacementIds.containsKey(bId)) { + + if (displacementIds.containsKey(bId)) + { return displacementIds.get(bId); } - Material material = Block.blocksList[bId].blockMaterial; - if (material.blocksMovement() || material == Material.portal) { + Material material = Block.blocksList[bId].blockMaterial; + if (material.blocksMovement() || material == Material.portal) + { return false; } return true; @@ -129,26 +127,32 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock { /** * Attempt to displace the block at (x, y, z), return true if it was displaced. */ - public boolean displaceIfPossible(World world, int x, int y, int z) { - - int bId = world.getBlockId(x, y, z); - - if (bId == 0) { + public boolean displaceIfPossible(World world, int x, int y, int z) + { + if (world.isAirBlock(x, y, z)) + { return true; } - if (bId == blockID) { + + int bId = world.getBlockId(x, y, z); + if (bId == blockID) + { return false; } - if (displacementIds.containsKey(bId)) { - if (displacementIds.get(bId)) { + + if (displacementIds.containsKey(bId)) + { + if (displacementIds.get(bId)) + { Block.blocksList[bId].dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0); return true; } return false; } - Material material = Block.blocksList[bId].blockMaterial; - if (material.blocksMovement() || material == Material.portal) { + Material material = Block.blocksList[bId].blockMaterial; + if (material.blocksMovement() || material == Material.portal) + { return false; } Block.blocksList[bId].dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0); @@ -164,60 +168,58 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock { /* BLOCK FUNCTIONS */ @Override - public void onBlockAdded(World world, int x, int y, int z) { - + public void onBlockAdded(World world, int x, int y, int z) + { world.scheduleBlockUpdate(x, y, z, blockID, tickRate); } @Override - public void onNeighborBlockChange(World world, int x, int y, int z, int blockId) { - + public void onNeighborBlockChange(World world, int x, int y, int z, int blockId) + { world.scheduleBlockUpdate(x, y, z, blockID, tickRate); } // Used to prevent updates on chunk generation @Override - public boolean func_82506_l() { - + public boolean func_82506_l() + { return false; } @Override - public boolean getBlocksMovement(IBlockAccess world, int x, int y, int z) { - + public boolean getBlocksMovement(IBlockAccess world, int x, int y, int z) + { return true; } @Override - public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { - + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) + { return null; } @Override - public int idDropped(int par1, Random par2Random, int par3) { - + public int idDropped(int par1, Random par2Random, int par3) + { return 0; } @Override - public int quantityDropped(Random par1Random) { - + public int quantityDropped(Random par1Random) + { return 0; } @Override - public int tickRate(World world) { - + public int tickRate(World world) + { return tickRate; } @Override - public void velocityToAddToEntity(World world, int x, int y, int z, Entity entity, Vec3 vec) { - - if (densityDir > 0) { - return; - } + public void velocityToAddToEntity(World world, int x, int y, int z, Entity entity, Vec3 vec) + { + if (densityDir > 0) return; Vec3 vec_flow = this.getFlowVector(world, x, y, z); vec.xCoord += vec_flow.xCoord * (quantaPerBlock * 4); vec.yCoord += vec_flow.yCoord * (quantaPerBlock * 4); @@ -225,9 +227,10 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock { } @Override - public int getLightValue(IBlockAccess world, int x, int y, int z) { - - if (maxScaledLight == 0) { + public int getLightValue(IBlockAccess world, int x, int y, int z) + { + if (maxScaledLight == 0) + { return super.getLightValue(world, x, y, z); } int data = world.getBlockMetadata(x, y, z); @@ -235,55 +238,55 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock { } @Override - public int getRenderType() { - + public int getRenderType() + { return FluidRegistry.renderIdFluid; } @Override - public boolean isOpaqueCube() { - + public boolean isOpaqueCube() + { return false; } @Override - public boolean renderAsNormalBlock() { - + public boolean renderAsNormalBlock() + { return false; } @Override - public float getBlockBrightness(IBlockAccess world, int x, int y, int z) { - + public float getBlockBrightness(IBlockAccess world, int x, int y, int z) + { float lightThis = world.getLightBrightness(x, y, z); float lightUp = world.getLightBrightness(x, y + 1, z); - return lightThis > lightUp ? lightThis : lightUp; } @Override - public int getMixedBrightnessForBlock(IBlockAccess world, int x, int y, int z) { - - int lightThis = world.getLightBrightnessForSkyBlocks(x, y, z, 0); - int lightUp = world.getLightBrightnessForSkyBlocks(x, y + 1, z, 0); + public int getMixedBrightnessForBlock(IBlockAccess world, int x, int y, int z) + { + int lightThis = world.getLightBrightnessForSkyBlocks(x, y, z, 0); + int lightUp = world.getLightBrightnessForSkyBlocks(x, y + 1, z, 0); int lightThisBase = lightThis & 255; - int lightUpBase = lightUp & 255; - int lightThisExt = lightThis >> 16 & 255; - int lightUpExt = lightUp >> 16 & 255; - - return (lightThisBase > lightUpBase ? lightThisBase : lightUpBase) | (lightThisExt > lightUpExt ? lightThisExt : lightUpExt) << 16; + int lightUpBase = lightUp & 255; + int lightThisExt = lightThis >> 16 & 255; + int lightUpExt = lightUp >> 16 & 255; + return (lightThisBase > lightUpBase ? lightThisBase : lightUpBase) | + ((lightThisExt > lightUpExt ? lightThisExt : lightUpExt) << 16); } @Override - public int getRenderBlockPass() { - + public int getRenderBlockPass() + { return renderPass; } @Override - public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) { - - if (world.getBlockId(x, y, z) != blockID) { + public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) + { + if (world.getBlockId(x, y, z) != blockID) + { return !world.isBlockOpaqueCube(x, y, z); } Material mat = world.getBlockMaterial(x, y, z); @@ -291,114 +294,105 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock { } /* FLUID FUNCTIONS */ - public static final int getDensity(IBlockAccess world, int x, int y, int z) { - + public static final int getDensity(IBlockAccess world, int x, int y, int z) + { Block block = Block.blocksList[world.getBlockId(x, y, z)]; - - if (!(block instanceof BlockFluidBase)) { + if (!(block instanceof BlockFluidBase)) + { return Integer.MAX_VALUE; } - return ((BlockFluidBase) block).density; + return ((BlockFluidBase)block).density; } - public static double getFlowDirection(IBlockAccess world, int x, int y, int z) { - + public static double getFlowDirection(IBlockAccess world, int x, int y, int z) + { Block block = Block.blocksList[world.getBlockId(x, y, z)]; - - if (!(Block.blocksList[world.getBlockId(x, y, z)] instanceof BlockFluidBase)) { + if (!(block instanceof BlockFluidBase)) + { return -1000.0; } Vec3 vec = ((BlockFluidBase) block).getFlowVector(world, x, y, z); return vec.xCoord == 0.0D && vec.zCoord == 0.0D ? -1000.0D : Math.atan2(vec.zCoord, vec.xCoord) - Math.PI / 2D; } - public final int getQuantaValueBelow(IBlockAccess world, int x, int y, int z, int belowThis) { - + public final int getQuantaValueBelow(IBlockAccess world, int x, int y, int z, int belowThis) + { int quantaRemaining = getQuantaValue(world, x, y, z); - - if (quantaRemaining >= belowThis) { + if (quantaRemaining >= belowThis) + { return -1; } return quantaRemaining; } - public final int getQuantaValueAbove(IBlockAccess world, int x, int y, int z, int aboveThis) { - + public final int getQuantaValueAbove(IBlockAccess world, int x, int y, int z, int aboveThis) + { int quantaRemaining = getQuantaValue(world, x, y, z); - - if (quantaRemaining <= aboveThis) { + if (quantaRemaining <= aboveThis) + { return -1; } return quantaRemaining; } - public final float getQuantaPercentage(IBlockAccess world, int x, int y, int z) { - + public final float getQuantaPercentage(IBlockAccess world, int x, int y, int z) + { int quantaRemaining = getQuantaValue(world, x, y, z); return quantaRemaining / quantaPerBlockFloat; } - public Vec3 getFlowVector(IBlockAccess world, int x, int y, int z) { - + public Vec3 getFlowVector(IBlockAccess world, int x, int y, int z) + { Vec3 vec = world.getWorldVec3Pool().getVecFromPool(0.0D, 0.0D, 0.0D); int decay = quantaPerBlock - getQuantaValue(world, x, y, z); - for (int side = 0; side < 4; ++side) { + for (int side = 0; side < 4; ++side) + { int x2 = x; int z2 = z; - switch (side) { - case 0: - --x2; - break; - case 1: - --z2; - break; - case 2: - ++x2; - break; - case 3: - ++z2; - break; + switch (side) + { + case 0: --x2; break; + case 1: --z2; break; + case 2: ++x2; break; + case 3: ++z2; break; } int otherDecay = quantaPerBlock - getQuantaValue(world, x2, y, z2); - - if (otherDecay >= quantaPerBlock) { - if (!world.getBlockMaterial(x2, y, z2).blocksMovement()) { + if (otherDecay >= quantaPerBlock) + { + if (!world.getBlockMaterial(x2, y, z2).blocksMovement()) + { otherDecay = quantaPerBlock - getQuantaValue(world, x2, y - 1, z2); - - if (otherDecay >= 0) { + if (otherDecay >= 0) + { int power = otherDecay - (decay - quantaPerBlock); vec = vec.addVector((x2 - x) * power, (y - y) * power, (z2 - z) * power); } } - } else if (otherDecay >= 0) { + } + else if (otherDecay >= 0) + { int power = otherDecay - decay; vec = vec.addVector((x2 - x) * power, (y - y) * power, (z2 - z) * power); } } - if (world.getBlockId(x, y + 1, z) == blockID) { - boolean flag = false; - if (this.isBlockSolid(world, x, y, z - 1, 2)) { - flag = true; - } else if (this.isBlockSolid(world, x, y, z + 1, 3)) { - flag = true; - } else if (this.isBlockSolid(world, x - 1, y, z, 4)) { - flag = true; - } else if (this.isBlockSolid(world, x + 1, y, z, 5)) { - flag = true; - } else if (this.isBlockSolid(world, x, y + 1, z - 1, 2)) { - flag = true; - } else if (this.isBlockSolid(world, x, y + 1, z + 1, 3)) { - flag = true; - } else if (this.isBlockSolid(world, x - 1, y + 1, z, 4)) { - flag = true; - } else if (this.isBlockSolid(world, x + 1, y + 1, z, 5)) { - flag = true; - } - if (flag) { + if (world.getBlockId(x, y + 1, z) == blockID) + { + boolean flag = + isBlockSolid(world, x, y, z - 1, 2) || + isBlockSolid(world, x, y, z + 1, 3) || + isBlockSolid(world, x - 1, y, z, 4) || + isBlockSolid(world, x + 1, y, z, 5) || + isBlockSolid(world, x, y + 1, z - 1, 2) || + isBlockSolid(world, x, y + 1, z + 1, 3) || + isBlockSolid(world, x - 1, y + 1, z, 4) || + isBlockSolid(world, x + 1, y + 1, z, 5); + + if (flag) + { vec = vec.normalize().addVector(0.0D, -6.0D, 0.0D); } } @@ -408,9 +402,8 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock { /* IFluidBlock */ @Override - public Fluid getFluid() { - + public Fluid getFluid() + { return FluidRegistry.getFluid(fluidName); } - } diff --git a/common/net/minecraftforge/fluids/BlockFluidClassic.java b/common/net/minecraftforge/fluids/BlockFluidClassic.java index 60a1958f7..ae63e2ceb 100644 --- a/common/net/minecraftforge/fluids/BlockFluidClassic.java +++ b/common/net/minecraftforge/fluids/BlockFluidClassic.java @@ -16,60 +16,65 @@ import net.minecraft.world.World; * @author King Lemming * */ -public class BlockFluidClassic extends BlockFluidBase { - +public class BlockFluidClassic extends BlockFluidBase +{ protected boolean[] isOptimalFlowDirection = new boolean[4]; protected int[] flowCost = new int[4]; protected FluidStack stack; - public BlockFluidClassic(int id, Fluid fluid, Material material) { - + public BlockFluidClassic(int id, Fluid fluid, Material material) + { super(id, fluid, material); stack = new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME); } - public BlockFluidClassic setFluidStack(FluidStack stack) { - + public BlockFluidClassic setFluidStack(FluidStack stack) + { this.stack = stack; return this; } - public BlockFluidClassic setFluidStackAmount(int amount) { - + public BlockFluidClassic setFluidStackAmount(int amount) + { this.stack.amount = amount; return this; } @Override - public int getQuantaValue(IBlockAccess world, int x, int y, int z) { - - if (world.getBlockId(x, y, z) == 0) { + public int getQuantaValue(IBlockAccess world, int x, int y, int z) + { + if (world.getBlockId(x, y, z) == 0) + { return 0; } - if (world.getBlockId(x, y, z) != blockID) { + + if (world.getBlockId(x, y, z) != blockID) + { return -1; } + int quantaRemaining = quantaPerBlock - world.getBlockMetadata(x, y, z); return quantaRemaining; } @Override - public boolean canCollideCheck(int meta, boolean fullHit) { - + public boolean canCollideCheck(int meta, boolean fullHit) + { return fullHit && meta == 0; } @Override - public int getMaxRenderHeightMeta() { - + public int getMaxRenderHeightMeta() + { return 0; } @Override - public int getLightValue(IBlockAccess world, int x, int y, int z) { - - if (maxScaledLight == 0) { + public int getLightValue(IBlockAccess world, int x, int y, int z) + { + if (maxScaledLight == 0) + { return super.getLightValue(world, x, y, z); } int data = quantaPerBlock - world.getBlockMetadata(x, y, z) - 1; @@ -77,138 +82,155 @@ public class BlockFluidClassic extends BlockFluidBase { } @Override - public void updateTick(World world, int x, int y, int z, Random rand) { - + public void updateTick(World world, int x, int y, int z, Random rand) + { int quantaRemaining = quantaPerBlock - world.getBlockMetadata(x, y, z); int expQuanta = -101; // check adjacent block levels if non-source - if (quantaRemaining < quantaPerBlock) { + if (quantaRemaining < quantaPerBlock) + { int y2 = y - densityDir; - if (world.getBlockId(x, y2, z) == blockID || world.getBlockId(x - 1, y2, z) == blockID || world.getBlockId(x + 1, y2, z) == blockID - || world.getBlockId(x, y2, z - 1) == blockID || world.getBlockId(x, y2, z + 1) == blockID) { + if (world.getBlockId(x, y2, z ) == blockID || + world.getBlockId(x - 1, y2, z ) == blockID || + world.getBlockId(x + 1, y2, z ) == blockID || + world.getBlockId(x, y2, z - 1) == blockID || + world.getBlockId(x, y2, z + 1) == blockID) + { expQuanta = quantaPerBlock - 1; - - } else { + } + else + { int maxQuanta = -100; - maxQuanta = getLargerQuanta(world, x - 1, y, z, maxQuanta); - maxQuanta = getLargerQuanta(world, x + 1, y, z, maxQuanta); - maxQuanta = getLargerQuanta(world, x, y, z - 1, maxQuanta); - maxQuanta = getLargerQuanta(world, x, y, z + 1, maxQuanta); + maxQuanta = getLargerQuanta(world, x - 1, y, z, maxQuanta); + maxQuanta = getLargerQuanta(world, x + 1, y, z, maxQuanta); + maxQuanta = getLargerQuanta(world, x, y, z - 1, maxQuanta); + maxQuanta = getLargerQuanta(world, x, y, z + 1, maxQuanta); expQuanta = maxQuanta - 1; } + // decay calculation - if (expQuanta != quantaRemaining) { + if (expQuanta != quantaRemaining) + { quantaRemaining = expQuanta; - if (expQuanta <= 0) { + if (expQuanta <= 0) + { world.setBlockToAir(x, y, z); - } else { + } + else + { world.setBlockMetadataWithNotify(x, y, z, quantaPerBlock - expQuanta, 3); world.scheduleBlockUpdate(x, y, z, blockID, tickRate); world.notifyBlocksOfNeighborChange(x, y, z, blockID); } } - } else if (quantaRemaining > quantaPerBlock) { + } + else if (quantaRemaining > quantaPerBlock) + { world.setBlockMetadataWithNotify(x, y, z, 0, 3); } + // Flow vertically if possible - if (canDisplace(world, x, y + densityDir, z)) { + if (canDisplace(world, x, y + densityDir, z)) + { flowIntoBlock(world, x, y + densityDir, z, 1); return; } + // Flow outward if possible int flowMeta = quantaPerBlock - quantaRemaining + 1; - if (flowMeta >= quantaPerBlock) { + if (flowMeta >= quantaPerBlock) + { return; } - if (isSourceBlock(world, x, y, z) || !isFlowingVertically(world, x, y, z)) { - - if (world.getBlockId(x, y - densityDir, z) == blockID) { + if (isSourceBlock(world, x, y, z) || !isFlowingVertically(world, x, y, z)) + { + if (world.getBlockId(x, y - densityDir, z) == blockID) + { flowMeta = 1; } boolean flowTo[] = getOptimalFlowDirections(world, x, y, z); - if (flowTo[0]) { - flowIntoBlock(world, x - 1, y, z, flowMeta); - } - if (flowTo[1]) { - flowIntoBlock(world, x + 1, y, z, flowMeta); - } - if (flowTo[2]) { - flowIntoBlock(world, x, y, z - 1, flowMeta); - } - if (flowTo[3]) { - flowIntoBlock(world, x, y, z + 1, flowMeta); - } + if (flowTo[0]) flowIntoBlock(world, x - 1, y, z, flowMeta); + if (flowTo[1]) flowIntoBlock(world, x + 1, y, z, flowMeta); + if (flowTo[2]) flowIntoBlock(world, x, y, z - 1, flowMeta); + if (flowTo[3]) flowIntoBlock(world, x, y, z + 1, flowMeta); } } - public boolean isFlowingVertically(IBlockAccess world, int x, int y, int z) { - - return world.getBlockId(x, y + densityDir, z) == blockID || world.getBlockId(x, y, z) == blockID && canFlowInto(world, x, y + densityDir, z); + public boolean isFlowingVertically(IBlockAccess world, int x, int y, int z) + { + return world.getBlockId(x, y + densityDir, z) == blockID || + (world.getBlockId(x, y, z) == blockID && canFlowInto(world, x, y + densityDir, z)); } - public boolean isSourceBlock(IBlockAccess world, int x, int y, int z) { - + public boolean isSourceBlock(IBlockAccess world, int x, int y, int z) + { return world.getBlockId(x, y, z) == blockID && world.getBlockMetadata(x, y, z) == 0; } - protected boolean[] getOptimalFlowDirections(World world, int x, int y, int z) { - - for (int side = 0; side < 4; side++) { + protected boolean[] getOptimalFlowDirections(World world, int x, int y, int z) + { + for (int side = 0; side < 4; side++) + { flowCost[side] = 1000; int x2 = x; int y2 = y; int z2 = z; - switch (side) { - case 0: - --x2; - break; - case 1: - ++x2; - break; - case 2: - --z2; - break; - case 3: - ++z2; - break; + switch (side) + { + case 0: --x2; break; + case 1: ++x2; break; + case 2: --z2; break; + case 3: ++z2; break; } - if (!canFlowInto(world, x2, y2, z2) || isSourceBlock(world, x2, y2, z2)) { + if (!canFlowInto(world, x2, y2, z2) || isSourceBlock(world, x2, y2, z2)) + { continue; } - if (canFlowInto(world, x2, y2 + densityDir, z2)) { + + if (canFlowInto(world, x2, y2 + densityDir, z2)) + { flowCost[side] = 0; - } else { + } + else + { flowCost[side] = calculateFlowCost(world, x2, y2, z2, 1, side); } } int min = flowCost[0]; - for (int side = 1; side < 4; side++) { - if (flowCost[side] < min) { + for (int side = 1; side < 4; side++) + { + if (flowCost[side] < min) + { min = flowCost[side]; } } - for (int side = 0; side < 4; side++) { + for (int side = 0; side < 4; side++) + { isOptimalFlowDirection[side] = flowCost[side] == min; } return isOptimalFlowDirection; } - protected int calculateFlowCost(World world, int x, int y, int z, int recurseDepth, int side) { - + protected int calculateFlowCost(World world, int x, int y, int z, int recurseDepth, int side) + { int cost = 1000; - - for (int adjSide = 0; adjSide < 4; adjSide++) { - if (adjSide == 0 && side == 1 || adjSide == 1 && side == 0 || adjSide == 2 && side == 3 || adjSide == 3 && side == 2) { + for (int adjSide = 0; adjSide < 4; adjSide++) + { + if ((adjSide == 0 && side == 1) || + (adjSide == 1 && side == 0) || + (adjSide == 2 && side == 3) || + (adjSide == 3 && side == 2)) + { continue; } @@ -216,72 +238,78 @@ public class BlockFluidClassic extends BlockFluidBase { int y2 = y; int z2 = z; - switch (adjSide) { - case 0: - --x2; - break; - case 1: - ++x2; - break; - case 2: - --z2; - break; - case 3: - ++z2; - break; + switch (adjSide) + { + case 0: --x2; break; + case 1: ++x2; break; + case 2: --z2; break; + case 3: ++z2; break; } - if (!canFlowInto(world, x2, y2, z2) || isSourceBlock(world, x2, y2, z2)) { + if (!canFlowInto(world, x2, y2, z2) || isSourceBlock(world, x2, y2, z2)) + { continue; } - if (canFlowInto(world, x2, y2 + densityDir, z2)) { + + if (canFlowInto(world, x2, y2 + densityDir, z2)) + { return recurseDepth; } - if (recurseDepth >= 4) { + + if (recurseDepth >= 4) + { continue; } + int min = calculateFlowCost(world, x2, y2, z2, recurseDepth + 1, adjSide); - if (min < cost) { + if (min < cost) + { cost = min; } } return cost; } - protected void flowIntoBlock(World world, int x, int y, int z, int meta) { - - if (meta < 0) { - return; - } - if (displaceIfPossible(world, x, y, z)) { + protected void flowIntoBlock(World world, int x, int y, int z, int meta) + { + if (meta < 0) return; + if (displaceIfPossible(world, x, y, z)) + { world.setBlock(x, y, z, this.blockID, meta, 3); } } - protected boolean canFlowInto(IBlockAccess world, int x, int y, int z) { + protected boolean canFlowInto(IBlockAccess world, int x, int y, int z) + { + if (world.isAirBlock(x, y, z)) return true; int bId = world.getBlockId(x, y, z); - if (bId == 0) { + if (bId == blockID) + { return true; } - if (bId == blockID) { - return true; - } - if (displacementIds.containsKey(bId)) { + + if (displacementIds.containsKey(bId)) + { return displacementIds.get(bId); } + Material material = Block.blocksList[bId].blockMaterial; - if (material.blocksMovement() || material == Material.water || material == Material.lava || material == Material.portal) { + if (material.blocksMovement() || + material == Material.water || + material == Material.lava || + material == Material.portal) + { return false; } return true; } - protected int getLargerQuanta(IBlockAccess world, int x, int y, int z, int compare) { - + protected int getLargerQuanta(IBlockAccess world, int x, int y, int z, int compare) + { int quantaRemaining = getQuantaValue(world, x, y, z); - - if (quantaRemaining <= 0) { + if (quantaRemaining <= 0) + { return compare; } return quantaRemaining >= compare ? quantaRemaining : compare; @@ -289,21 +317,24 @@ public class BlockFluidClassic extends BlockFluidBase { /* IFluidBlock */ @Override - public FluidStack drain(World world, int x, int y, int z, boolean doDrain) { - - if (!isSourceBlock(world, x, y, z)) { + public FluidStack drain(World world, int x, int y, int z, boolean doDrain) + { + if (!isSourceBlock(world, x, y, z)) + { return null; } - if (doDrain) { + + if (doDrain) + { world.setBlockToAir(x, y, z); } + return stack.copy(); } @Override - public boolean canDrain(World world, int x, int y, int z) { - + public boolean canDrain(World world, int x, int y, int z) + { return isSourceBlock(world, x, y, z); } - } diff --git a/common/net/minecraftforge/fluids/BlockFluidFinite.java b/common/net/minecraftforge/fluids/BlockFluidFinite.java index 1d0e4b945..6a6edf72d 100644 --- a/common/net/minecraftforge/fluids/BlockFluidFinite.java +++ b/common/net/minecraftforge/fluids/BlockFluidFinite.java @@ -16,41 +16,44 @@ import net.minecraft.world.World; * @author OvermindDL1, KingLemming * */ -public class BlockFluidFinite extends BlockFluidBase { - - public BlockFluidFinite(int id, Fluid fluid, Material material) { - +public class BlockFluidFinite extends BlockFluidBase +{ + public BlockFluidFinite(int id, Fluid fluid, Material material) + { super(id, fluid, material); } @Override - public int getQuantaValue(IBlockAccess world, int x, int y, int z) { - - if (world.getBlockId(x, y, z) == 0) { + public int getQuantaValue(IBlockAccess world, int x, int y, int z) + { + if (world.isAirBlock(x, y, z)) + { return 0; } + if (world.getBlockId(x, y, z) != blockID) { return -1; } + int quantaRemaining = world.getBlockMetadata(x, y, z) + 1; return quantaRemaining; } @Override - public boolean canCollideCheck(int meta, boolean fullHit) { - + public boolean canCollideCheck(int meta, boolean fullHit) + { return fullHit && meta == quantaPerBlock - 1; } @Override - public int getMaxRenderHeightMeta() { - + public int getMaxRenderHeightMeta() + { return quantaPerBlock - 1; } @Override - public void updateTick(World world, int x, int y, int z, Random rand) { - + public void updateTick(World world, int x, int y, int z, Random rand) + { boolean changed = false; int quantaRemaining = world.getBlockMetadata(x, y, z) + 1; @@ -58,103 +61,124 @@ public class BlockFluidFinite extends BlockFluidBase { int prevRemaining = quantaRemaining; quantaRemaining = tryToFlowVerticallyInto(world, x, y, z, quantaRemaining); - if (quantaRemaining < 1) { + if (quantaRemaining < 1) + { return; - } else if (quantaRemaining != prevRemaining) { + } + else if (quantaRemaining != prevRemaining) + { changed = true; - - if (quantaRemaining == 1) { + if (quantaRemaining == 1) + { world.setBlockMetadataWithNotify(x, y, z, quantaRemaining - 1, 2); return; } - } else if (quantaRemaining == 1) { + } + else if (quantaRemaining == 1) + { return; } // Flow out if possible int lowerthan = quantaRemaining - 1; - - if (displaceIfPossible(world, x, y, z - 1)) { - world.setBlock(x, y, z - 1, 0); - } - if (displaceIfPossible(world, x, y, z + 1)) { - world.setBlock(x, y, z + 1, 0); - } - if (displaceIfPossible(world, x - 1, y, z)) { - world.setBlock(x - 1, y, z, 0); - } - if (displaceIfPossible(world, x + 1, y, z)) { - world.setBlock(x + 1, y, z, 0); - } - int north = getQuantaValueBelow(world, x, y, z - 1, lowerthan); - int south = getQuantaValueBelow(world, x, y, z + 1, lowerthan); - int west = getQuantaValueBelow(world, x - 1, y, z, lowerthan); - int east = getQuantaValueBelow(world, x + 1, y, z, lowerthan); + if (displaceIfPossible(world, x, y, z - 1)) world.setBlock(x, y, z - 1, 0); + if (displaceIfPossible(world, x, y, z + 1)) world.setBlock(x, y, z + 1, 0); + if (displaceIfPossible(world, x - 1, y, z )) world.setBlock(x - 1, y, z, 0); + if (displaceIfPossible(world, x + 1, y, z )) world.setBlock(x + 1, y, z, 0); + int north = getQuantaValueBelow(world, x, y, z - 1, lowerthan); + int south = getQuantaValueBelow(world, x, y, z + 1, lowerthan); + int west = getQuantaValueBelow(world, x - 1, y, z, lowerthan); + int east = getQuantaValueBelow(world, x + 1, y, z, lowerthan); int total = quantaRemaining; int count = 1; - if (north >= 0) { - ++count; + if (north >= 0) + { + count++; total += north; } - if (south >= 0) { - ++count; + + if (south >= 0) + { + count++; total += south; } - if (west >= 0) { - ++count; + + if (west >= 0) + { + count++; total += west; } + if (east >= 0) { ++count; total += east; } - if (count == 1) { - if (changed) { + + if (count == 1) + { + if (changed) + { world.setBlockMetadataWithNotify(x, y, z, quantaRemaining - 1, 2); } return; } + int each = total / count; int rem = total % count; - if (north >= 0) { + if (north >= 0) + { int newnorth = each; - - if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0) { + if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0) + { ++newnorth; --rem; } - if (newnorth != north) { - if (newnorth == 0) { + + if (newnorth != north) + { + if (newnorth == 0) + { world.setBlock(x, y, z - 1, 0); - } else { + } + else + { world.setBlock(x, y, z - 1, blockID, newnorth - 1, 2); } world.scheduleBlockUpdate(x, y, z - 1, blockID, tickRate); } --count; } - if (south >= 0) { - int newsouth = each; - if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0) { + if (south >= 0) + { + int newsouth = each; + if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0) + { ++newsouth; --rem; } - if (newsouth != south) { - if (newsouth == 0) { + + if (newsouth != south) + { + if (newsouth == 0) + { world.setBlock(x, y, z + 1, 0); - } else { + } + else + { world.setBlock(x, y, z + 1, blockID, newsouth - 1, 2); } world.scheduleBlockUpdate(x, y, z + 1, blockID, tickRate); } --count; } - if (west >= 0) { - int newwest = each; - if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0) { + if (west >= 0) + { + int newwest = each; + if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0) + { ++newwest; --rem; } @@ -168,66 +192,86 @@ public class BlockFluidFinite extends BlockFluidBase { } --count; } - if (east >= 0) { - int neweast = each; - if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0) { + if (east >= 0) + { + int neweast = each; + if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0) + { ++neweast; --rem; } - if (neweast != east) { - if (neweast == 0) { + + if (neweast != east) + { + if (neweast == 0) + { world.setBlock(x + 1, y, z, 0); - } else { + } + else + { world.setBlock(x + 1, y, z, blockID, neweast - 1, 2); } world.scheduleBlockUpdate(x + 1, y, z, blockID, tickRate); } --count; } - if (rem > 0) { + + if (rem > 0) + { ++each; } world.setBlockMetadataWithNotify(x, y, z, each - 1, 2); } - public int tryToFlowVerticallyInto(World world, int x, int y, int z, int amtToInput) { - + public int tryToFlowVerticallyInto(World world, int x, int y, int z, int amtToInput) + { int otherY = y + densityDir; - - if (otherY < 0 || otherY >= world.getHeight()) { + if (otherY < 0 || otherY >= world.getHeight()) + { world.setBlockToAir(x, y, z); return 0; } - int amt = getQuantaValueBelow(world, x, otherY, z, quantaPerBlock); - if (amt >= 0) { + int amt = getQuantaValueBelow(world, x, otherY, z, quantaPerBlock); + if (amt >= 0) + { amt += amtToInput; - if (amt > quantaPerBlock) { + if (amt > quantaPerBlock) + { world.setBlock(x, otherY, z, blockID, quantaPerBlock - 1, 3); world.scheduleBlockUpdate(x, otherY, z, blockID, tickRate); return amt - quantaPerBlock; - } else if (amt > 0) { + } + else if (amt > 0) + { world.setBlock(x, otherY, z, blockID, amt - 1, 3); world.scheduleBlockUpdate(x, otherY, z, blockID, tickRate); world.setBlockToAir(x, y, z); return 0; } return amtToInput; - } else { + } + else + { int density_other = getDensity(world, x, otherY, z); - - if (density_other == Integer.MAX_VALUE) { - if (displaceIfPossible(world, x, otherY, z)) { + if (density_other == Integer.MAX_VALUE) + { + if (displaceIfPossible(world, x, otherY, z)) + { world.setBlock(x, otherY, z, blockID, amtToInput - 1, 3); world.scheduleBlockUpdate(x, otherY, z, blockID, tickRate); world.setBlockToAir(x, y, z); return 0; - } else { + } + else + { return amtToInput; } } - if (densityDir < 0) { + + if (densityDir < 0) + { if (density_other < density) // then swap { int bId = world.getBlockId(x, otherY, z); @@ -239,8 +283,11 @@ public class BlockFluidFinite extends BlockFluidBase { world.scheduleBlockUpdate(x, y, z, bId, block.tickRate(world)); return 0; } - } else { - if (density_other > density) { + } + else + { + if (density_other > density) + { int bId = world.getBlockId(x, otherY, z); BlockFluidBase block = (BlockFluidBase) Block.blocksList[bId]; int otherData = world.getBlockMetadata(x, otherY, z); @@ -257,15 +304,14 @@ public class BlockFluidFinite extends BlockFluidBase { /* IFluidBlock */ @Override - public FluidStack drain(World world, int x, int y, int z, boolean doDrain) { - + public FluidStack drain(World world, int x, int y, int z, boolean doDrain) + { return null; } @Override - public boolean canDrain(World world, int x, int y, int z) { - + public boolean canDrain(World world, int x, int y, int z) + { return false; } - } diff --git a/common/net/minecraftforge/fluids/Fluid.java b/common/net/minecraftforge/fluids/Fluid.java index 2c29fe19e..b7c6f9147 100644 --- a/common/net/minecraftforge/fluids/Fluid.java +++ b/common/net/minecraftforge/fluids/Fluid.java @@ -31,8 +31,8 @@ import cpw.mods.fml.relauncher.SideOnly; * @author King Lemming * */ -public class Fluid { - +public class Fluid +{ /** The unique identification name for this fluid. */ protected final String fluidName; @@ -40,9 +40,7 @@ public class Fluid { protected String unlocalizedName; /** The Icons for this fluid. */ - @SideOnly(Side.CLIENT) protected Icon stillIcon; - @SideOnly(Side.CLIENT) protected Icon flowingIcon; /** @@ -84,26 +82,31 @@ public class Fluid { */ protected int blockID = -1; - public Fluid(String fluidName) { - + public Fluid(String fluidName) + { this.fluidName = fluidName.toLowerCase(Locale.ENGLISH); this.unlocalizedName = fluidName; } - public Fluid setUnlocalizedName(String unlocalizedName) { - + public Fluid setUnlocalizedName(String unlocalizedName) + { this.unlocalizedName = unlocalizedName; return this; } - public Fluid setBlockID(int blockID) { - - if (this.blockID == -1 || this.blockID == blockID) { + public Fluid setBlockID(int blockID) + { + if (this.blockID == -1 || this.blockID == blockID) + { this.blockID = blockID; - } else if (!ForgeDummyContainer.forceDuplicateFluidBlockCrash) { + } + else if (!ForgeDummyContainer.forceDuplicateFluidBlockCrash) + { FMLLog.warning("A mod has attempted to assign BlockID " + blockID + " to the Fluid '" + fluidName + "' but this Fluid has already been linked to BlockID " + this.blockID + ". Configure your mods to prevent this from happening."); - } else { + } + else + { FMLLog.severe("A mod has attempted to assign BlockID " + blockID + " to the Fluid '" + fluidName + "' but this Fluid has already been linked to BlockID " + this.blockID + ". Configure your mods to prevent this from happening."); throw new LoaderException(new RuntimeException("A mod has attempted to assign BlockID " + blockID + " to the Fluid '" + fluidName @@ -112,60 +115,60 @@ public class Fluid { return this; } - public Fluid setBlockID(Block block) { - + public Fluid setBlockID(Block block) + { return setBlockID(block.blockID); } - public Fluid setLuminosity(int luminosity) { - + public Fluid setLuminosity(int luminosity) + { this.luminosity = luminosity; return this; } - public Fluid setDensity(int density) { - + public Fluid setDensity(int density) + { this.density = density; return this; } - public Fluid setViscosity(int viscosity) { - + public Fluid setViscosity(int viscosity) + { this.viscosity = viscosity; return this; } - public Fluid setGaseous(boolean isGaseous) { - + public Fluid setGaseous(boolean isGaseous) + { this.isGaseous = isGaseous; return this; } - public final String getName() { - + public final String getName() + { return this.fluidName; } - public final int getID() { - + public final int getID() + { return FluidRegistry.getFluidID(this.fluidName); } - public final int getBlockID() { - + public final int getBlockID() + { return blockID; } - public final boolean canBePlacedInWorld() { - + public final boolean canBePlacedInWorld() + { return blockID != -1; } /** * Returns the localized name of this fluid. */ - public String getLocalizedName() { - + public String getLocalizedName() + { String s = this.getUnlocalizedName(); return s == null ? "" : StatCollector.translateToLocal(s); } @@ -173,155 +176,91 @@ public class Fluid { /** * Returns the unlocalized name of this fluid. */ - public String getUnlocalizedName() { - + public String getUnlocalizedName() + { return "fluid." + this.unlocalizedName; } /** * Returns 0 for "/terrain.png". ALL FLUID TEXTURES MUST BE ON THIS SHEET. */ - public final int getSpriteNumber() { - + public final int getSpriteNumber() + { return 0; } /* Default Accessors */ - public final int getLuminosity() { - + public final int getLuminosity() + { return this.luminosity; } - public final int getDensity() { - + public final int getDensity() + { return this.density; } - public final int getViscosity() { - + public final int getViscosity() + { return this.viscosity; } - public final boolean isGaseous() { - + public final boolean isGaseous() + { return this.isGaseous; } - public int getColor() { - + public int getColor() + { return 0xFFFFFF; } - /* Stack-based Accessors */ - public int getLuminosity(FluidStack stack) { - - return getLuminosity(); - } - - public int getDensity(FluidStack stack) { - - return getDensity(); - } - - public int getViscosity(FluidStack stack) { - - return getViscosity(); - } - - public boolean isGaseous(FluidStack stack) { - - return isGaseous(); - } - - public int getColor(FluidStack stack) { - - return getColor(); - } - - /* World-based Accessors */ - public int getLuminosity(World world, int x, int y, int z) { - - return getLuminosity(); - } - - public int getDensity(World world, int x, int y, int z) { - - return getDensity(); - } - - public int getViscosity(World world, int x, int y, int z) { - - return getViscosity(); - } - - public boolean isGaseous(World world, int x, int y, int z) { - - return isGaseous(); - } - - public int getColor(World world, int x, int y, int z) { - - return getColor(); - } - - @SideOnly(Side.CLIENT) - public final Fluid setStillIcon(Icon stillIcon) { - + public final Fluid setStillIcon(Icon stillIcon) + { this.stillIcon = stillIcon; return this; } - @SideOnly(Side.CLIENT) - public final Fluid setFlowingIcon(Icon flowingIcon) { - + public final Fluid setFlowingIcon(Icon flowingIcon) + { this.flowingIcon = flowingIcon; return this; } - @SideOnly(Side.CLIENT) - public final Fluid setIcons(Icon stillIcon, Icon flowingIcon) { - - this.stillIcon = stillIcon; - this.flowingIcon = flowingIcon; - return this; + public final Fluid setIcons(Icon stillIcon, Icon flowingIcon) + { + return this.setStillIcon(stillIcon).setFlowingIcon(flowingIcon); } - @SideOnly(Side.CLIENT) - public final Fluid setIcons(Icon commonIcon) { - - this.stillIcon = commonIcon; - this.flowingIcon = commonIcon; - return this; + public final Fluid setIcons(Icon commonIcon) + { + return this.setStillIcon(commonIcon).setFlowingIcon(commonIcon); } - @SideOnly(Side.CLIENT) - public Icon getIcon() { - - return getStillIcon(); - } - - @SideOnly(Side.CLIENT) - public Icon getIcon(FluidStack stack) { - - return getIcon(); - } - - @SideOnly(Side.CLIENT) - public Icon getIcon(World world, int x, int y, int z) { - - return getIcon(); - } - - @SideOnly(Side.CLIENT) - public Icon getStillIcon() { + public Icon getIcon(){ return getStillIcon(); } + public Icon getStillIcon() + { return this.stillIcon; } - @SideOnly(Side.CLIENT) - public Icon getFlowingIcon() { - + public Icon getFlowingIcon() + { return this.flowingIcon; } + /* Stack-based Accessors */ + public int getLuminosity(FluidStack stack){ return getLuminosity(); } + public int getDensity(FluidStack stack){ return getDensity(); } + public int getViscosity(FluidStack stack){ return getViscosity(); } + public boolean isGaseous(FluidStack stack){ return isGaseous(); } + public int getColor(FluidStack stack){ return getColor(); } + public Icon getIcon(FluidStack stack){ return getIcon(); } + /* World-based Accessors */ + public int getLuminosity(World world, int x, int y, int z){ return getLuminosity(); } + public int getDensity(World world, int x, int y, int z){ return getDensity(); } + public int getViscosity(World world, int x, int y, int z){ return getViscosity(); } + public boolean isGaseous(World world, int x, int y, int z){ return isGaseous(); } + public int getColor(World world, int x, int y, int z){ return getColor(); } + public Icon getIcon(World world, int x, int y, int z){ return getIcon(); } } diff --git a/common/net/minecraftforge/fluids/FluidContainerRegistry.java b/common/net/minecraftforge/fluids/FluidContainerRegistry.java index e6fba89fa..cf37e565b 100644 --- a/common/net/minecraftforge/fluids/FluidContainerRegistry.java +++ b/common/net/minecraftforge/fluids/FluidContainerRegistry.java @@ -22,8 +22,8 @@ import net.minecraftforge.event.Event; * @author King Lemming * */ -public abstract class FluidContainerRegistry { - +public abstract class FluidContainerRegistry +{ private static Map containerFluidMap = new HashMap(); private static Map filledContainerMap = new HashMap(); private static Set emptyContainers = new HashSet(); @@ -32,15 +32,14 @@ public abstract class FluidContainerRegistry { public static final ItemStack EMPTY_BUCKET = new ItemStack(Item.bucketEmpty); public static final ItemStack EMPTY_BOTTLE = new ItemStack(Item.glassBottle); - static { + static + { registerFluidContainer(FluidRegistry.WATER, new ItemStack(Item.bucketWater), EMPTY_BUCKET); - registerFluidContainer(FluidRegistry.LAVA, new ItemStack(Item.bucketLava), EMPTY_BUCKET); - registerFluidContainer(FluidRegistry.WATER, new ItemStack(Item.potion), EMPTY_BOTTLE); + registerFluidContainer(FluidRegistry.LAVA, new ItemStack(Item.bucketLava), EMPTY_BUCKET); + registerFluidContainer(FluidRegistry.WATER, new ItemStack(Item.potion), EMPTY_BOTTLE); } - private FluidContainerRegistry() { - - } + private FluidContainerRegistry(){} /** * Register a new fluid containing item. @@ -53,8 +52,8 @@ public abstract class FluidContainerRegistry { * ItemStack representing the container when it is empty. * @return True if container was successfully registered; false if it already is. */ - public static boolean registerFluidContainer(FluidStack stack, ItemStack filledContainer, ItemStack emptyContainer) { - + public static boolean registerFluidContainer(FluidStack stack, ItemStack filledContainer, ItemStack emptyContainer) + { return registerFluidContainer(new FluidContainerData(stack, filledContainer, emptyContainer)); } @@ -70,9 +69,10 @@ public abstract class FluidContainerRegistry { * ItemStack representing the container when it is empty. * @return True if container was successfully registered; false if it already is. */ - public static boolean registerFluidContainer(Fluid fluid, ItemStack filledContainer, ItemStack emptyContainer) { - - if (!FluidRegistry.isFluidRegistered(fluid)) { + public static boolean registerFluidContainer(Fluid fluid, ItemStack filledContainer, ItemStack emptyContainer) + { + if (!FluidRegistry.isFluidRegistered(fluid)) + { FluidRegistry.registerFluid(fluid); } return registerFluidContainer(new FluidStack(fluid, BUCKET_VOLUME), filledContainer, emptyContainer); @@ -87,8 +87,8 @@ public abstract class FluidContainerRegistry { * ItemStack representing the container when it is full. * @return True if container was successfully registered; false if it already is. */ - public static boolean registerFluidContainer(FluidStack stack, ItemStack filledContainer) { - + public static boolean registerFluidContainer(FluidStack stack, ItemStack filledContainer) + { return registerFluidContainer(new FluidContainerData(stack, filledContainer, null, true)); } @@ -102,9 +102,10 @@ public abstract class FluidContainerRegistry { * ItemStack representing the container when it is full. * @return True if container was successfully registered; false if it already is. */ - public static boolean registerFluidContainer(Fluid fluid, ItemStack filledContainer) { - - if (!FluidRegistry.isFluidRegistered(fluid)) { + public static boolean registerFluidContainer(Fluid fluid, ItemStack filledContainer) + { + if (!FluidRegistry.isFluidRegistered(fluid)) + { FluidRegistry.registerFluid(fluid); } return registerFluidContainer(new FluidStack(fluid, BUCKET_VOLUME), filledContainer); @@ -117,17 +118,20 @@ public abstract class FluidContainerRegistry { * See {@link FluidContainerData}. * @return True if container was successfully registered; false if it already is. */ - public static boolean registerFluidContainer(FluidContainerData data) { - - if (isFilledContainer(data.filledContainer)) { + public static boolean registerFluidContainer(FluidContainerData data) + { + if (isFilledContainer(data.filledContainer)) + { return false; } containerFluidMap.put(Arrays.asList(data.filledContainer.itemID, data.filledContainer.getItemDamage()), data); - if (data.emptyContainer != null) { + if (data.emptyContainer != null) + { filledContainerMap.put(Arrays.asList(data.emptyContainer.itemID, data.emptyContainer.getItemDamage(), data.fluid.fluidID), data); emptyContainers.add(Arrays.asList(data.emptyContainer.itemID, data.emptyContainer.getItemDamage())); } + MinecraftForge.EVENT_BUS.post(new FluidContainerRegisterEvent(data)); return true; } @@ -139,11 +143,13 @@ public abstract class FluidContainerRegistry { * The fluid container. * @return FluidStack representing stored fluid. */ - public static FluidStack getFluidForFilledItem(ItemStack container) { - - if (container == null) { + public static FluidStack getFluidForFilledItem(ItemStack container) + { + if (container == null) + { return null; } + FluidContainerData data = containerFluidMap.get(Arrays.asList(container.itemID, container.getItemDamage())); return data == null ? null : data.fluid.copy(); } @@ -159,13 +165,16 @@ public abstract class FluidContainerRegistry { * ItemStack representing the empty container. * @return Filled container if successful, otherwise null. */ - public static ItemStack fillFluidContainer(FluidStack fluid, ItemStack container) { - - if (container == null || fluid == null) { + public static ItemStack fillFluidContainer(FluidStack fluid, ItemStack container) + { + if (container == null || fluid == null) + { return null; } + FluidContainerData data = filledContainerMap.get(Arrays.asList(container.itemID, container.getItemDamage(), fluid.fluidID)); - if (data != null && fluid.amount >= data.fluid.amount) { + if (data != null && fluid.amount >= data.fluid.amount) + { return data.filledContainer.copy(); } return null; @@ -174,43 +183,50 @@ public abstract class FluidContainerRegistry { /** * Determines if a container holds a specific fluid. */ - public static boolean containsFluid(ItemStack container, FluidStack fluid) { - - if (container == null || fluid == null) { + public static boolean containsFluid(ItemStack container, FluidStack fluid) + { + if (container == null || fluid == null) + { return false; } + FluidContainerData data = filledContainerMap.get(Arrays.asList(container.itemID, container.getItemDamage(), fluid.fluidID)); return data == null ? false : data.fluid.isFluidEqual(fluid); } - public static boolean isBucket(ItemStack container) { - - if (container == null) { + public static boolean isBucket(ItemStack container) + { + if (container == null) + { return false; } - if (container.isItemEqual(EMPTY_BUCKET)) { + + if (container.isItemEqual(EMPTY_BUCKET)) + { return true; } + FluidContainerData data = containerFluidMap.get(Arrays.asList(container.itemID, container.getItemDamage())); return data != null && data.emptyContainer.isItemEqual(EMPTY_BUCKET); } - public static boolean isContainer(ItemStack container) { - + public static boolean isContainer(ItemStack container) + { return isEmptyContainer(container) || isFilledContainer(container); } - public static boolean isEmptyContainer(ItemStack container) { - + public static boolean isEmptyContainer(ItemStack container) + { return container != null && emptyContainers.contains(Arrays.asList(container.itemID, container.getItemDamage())); } - public static boolean isFilledContainer(ItemStack container) { - + public static boolean isFilledContainer(ItemStack container) + { return container != null && getFluidForFilledItem(container) != null; } - public static FluidContainerData[] getRegisteredFluidContainerData() { + public static FluidContainerData[] getRegisteredFluidContainerData() + { return containerFluidMap.values().toArray(new FluidContainerData[containerFluidMap.size()]); } @@ -218,40 +234,41 @@ public abstract class FluidContainerRegistry { * Wrapper class for the registry entries. Ensures that none of the attempted registrations * contain null references unless permitted. */ - public static class FluidContainerData { - + public static class FluidContainerData + { public final FluidStack fluid; public final ItemStack filledContainer; public final ItemStack emptyContainer; - public FluidContainerData(FluidStack stack, ItemStack filledContainer, ItemStack emptyContainer) { - + public FluidContainerData(FluidStack stack, ItemStack filledContainer, ItemStack emptyContainer) + { this(stack, filledContainer, emptyContainer, false); } - public FluidContainerData(FluidStack stack, ItemStack filledContainer, ItemStack emptyContainer, boolean nullEmpty) { - + public FluidContainerData(FluidStack stack, ItemStack filledContainer, ItemStack emptyContainer, boolean nullEmpty) + { this.fluid = stack; this.filledContainer = filledContainer; this.emptyContainer = emptyContainer; - if (stack == null || filledContainer == null || emptyContainer == null && !nullEmpty) { + if (stack == null || filledContainer == null || emptyContainer == null && !nullEmpty) + { throw new RuntimeException("Invalid FluidContainerData - a parameter was null."); } } - public FluidContainerData copy() { - + public FluidContainerData copy() + { return new FluidContainerData(fluid, filledContainer, emptyContainer, true); } } - public static class FluidContainerRegisterEvent extends Event { - + public static class FluidContainerRegisterEvent extends Event + { public final FluidContainerData data; - public FluidContainerRegisterEvent(FluidContainerData data) { - + public FluidContainerRegisterEvent(FluidContainerData data) + { this.data = data.copy(); } } diff --git a/common/net/minecraftforge/fluids/FluidEvent.java b/common/net/minecraftforge/fluids/FluidEvent.java index 328ba706b..c9cff4ff5 100644 --- a/common/net/minecraftforge/fluids/FluidEvent.java +++ b/common/net/minecraftforge/fluids/FluidEvent.java @@ -5,16 +5,16 @@ import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.Event; -public class FluidEvent extends Event { - +public class FluidEvent extends Event +{ public final FluidStack fluid; public final int x; public final int y; public final int z; public final World world; - public FluidEvent(FluidStack fluid, World world, int x, int y, int z) { - + public FluidEvent(FluidStack fluid, World world, int x, int y, int z) + { this.fluid = fluid; this.world = world; this.x = x; @@ -28,10 +28,10 @@ public class FluidEvent extends Event { * @author cpw * */ - public static class FluidMotionEvent extends FluidEvent { - - public FluidMotionEvent(FluidStack fluid, World world, int x, int y, int z) { - + public static class FluidMotionEvent extends FluidEvent + { + public FluidMotionEvent(FluidStack fluid, World world, int x, int y, int z) + { super(fluid, world, x, y, z); } } @@ -43,12 +43,11 @@ public class FluidEvent extends Event { * @author cpw * */ - public static class FluidFillingEvent extends FluidEvent { - + public static class FluidFillingEvent extends FluidEvent + { public final IFluidTank tank; - - public FluidFillingEvent(FluidStack fluid, World world, int x, int y, int z, IFluidTank tank) { - + public FluidFillingEvent(FluidStack fluid, World world, int x, int y, int z, IFluidTank tank) + { super(fluid, world, x, y, z); this.tank = tank; } @@ -61,12 +60,11 @@ public class FluidEvent extends Event { * @author cpw * */ - public static class FluidDrainingEvent extends FluidEvent { - + public static class FluidDrainingEvent extends FluidEvent + { public final IFluidTank tank; - - public FluidDrainingEvent(FluidStack fluid, World world, int x, int y, int z, IFluidTank tank) { - + public FluidDrainingEvent(FluidStack fluid, World world, int x, int y, int z, IFluidTank tank) + { super(fluid, world, x, y, z); this.tank = tank; } @@ -79,10 +77,10 @@ public class FluidEvent extends Event { * @author cpw * */ - public static class FluidSpilledEvent extends FluidEvent { - - public FluidSpilledEvent(FluidStack fluid, World world, int x, int y, int z) { - + public static class FluidSpilledEvent extends FluidEvent + { + public FluidSpilledEvent(FluidStack fluid, World world, int x, int y, int z) + { super(fluid, world, x, y, z); } } @@ -92,9 +90,8 @@ public class FluidEvent extends Event { * * @param event */ - public static final void fireEvent(FluidEvent event) { - + public static final void fireEvent(FluidEvent event) + { MinecraftForge.EVENT_BUS.post(event); } - } diff --git a/common/net/minecraftforge/fluids/FluidIdMapPacket.java b/common/net/minecraftforge/fluids/FluidIdMapPacket.java index 7859c61d4..9c8cc8ae7 100644 --- a/common/net/minecraftforge/fluids/FluidIdMapPacket.java +++ b/common/net/minecraftforge/fluids/FluidIdMapPacket.java @@ -13,17 +13,18 @@ import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; -public class FluidIdMapPacket extends ForgePacket { - +public class FluidIdMapPacket extends ForgePacket +{ private BiMap fluidIds = HashBiMap.create(); @Override - public byte[] generatePacket() { - + public byte[] generatePacket() + { ByteArrayDataOutput dat = ByteStreams.newDataOutput(); dat.writeInt(FluidRegistry.maxID); - for (Map.Entry entry : FluidRegistry.fluidIDs.entrySet()) { + for (Map.Entry entry : FluidRegistry.fluidIDs.entrySet()) + { dat.writeUTF(entry.getKey()); dat.writeInt(entry.getValue()); } @@ -31,8 +32,8 @@ public class FluidIdMapPacket extends ForgePacket { } @Override - public ForgePacket consumePacket(byte[] data) { - + public ForgePacket consumePacket(byte[] data) + { ByteArrayDataInput dat = ByteStreams.newDataInput(data); int listSize = dat.readInt(); for (int i = 0; i < listSize; i++) { @@ -44,9 +45,8 @@ public class FluidIdMapPacket extends ForgePacket { } @Override - public void execute(INetworkManager network, EntityPlayer player) { - + public void execute(INetworkManager network, EntityPlayer player) + { FluidRegistry.initFluidIDs(fluidIds); } - } diff --git a/common/net/minecraftforge/fluids/FluidRegistry.java b/common/net/minecraftforge/fluids/FluidRegistry.java index 34bd87fc1..4eba91c67 100644 --- a/common/net/minecraftforge/fluids/FluidRegistry.java +++ b/common/net/minecraftforge/fluids/FluidRegistry.java @@ -18,8 +18,8 @@ import com.google.common.collect.ImmutableMap; * @author King Lemming, CovertJaguar (LiquidDictionary) * */ -public abstract class FluidRegistry { - +public abstract class FluidRegistry +{ static int maxID = 0; static HashMap fluids = new HashMap(); @@ -30,20 +30,19 @@ public abstract class FluidRegistry { public static int renderIdFluid = -1; - static { + static + { registerFluid(WATER); registerFluid(LAVA); } - private FluidRegistry() { - - } + private FluidRegistry(){} /** * Called by Forge to prepare the ID map for server -> client sync. */ - static void initFluidIDs(BiMap newfluidIDs) { - + static void initFluidIDs(BiMap newfluidIDs) + { maxID = newfluidIDs.size(); fluidIDs.clear(); fluidIDs.putAll(newfluidIDs); @@ -56,9 +55,10 @@ public abstract class FluidRegistry { * The fluid to register. * @return True if the fluid was successfully registered; false if there is a name clash. */ - public static boolean registerFluid(Fluid fluid) { - - if (fluidIDs.containsKey(fluid.getName())) { + public static boolean registerFluid(Fluid fluid) + { + if (fluidIDs.containsKey(fluid.getName())) + { return false; } fluids.put(fluid.getName(), fluid); @@ -68,44 +68,45 @@ public abstract class FluidRegistry { return true; } - public static boolean isFluidRegistered(Fluid fluid) { - + public static boolean isFluidRegistered(Fluid fluid) + { return fluidIDs.containsKey(fluid.getName()); } - public static boolean isFluidRegistered(String fluidName) { - + public static boolean isFluidRegistered(String fluidName) + { return fluidIDs.containsKey(fluidName); } - public static Fluid getFluid(String fluidName) { - + public static Fluid getFluid(String fluidName) + { return fluids.get(fluidName); } - public static Fluid getFluid(int fluidID) { - + public static Fluid getFluid(int fluidID) + { return fluids.get(getFluidName(fluidID)); } - public static String getFluidName(int fluidID) { - + public static String getFluidName(int fluidID) + { return fluidIDs.inverse().get(fluidID); } - public static String getFluidName(FluidStack stack) { - + public static String getFluidName(FluidStack stack) + { return getFluidName(stack.fluidID); } - public static int getFluidID(String fluidName) { - + public static int getFluidID(String fluidName) + { return fluidIDs.get(fluidName); } - public static FluidStack getFluidStack(String fluidName, int amount) { - - if (!fluidIDs.containsKey(fluidName)) { + public static FluidStack getFluidStack(String fluidName, int amount) + { + if (!fluidIDs.containsKey(fluidName)) + { return null; } return new FluidStack(getFluidID(fluidName), amount); @@ -114,29 +115,28 @@ public abstract class FluidRegistry { /** * Returns a read-only map containing Fluid Names and their associated Fluids. */ - public static Map getRegisteredFluids() { - + public static Map getRegisteredFluids() + { return ImmutableMap.copyOf(fluids); } /** * Returns a read-only map containing Fluid Names and their associated IDs. */ - public static Map getRegisteredFluidIDs() { - + public static Map getRegisteredFluidIDs() + { return ImmutableMap.copyOf(fluidIDs); } - public static class FluidRegisterEvent extends Event { - + public static class FluidRegisterEvent extends Event + { public final String fluidName; public final int fluidID; - public FluidRegisterEvent(String fluidName, int fluidID) { - + public FluidRegisterEvent(String fluidName, int fluidID) + { this.fluidName = fluidName; this.fluidID = fluidID; } } - } diff --git a/common/net/minecraftforge/fluids/FluidStack.java b/common/net/minecraftforge/fluids/FluidStack.java index ede8942b1..99615501b 100644 --- a/common/net/minecraftforge/fluids/FluidStack.java +++ b/common/net/minecraftforge/fluids/FluidStack.java @@ -14,35 +14,36 @@ import net.minecraft.nbt.NBTTagCompound; * @author King Lemming, SirSengir (LiquidStack) * */ -public class FluidStack { - +public class FluidStack +{ public int fluidID; public int amount; public NBTTagCompound tag; - public FluidStack(Fluid fluid, int amount) { - + public FluidStack(Fluid fluid, int amount) + { this.fluidID = fluid.getID(); this.amount = amount; } - public FluidStack(int fluidID, int amount) { - + public FluidStack(int fluidID, int amount) + { this.fluidID = fluidID; this.amount = amount; } - public FluidStack(int fluidID, int amount, NBTTagCompound nbt) { - + public FluidStack(int fluidID, int amount, NBTTagCompound nbt) + { this(fluidID, amount); - if (nbt != null) { + if (nbt != null) + { tag = (NBTTagCompound) nbt.copy(); } } - public FluidStack(FluidStack stack, int amount) { - + public FluidStack(FluidStack stack, int amount) + { this(stack.fluidID, amount, stack.tag); } @@ -50,40 +51,43 @@ public class FluidStack { * This provides a safe method for retrieving a FluidStack - if the Fluid is invalid, the stack * will return as null. */ - public static FluidStack loadFluidStackFromNBT(NBTTagCompound nbt) { - - if (nbt == null || FluidRegistry.getFluid(nbt.getString("FluidName")) == null) { + public static FluidStack loadFluidStackFromNBT(NBTTagCompound nbt) + { + if (nbt == null || FluidRegistry.getFluid(nbt.getString("FluidName")) == null) + { return null; } FluidStack stack = new FluidStack(FluidRegistry.getFluidID(nbt.getString("FluidName")), nbt.getInteger("Amount")); - if (nbt.hasKey("Tag")) { + if (nbt.hasKey("Tag")) + { stack.tag = nbt.getCompoundTag("Tag"); } return stack; } - public NBTTagCompound writeToNBT(NBTTagCompound nbt) { - + public NBTTagCompound writeToNBT(NBTTagCompound nbt) + { nbt.setString("FluidName", FluidRegistry.getFluidName(fluidID)); nbt.setInteger("Amount", amount); - if (tag != null) { + if (tag != null) + { nbt.setTag("Tag", tag); } return nbt; } - public final Fluid getFluid() { - + public final Fluid getFluid() + { return FluidRegistry.getFluid(fluidID); } /** * @return A copy of this FluidStack */ - public FluidStack copy() { - + public FluidStack copy() + { return new FluidStack(fluidID, amount, tag); } @@ -94,21 +98,21 @@ public class FluidStack { * The FluidStack for comparison * @return true if the Fluids (IDs and NBT Tags) are the same */ - public boolean isFluidEqual(FluidStack other) { - + public boolean isFluidEqual(FluidStack other) + { return other != null && fluidID == other.fluidID && isFluidStackTagEqual(other); } - private boolean isFluidStackTagEqual(FluidStack other) { - + private boolean isFluidStackTagEqual(FluidStack other) + { return tag == null ? other.tag == null : other.tag == null ? false : tag.equals(other.tag); } /** * Determines if the NBT Tags are equal. Useful if the FluidIDs are known to be equal. */ - public static boolean areFluidStackTagsEqual(FluidStack stack1, FluidStack stack2) { - + public static boolean areFluidStackTagsEqual(FluidStack stack1, FluidStack stack2) + { return stack1 == null && stack2 == null ? true : stack1 == null || stack2 == null ? false : stack1.isFluidStackTagEqual(stack2); } @@ -118,8 +122,8 @@ public class FluidStack { * @param other * @return true if this FluidStack contains the other FluidStack (same fluid and >= amount) */ - public boolean containsFluid(FluidStack other) { - + public boolean containsFluid(FluidStack other) + { return isFluidEqual(other) && amount >= other.amount; } @@ -130,8 +134,8 @@ public class FluidStack { * - the FluidStack for comparison * @return true if the two FluidStacks are exactly the same */ - public boolean isFluidStackIdentical(FluidStack other) { - + public boolean isFluidStackIdentical(FluidStack other) + { return isFluidEqual(other) && amount == other.amount; } @@ -143,20 +147,24 @@ public class FluidStack { * The ItemStack for comparison * @return true if the Fluids (IDs and NBT Tags) are the same */ - public boolean isFluidEqual(ItemStack other) { - - if (other == null) { + public boolean isFluidEqual(ItemStack other) + { + if (other == null) + { return false; } - if (other.getItem() instanceof IFluidContainerItem) { + + if (other.getItem() instanceof IFluidContainerItem) + { return isFluidEqual(((IFluidContainerItem) other.getItem()).getFluid(other)); } + return isFluidEqual(FluidContainerRegistry.getFluidForFilledItem(other)); } @Override - public final int hashCode() { - + public final int hashCode() + { return fluidID; } @@ -166,12 +174,13 @@ public class FluidStack { * This is included for use in data structures. */ @Override - public final boolean equals(Object o) { - - if (!(o instanceof FluidStack)) { + public final boolean equals(Object o) + { + if (!(o instanceof FluidStack)) + { return false; } + return isFluidEqual((FluidStack) o); } - } diff --git a/common/net/minecraftforge/fluids/FluidTank.java b/common/net/minecraftforge/fluids/FluidTank.java index ee39fa515..4aa7a9cab 100644 --- a/common/net/minecraftforge/fluids/FluidTank.java +++ b/common/net/minecraftforge/fluids/FluidTank.java @@ -10,152 +10,179 @@ import net.minecraft.tileentity.TileEntity; * @author King Lemming, cpw (LiquidTank) * */ -public class FluidTank implements IFluidTank { - +public class FluidTank implements IFluidTank +{ protected FluidStack fluid; protected int capacity; protected TileEntity tile; - public FluidTank(int capacity) { - + public FluidTank(int capacity) + { this(null, capacity); } - public FluidTank(FluidStack stack, int capacity) { - + public FluidTank(FluidStack stack, int capacity) + { this.fluid = stack; this.capacity = capacity; } - public FluidTank(Fluid fluid, int amount, int capacity) { - + public FluidTank(Fluid fluid, int amount, int capacity) + { this(new FluidStack(fluid, amount), capacity); } - public FluidTank readFromNBT(NBTTagCompound nbt) { - - if (!nbt.hasKey("Empty")) { + public FluidTank readFromNBT(NBTTagCompound nbt) + { + if (!nbt.hasKey("Empty")) + { FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt); - if (fluid != null) { + if (fluid != null) + { setFluid(fluid); } } return this; } - public NBTTagCompound writeToNBT(NBTTagCompound nbt) { - - if (fluid != null) { + public NBTTagCompound writeToNBT(NBTTagCompound nbt) + { + if (fluid != null) + { fluid.writeToNBT(nbt); - } else { + } + else + { nbt.setString("Empty", ""); } return nbt; } - public void setFluid(FluidStack fluid) { - + public void setFluid(FluidStack fluid) + { this.fluid = fluid; } - public void setCapacity(int capacity) { - + public void setCapacity(int capacity) + { this.capacity = capacity; } /* IFluidTank */ @Override - public FluidStack getFluid() { - + public FluidStack getFluid() + { return fluid; } @Override - public int getFluidAmount() { - - if (fluid == null) { + public int getFluidAmount() + { + if (fluid == null) + { return 0; } return fluid.amount; } @Override - public int getCapacity() { - + public int getCapacity() + { return capacity; } @Override - public FluidTankInfo getInfo() { - + public FluidTankInfo getInfo() + { return new FluidTankInfo(this); } @Override - public int fill(FluidStack resource, boolean doFill) { - - if (resource == null) { + public int fill(FluidStack resource, boolean doFill) + { + if (resource == null) + { return 0; } - if (!doFill) { - if (fluid == null) { + + if (!doFill) + { + if (fluid == null) + { return Math.min(capacity, resource.amount); } - if (!fluid.isFluidEqual(resource)) { + + if (!fluid.isFluidEqual(resource)) + { return 0; } + return Math.min(capacity - fluid.amount, resource.amount); } - if (fluid == null) { + + if (fluid == null) + { fluid = new FluidStack(resource, Math.min(capacity, resource.amount)); - if (tile != null) { + if (tile != null) + { FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fluid, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this)); } return fluid.amount; } - if (!fluid.isFluidEqual(resource)) { + + if (!fluid.isFluidEqual(resource)) + { return 0; } int filled = capacity - fluid.amount; - if (resource.amount < filled) { + if (resource.amount < filled) + { fluid.amount += resource.amount; filled = resource.amount; - } else { + } + else + { fluid.amount = capacity; } - if (tile != null) { + + if (tile != null) + { FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fluid, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this)); } return filled; } @Override - public FluidStack drain(int maxDrain, boolean doDrain) { - - if (fluid == null) { + public FluidStack drain(int maxDrain, boolean doDrain) + { + if (fluid == null) + { return null; } - int drained = maxDrain; - if (fluid.amount < drained) { + int drained = maxDrain; + if (fluid.amount < drained) + { drained = fluid.amount; } + FluidStack stack = new FluidStack(fluid, drained); - - if (doDrain) { + if (doDrain) + { fluid.amount -= drained; - - if (fluid.amount <= 0) { + if (fluid.amount <= 0) + { fluid = null; } - if (tile != null) { + + if (tile != null) + { FluidEvent.fireEvent(new FluidEvent.FluidDrainingEvent(fluid, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this)); } } return stack; } - } diff --git a/common/net/minecraftforge/fluids/FluidTankInfo.java b/common/net/minecraftforge/fluids/FluidTankInfo.java index 8443f1452..a61ca4e4c 100644 --- a/common/net/minecraftforge/fluids/FluidTankInfo.java +++ b/common/net/minecraftforge/fluids/FluidTankInfo.java @@ -1,4 +1,3 @@ - package net.minecraftforge.fluids; /** @@ -7,21 +6,20 @@ package net.minecraftforge.fluids; * @author King Lemming * */ -public final class FluidTankInfo { - +public final class FluidTankInfo +{ public final FluidStack fluid; public final int capacity; - public FluidTankInfo(FluidStack fluid, int capacity) { - + public FluidTankInfo(FluidStack fluid, int capacity) + { this.fluid = fluid; this.capacity = capacity; } - public FluidTankInfo(IFluidTank tank) { - + public FluidTankInfo(IFluidTank tank) + { this.fluid = tank.getFluid(); this.capacity = tank.getCapacity(); } - } diff --git a/common/net/minecraftforge/fluids/IFluidBlock.java b/common/net/minecraftforge/fluids/IFluidBlock.java index 5d66980a6..f2f13b23e 100644 --- a/common/net/minecraftforge/fluids/IFluidBlock.java +++ b/common/net/minecraftforge/fluids/IFluidBlock.java @@ -1,4 +1,3 @@ - package net.minecraftforge.fluids; import net.minecraft.world.World; @@ -11,8 +10,8 @@ import net.minecraft.world.World; * @author King Lemming * */ -public interface IFluidBlock { - +public interface IFluidBlock +{ /** * Returns the Fluid associated with this Block. */ diff --git a/common/net/minecraftforge/fluids/IFluidContainerItem.java b/common/net/minecraftforge/fluids/IFluidContainerItem.java index c3ab9924a..04957b9cd 100644 --- a/common/net/minecraftforge/fluids/IFluidContainerItem.java +++ b/common/net/minecraftforge/fluids/IFluidContainerItem.java @@ -1,4 +1,3 @@ - package net.minecraftforge.fluids; import net.minecraft.item.ItemStack; @@ -14,8 +13,8 @@ import net.minecraft.item.ItemStack; * @author King Lemming * */ -public interface IFluidContainerItem { - +public interface IFluidContainerItem +{ /** * * @param container @@ -57,5 +56,4 @@ public interface IFluidContainerItem { * container. */ FluidStack drain(ItemStack container, int maxDrain, boolean doDrain); - } diff --git a/common/net/minecraftforge/fluids/IFluidHandler.java b/common/net/minecraftforge/fluids/IFluidHandler.java index 17e96343e..bc443e957 100644 --- a/common/net/minecraftforge/fluids/IFluidHandler.java +++ b/common/net/minecraftforge/fluids/IFluidHandler.java @@ -1,4 +1,3 @@ - package net.minecraftforge.fluids; import net.minecraftforge.common.ForgeDirection; @@ -12,8 +11,8 @@ import net.minecraftforge.common.ForgeDirection; * @author King Lemming * */ -public interface IFluidHandler { - +public interface IFluidHandler +{ /** * Fills fluid into internal tanks, distribution is left entirely to the IFluidHandler. * @@ -80,5 +79,4 @@ public interface IFluidHandler { * @return Info for the relevant internal tanks. */ FluidTankInfo[] getTankInfo(ForgeDirection from); - } diff --git a/common/net/minecraftforge/fluids/IFluidTank.java b/common/net/minecraftforge/fluids/IFluidTank.java index f88564857..741676185 100644 --- a/common/net/minecraftforge/fluids/IFluidTank.java +++ b/common/net/minecraftforge/fluids/IFluidTank.java @@ -1,4 +1,3 @@ - package net.minecraftforge.fluids; /** @@ -9,8 +8,8 @@ package net.minecraftforge.fluids; * @author King Lemming, cpw (ILiquidTank) * */ -public interface IFluidTank { - +public interface IFluidTank +{ /** * @return FluidStack representing the fluid in the tank, null if the tank is empty. */ @@ -55,5 +54,4 @@ public interface IFluidTank { * @return Amount of fluid that was removed from the tank. */ FluidStack drain(int maxDrain, boolean doDrain); - } diff --git a/common/net/minecraftforge/fluids/ItemFluidContainer.java b/common/net/minecraftforge/fluids/ItemFluidContainer.java index 5503cf423..e42703aa4 100644 --- a/common/net/minecraftforge/fluids/ItemFluidContainer.java +++ b/common/net/minecraftforge/fluids/ItemFluidContainer.java @@ -1,4 +1,3 @@ - package net.minecraftforge.fluids; import net.minecraft.item.Item; @@ -11,122 +10,149 @@ import net.minecraft.nbt.NBTTagCompound; * @author King Lemming * */ -public class ItemFluidContainer extends Item implements IFluidContainerItem { - +public class ItemFluidContainer extends Item implements IFluidContainerItem +{ protected int capacity; - public ItemFluidContainer(int itemID) { - + public ItemFluidContainer(int itemID) + { super(itemID); } - public ItemFluidContainer(int itemID, int capacity) { - + public ItemFluidContainer(int itemID, int capacity) + { super(itemID); this.capacity = capacity; } - public ItemFluidContainer setCapacity(int capacity) { - + public ItemFluidContainer setCapacity(int capacity) + { this.capacity = capacity; return this; } /* IFluidContainerItem */ @Override - public FluidStack getFluid(ItemStack container) { - - if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) { + public FluidStack getFluid(ItemStack container) + { + if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) + { return null; } return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid")); } @Override - public int getCapacity(ItemStack container) { - + public int getCapacity(ItemStack container) + { return capacity; } @Override - public int fill(ItemStack container, FluidStack resource, boolean doFill) { - - if (resource == null) { + public int fill(ItemStack container, FluidStack resource, boolean doFill) + { + if (resource == null) + { return 0; } - if (!doFill) { - if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) { + + if (!doFill) + { + if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) + { return Math.min(capacity, resource.amount); } + FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid")); - if (stack == null) { + if (stack == null) + { return Math.min(capacity, resource.amount); } - if (!stack.isFluidEqual(resource)) { + + if (!stack.isFluidEqual(resource)) + { return 0; } + return Math.min(capacity - stack.amount, resource.amount); } - if (container.stackTagCompound == null) { + + if (container.stackTagCompound == null) + { container.stackTagCompound = new NBTTagCompound(); } - if (!container.stackTagCompound.hasKey("Fluid")) { + + if (!container.stackTagCompound.hasKey("Fluid")) + { NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound()); - if (capacity < resource.amount) { + if (capacity < resource.amount) + { fluidTag.setInteger("Amount", capacity); container.stackTagCompound.setTag("Fluid", fluidTag); return capacity; } + container.stackTagCompound.setTag("Fluid", fluidTag); return resource.amount; } + NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid"); FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag); - if (!stack.isFluidEqual(resource)) { + if (!stack.isFluidEqual(resource)) + { return 0; } - int filled = capacity - resource.amount; - if (resource.amount < filled) { + int filled = capacity - resource.amount; + if (resource.amount < filled) + { stack.amount += resource.amount; filled = resource.amount; - } else { + } + else + { stack.amount = capacity; } + container.stackTagCompound.setTag("Fluid", stack.writeToNBT(fluidTag)); return filled; } @Override - public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) { - - if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) { + public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) + { + if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) + { return null; } + FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid")); - - if (stack == null) { + if (stack == null) + { return null; } - stack.amount = Math.min(stack.amount, maxDrain); - if (doDrain) { - if (maxDrain >= capacity) { + stack.amount = Math.min(stack.amount, maxDrain); + if (doDrain) + { + if (maxDrain >= capacity) + { container.stackTagCompound.removeTag("Fluid"); - if (container.stackTagCompound.hasNoTags()) { + if (container.stackTagCompound.hasNoTags()) + { container.stackTagCompound = null; } return stack; } + NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid"); fluidTag.setInteger("Amount", fluidTag.getInteger("Amount") - maxDrain); container.stackTagCompound.setTag("Fluid", fluidTag); } return stack; } - } diff --git a/common/net/minecraftforge/fluids/RenderBlockFluid.java b/common/net/minecraftforge/fluids/RenderBlockFluid.java index 971d62fbb..5a0e6b180 100644 --- a/common/net/minecraftforge/fluids/RenderBlockFluid.java +++ b/common/net/minecraftforge/fluids/RenderBlockFluid.java @@ -15,8 +15,8 @@ import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; * @author King Lemming * */ -public class RenderBlockFluid implements ISimpleBlockRenderingHandler { - +public class RenderBlockFluid implements ISimpleBlockRenderingHandler +{ public static RenderBlockFluid instance = new RenderBlockFluid(); static final float LIGHT_Y_NEG = 0.5F; @@ -25,16 +25,20 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { static final float LIGHT_XZ_POS = 0.6F; static final double RENDER_OFFSET = 0.0010000000474974513D; - public float getFluidHeightAverage(float[] flow) { - + public float getFluidHeightAverage(float[] flow) + { float total = 0; int count = 0; - for (int i = 0; i < flow.length; i++) { - if (flow[i] >= 0.875F) { + for (int i = 0; i < flow.length; i++) + { + if (flow[i] >= 0.875F) + { return flow[i]; } - if (flow[i] >= 0) { + + if (flow[i] >= 0) + { total += flow[i]; count++; } @@ -42,14 +46,17 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { return total / count; } - public float getFluidHeightForRender(IBlockAccess world, int x, int y, int z, BlockFluidBase block) { - - if (world.getBlockId(x, y, z) == block.blockID) { - - if (world.getBlockId(x, y - block.densityDir, z) == block.blockID) { + public float getFluidHeightForRender(IBlockAccess world, int x, int y, int z, BlockFluidBase block) + { + if (world.getBlockId(x, y, z) == block.blockID) + { + if (world.getBlockId(x, y - block.densityDir, z) == block.blockID) + { return 1; } - if (world.getBlockMetadata(x, y, z) == block.getMaxRenderHeightMeta()) { + + if (world.getBlockMetadata(x, y, z) == block.getMaxRenderHeightMeta()) + { return 0.875F; } } @@ -58,16 +65,16 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { /* ISimpleBlockRenderingHandler */ @Override - public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { - - } + public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer){} @Override - public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { - - if (!(block instanceof BlockFluidBase)) { + public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) + { + if (!(block instanceof BlockFluidBase)) + { return false; } + Tessellator tessellator = Tessellator.instance; int color = block.colorMultiplier(world, x, y, z); float red = (color >> 16 & 255) / 255.0F; @@ -81,33 +88,42 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { boolean renderBottom = block.shouldSideBeRendered(world, x, y + theFluid.densityDir, z, 0) && world.getBlockId(x, y + theFluid.densityDir, z) != theFluid.blockID; - boolean[] renderSides = new boolean[] { block.shouldSideBeRendered(world, x, y, z - 1, 2), block.shouldSideBeRendered(world, x, y, z + 1, 3), - block.shouldSideBeRendered(world, x - 1, y, z, 4), block.shouldSideBeRendered(world, x + 1, y, z, 5) }; + boolean[] renderSides = new boolean[] + { + block.shouldSideBeRendered(world, x, y, z - 1, 2), + block.shouldSideBeRendered(world, x, y, z + 1, 3), + block.shouldSideBeRendered(world, x - 1, y, z, 4), + block.shouldSideBeRendered(world, x + 1, y, z, 5) + }; - if (!renderTop && !renderBottom && !renderSides[0] && !renderSides[1] && !renderSides[2] && !renderSides[3]) { + if (!renderTop && !renderBottom && !renderSides[0] && !renderSides[1] && !renderSides[2] && !renderSides[3]) + { return false; - } else { + } + else + { boolean rendered = false; - double heightNW, heightSW, heightSE, heightNE; - float flow11 = getFluidHeightForRender(world, x, y, z, theFluid); - if (flow11 != 1) { + if (flow11 != 1) + { float flow00 = getFluidHeightForRender(world, x - 1, y, z - 1, theFluid); - float flow01 = getFluidHeightForRender(world, x - 1, y, z, theFluid); + float flow01 = getFluidHeightForRender(world, x - 1, y, z, theFluid); float flow02 = getFluidHeightForRender(world, x - 1, y, z + 1, theFluid); - float flow10 = getFluidHeightForRender(world, x, y, z - 1, theFluid); - float flow12 = getFluidHeightForRender(world, x, y, z + 1, theFluid); + float flow10 = getFluidHeightForRender(world, x, y, z - 1, theFluid); + float flow12 = getFluidHeightForRender(world, x, y, z + 1, theFluid); float flow20 = getFluidHeightForRender(world, x + 1, y, z - 1, theFluid); - float flow21 = getFluidHeightForRender(world, x + 1, y, z, theFluid); + float flow21 = getFluidHeightForRender(world, x + 1, y, z, theFluid); float flow22 = getFluidHeightForRender(world, x + 1, y, z + 1, theFluid); - heightNW = getFluidHeightAverage(new float[] { flow00, flow01, flow10, flow11 }); - heightSW = getFluidHeightAverage(new float[] { flow01, flow02, flow12, flow11 }); - heightSE = getFluidHeightAverage(new float[] { flow12, flow21, flow22, flow11 }); - heightNE = getFluidHeightAverage(new float[] { flow10, flow20, flow21, flow11 }); - } else { + heightNW = getFluidHeightAverage(new float[]{ flow00, flow01, flow10, flow11 }); + heightSW = getFluidHeightAverage(new float[]{ flow01, flow02, flow12, flow11 }); + heightSE = getFluidHeightAverage(new float[]{ flow12, flow21, flow22, flow11 }); + heightNE = getFluidHeightAverage(new float[]{ flow10, flow20, flow21, flow11 }); + } + else + { heightNW = flow11; heightSW = flow11; heightSE = flow11; @@ -115,16 +131,17 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { } boolean rises = theFluid.densityDir == 1; - - if (renderer.renderAllFaces || renderTop) { + if (renderer.renderAllFaces || renderTop) + { rendered = true; - Icon iconStill = block.getIcon(1, bMeta); float flowDir = (float) BlockFluidBase.getFlowDirection(world, x, y, z); - if (flowDir > -999.0F) { + if (flowDir > -999.0F) + { iconStill = block.getIcon(2, bMeta); } + heightNW -= RENDER_OFFSET; heightSW -= RENDER_OFFSET; heightSE -= RENDER_OFFSET; @@ -132,7 +149,8 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { double u1, u2, u3, u4, v1, v2, v3, v4; - if (flowDir < -999.0F) { + if (flowDir < -999.0F) + { u2 = iconStill.getInterpolatedU(0.0D); v2 = iconStill.getInterpolatedV(0.0D); u1 = u2; @@ -141,7 +159,9 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { v4 = v1; u3 = u4; v3 = v2; - } else { + } + else + { float xFlow = MathHelper.sin(flowDir) * 0.25F; float zFlow = MathHelper.cos(flowDir) * 0.25F; u2 = iconStill.getInterpolatedU(8.0F + (-zFlow - xFlow) * 16.0F); @@ -153,15 +173,19 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { u3 = iconStill.getInterpolatedU(8.0F + (zFlow - xFlow) * 16.0F); v3 = iconStill.getInterpolatedV(8.0F + (-zFlow - xFlow) * 16.0F); } + tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z)); tessellator.setColorOpaque_F(LIGHT_Y_POS * red, LIGHT_Y_POS * green, LIGHT_Y_POS * blue); - if (!rises) { + if (!rises) + { tessellator.addVertexWithUV(x + 0, y + heightNW, z + 0, u2, v2); tessellator.addVertexWithUV(x + 0, y + heightSW, z + 1, u1, v1); tessellator.addVertexWithUV(x + 1, y + heightSE, z + 1, u4, v4); tessellator.addVertexWithUV(x + 1, y + heightNE, z + 0, u3, v3); - } else { + } + else + { tessellator.addVertexWithUV(x + 1, y + 1 - heightNE, z + 0, u3, v3); tessellator.addVertexWithUV(x + 1, y + 1 - heightSE, z + 1, u4, v4); tessellator.addVertexWithUV(x + 0, y + 1 - heightSW, z + 1, u1, v1); @@ -169,40 +193,38 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { } } - if (renderer.renderAllFaces || renderBottom) { + if (renderer.renderAllFaces || renderBottom) + { rendered = true; - tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y - 1, z)); - - if (!rises) { + if (!rises) + { tessellator.setColorOpaque_F(LIGHT_Y_NEG, LIGHT_Y_NEG, LIGHT_Y_NEG); renderer.renderFaceYNeg(block, x, y + RENDER_OFFSET, z, block.getIcon(0, bMeta)); - } else { + } + else + { tessellator.setColorOpaque_F(LIGHT_Y_POS, LIGHT_Y_POS, LIGHT_Y_POS); renderer.renderFaceYPos(block, x, y + RENDER_OFFSET, z, block.getIcon(1, bMeta)); } } - for (int side = 0; side < 4; ++side) { + + for (int side = 0; side < 4; ++side) + { int x2 = x; int z2 = z; - switch (side) { - case 0: - --z2; - break; - case 1: - ++z2; - break; - case 2: - --x2; - break; - case 3: - ++x2; - break; + switch (side) + { + case 0: --z2; break; + case 1: ++z2; break; + case 2: --x2; break; + case 3: ++x2; break; } - Icon iconFlow = block.getIcon(side + 2, bMeta); - if (renderer.renderAllFaces || renderSides[side]) { + Icon iconFlow = block.getIcon(side + 2, bMeta); + if (renderer.renderAllFaces || renderSides[side]) + { rendered = true; double ty1; @@ -212,28 +234,35 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { double tz1; double tz2; - if (side == 0) { + if (side == 0) + { ty1 = heightNW; ty2 = heightNE; tx1 = x; tx2 = x + 1; tz1 = z + RENDER_OFFSET; tz2 = z + RENDER_OFFSET; - } else if (side == 1) { + } + else if (side == 1) + { ty1 = heightSE; ty2 = heightSW; tx1 = x + 1; tx2 = x; tz1 = z + 1 - RENDER_OFFSET; tz2 = z + 1 - RENDER_OFFSET; - } else if (side == 2) { + } + else if (side == 2) + { ty1 = heightSW; ty2 = heightNW; tx1 = x + RENDER_OFFSET; tx2 = x + RENDER_OFFSET; tz1 = z + 1; tz2 = z; - } else { + } + else + { ty1 = heightNE; ty2 = heightSE; tx1 = x + 1 - RENDER_OFFSET; @@ -241,6 +270,7 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { tz1 = z; tz2 = z + 1; } + float u1Flow = iconFlow.getInterpolatedU(0.0D); float u2Flow = iconFlow.getInterpolatedU(8.0D); float v1Flow = iconFlow.getInterpolatedV((1.0D - ty1) * 16.0D * 0.5D); @@ -249,19 +279,26 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x2, y, z2)); float sideLighting = 1.0F; - if (side < 2) { + if (side < 2) + { sideLighting = LIGHT_XZ_NEG; - } else { + } + else + { sideLighting = LIGHT_XZ_POS; } + tessellator.setColorOpaque_F(LIGHT_Y_POS * sideLighting * red, LIGHT_Y_POS * sideLighting * green, LIGHT_Y_POS * sideLighting * blue); - if (!rises) { + if (!rises) + { tessellator.addVertexWithUV(tx1, y + ty1, tz1, u1Flow, v1Flow); tessellator.addVertexWithUV(tx2, y + ty2, tz2, u2Flow, v2Flow); tessellator.addVertexWithUV(tx2, y + 0, tz2, u2Flow, v3Flow); tessellator.addVertexWithUV(tx1, y + 0, tz1, u1Flow, v3Flow); - } else { + } + else + { tessellator.addVertexWithUV(tx1, y + 1 - 0, tz1, u1Flow, v3Flow); tessellator.addVertexWithUV(tx2, y + 1 - 0, tz2, u2Flow, v3Flow); tessellator.addVertexWithUV(tx2, y + 1 - ty2, tz2, u2Flow, v2Flow); @@ -276,15 +313,10 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler { } @Override - public boolean shouldRender3DInInventory() { - - return false; - } - + public boolean shouldRender3DInInventory(){ return false; } @Override - public int getRenderId() { - + public int getRenderId() + { return FluidRegistry.renderIdFluid; } - } diff --git a/common/net/minecraftforge/fluids/TileFluidHandler.java b/common/net/minecraftforge/fluids/TileFluidHandler.java index 988c80f66..b39948624 100644 --- a/common/net/minecraftforge/fluids/TileFluidHandler.java +++ b/common/net/minecraftforge/fluids/TileFluidHandler.java @@ -11,62 +11,62 @@ import net.minecraftforge.common.ForgeDirection; * @author King Lemming * */ -public class TileFluidHandler extends TileEntity implements IFluidHandler { - +public class TileFluidHandler extends TileEntity implements IFluidHandler +{ protected FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME); @Override - public void readFromNBT(NBTTagCompound tag) { - + public void readFromNBT(NBTTagCompound tag) + { super.readFromNBT(tag); tank.writeToNBT(tag); } @Override - public void writeToNBT(NBTTagCompound tag) { - + public void writeToNBT(NBTTagCompound tag) + { super.writeToNBT(tag); tank.readFromNBT(tag); } /* IFluidHandler */ @Override - public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { - + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) + { return tank.fill(resource, doFill); } @Override - public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { - - if (resource == null || !resource.isFluidEqual(tank.getFluid())) { + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) + { + if (resource == null || !resource.isFluidEqual(tank.getFluid())) + { return null; } return tank.drain(resource.amount, doDrain); } @Override - public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { return tank.drain(maxDrain, doDrain); } @Override - public boolean canFill(ForgeDirection from, Fluid fluid) { - + public boolean canFill(ForgeDirection from, Fluid fluid) + { return true; } @Override - public boolean canDrain(ForgeDirection from, Fluid fluid) { - + public boolean canDrain(ForgeDirection from, Fluid fluid) + { return true; } @Override - public FluidTankInfo[] getTankInfo(ForgeDirection from) { - + public FluidTankInfo[] getTankInfo(ForgeDirection from) + { return new FluidTankInfo[] { tank.getInfo() }; } - }