General code cleanup of Fluid system. Made Fluid icons and associated functions non-sided.

This commit is contained in:
LexManos 2013-07-16 21:40:49 -07:00
parent f7ab5684e9
commit acb6777ab5
18 changed files with 995 additions and 887 deletions

View file

@ -21,16 +21,17 @@ import net.minecraft.world.World;
* @author King Lemming, OvermindDL1 * @author King Lemming, OvermindDL1
* *
*/ */
public abstract class BlockFluidBase extends Block implements IFluidBlock { public abstract class BlockFluidBase extends Block implements IFluidBlock
{
protected final static Map<Integer, Boolean> defaultDisplacementIds = new HashMap<Integer, Boolean>(); protected final static Map<Integer, Boolean> defaultDisplacementIds = new HashMap<Integer, Boolean>();
static { static
{
defaultDisplacementIds.put(Block.doorWood.blockID, false); defaultDisplacementIds.put(Block.doorWood.blockID, false);
defaultDisplacementIds.put(Block.doorIron.blockID, false); defaultDisplacementIds.put(Block.doorIron.blockID, false);
defaultDisplacementIds.put(Block.signPost.blockID, false); defaultDisplacementIds.put(Block.signPost.blockID, false);
defaultDisplacementIds.put(Block.signWall.blockID, false); defaultDisplacementIds.put(Block.signWall.blockID, false);
defaultDisplacementIds.put(Block.reed.blockID, false); defaultDisplacementIds.put(Block.reed.blockID, false);
} }
protected Map<Integer, Boolean> displacementIds = new HashMap<Integer, Boolean>(); protected Map<Integer, Boolean> displacementIds = new HashMap<Integer, Boolean>();
@ -45,8 +46,8 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock {
protected final String fluidName; protected final String fluidName;
public BlockFluidBase(int id, Fluid fluid, Material material) { public BlockFluidBase(int id, Fluid fluid, Material material)
{
super(id, material); super(id, material);
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
this.setTickRandomly(true); this.setTickRandomly(true);
@ -61,43 +62,37 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock {
displacementIds.putAll(defaultDisplacementIds); displacementIds.putAll(defaultDisplacementIds);
} }
public BlockFluidBase setQuantaPerBlock(int quantaPerBlock) { public BlockFluidBase setQuantaPerBlock(int quantaPerBlock)
{
if (quantaPerBlock > 16 || quantaPerBlock < 1) { if (quantaPerBlock > 16 || quantaPerBlock < 1) quantaPerBlock = 8;
quantaPerBlock = 8;
}
this.quantaPerBlock = quantaPerBlock; this.quantaPerBlock = quantaPerBlock;
this.quantaPerBlockFloat = quantaPerBlock; this.quantaPerBlockFloat = quantaPerBlock;
return this; return this;
} }
public BlockFluidBase setDensity(int density) { public BlockFluidBase setDensity(int density)
{
if (density == 0) { if (density == 0) density = 1;
density = 1;
}
this.density = density; this.density = density;
this.densityDir = density > 0 ? -1 : 1; this.densityDir = density > 0 ? -1 : 1;
return this; return this;
} }
public BlockFluidBase setTickRate(int tickRate) { public BlockFluidBase setTickRate(int tickRate)
{
if (tickRate <= 0) { if (tickRate <= 0) tickRate = 20;
tickRate = 20;
}
this.tickRate = tickRate; this.tickRate = tickRate;
return this; return this;
} }
public BlockFluidBase setRenderPass(int renderPass) { public BlockFluidBase setRenderPass(int renderPass)
{
this.renderPass = renderPass; this.renderPass = renderPass;
return this; return this;
} }
public BlockFluidBase setMaxScaledLight(int maxScaledLight) { public BlockFluidBase setMaxScaledLight(int maxScaledLight)
{
this.maxScaledLight = maxScaledLight; this.maxScaledLight = maxScaledLight;
return this; 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. * 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); int bId = world.getBlockId(x, y, z);
if (bId == 0) { if (bId == blockID)
return true; {
}
if (bId == blockID) {
return false; return false;
} }
if (displacementIds.containsKey(bId)) {
if (displacementIds.containsKey(bId))
{
return displacementIds.get(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 false;
} }
return true; 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. * 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) { public boolean displaceIfPossible(World world, int x, int y, int z)
{
int bId = world.getBlockId(x, y, z); if (world.isAirBlock(x, y, z))
{
if (bId == 0) {
return true; return true;
} }
if (bId == blockID) {
int bId = world.getBlockId(x, y, z);
if (bId == blockID)
{
return false; 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); Block.blocksList[bId].dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
return true; return true;
} }
return false; 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; return false;
} }
Block.blocksList[bId].dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0); 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 */ /* BLOCK FUNCTIONS */
@Override @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); world.scheduleBlockUpdate(x, y, z, blockID, tickRate);
} }
@Override @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); world.scheduleBlockUpdate(x, y, z, blockID, tickRate);
} }
// Used to prevent updates on chunk generation // Used to prevent updates on chunk generation
@Override @Override
public boolean func_82506_l() { public boolean func_82506_l()
{
return false; return false;
} }
@Override @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; return true;
} }
@Override @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; return null;
} }
@Override @Override
public int idDropped(int par1, Random par2Random, int par3) { public int idDropped(int par1, Random par2Random, int par3)
{
return 0; return 0;
} }
@Override @Override
public int quantityDropped(Random par1Random) { public int quantityDropped(Random par1Random)
{
return 0; return 0;
} }
@Override @Override
public int tickRate(World world) { public int tickRate(World world)
{
return tickRate; return tickRate;
} }
@Override @Override
public void velocityToAddToEntity(World world, int x, int y, int z, Entity entity, Vec3 vec) { public void velocityToAddToEntity(World world, int x, int y, int z, Entity entity, Vec3 vec)
{
if (densityDir > 0) { if (densityDir > 0) return;
return;
}
Vec3 vec_flow = this.getFlowVector(world, x, y, z); Vec3 vec_flow = this.getFlowVector(world, x, y, z);
vec.xCoord += vec_flow.xCoord * (quantaPerBlock * 4); vec.xCoord += vec_flow.xCoord * (quantaPerBlock * 4);
vec.yCoord += vec_flow.yCoord * (quantaPerBlock * 4); vec.yCoord += vec_flow.yCoord * (quantaPerBlock * 4);
@ -225,9 +227,10 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock {
} }
@Override @Override
public int getLightValue(IBlockAccess world, int x, int y, int z) { public int getLightValue(IBlockAccess world, int x, int y, int z)
{
if (maxScaledLight == 0) { if (maxScaledLight == 0)
{
return super.getLightValue(world, x, y, z); return super.getLightValue(world, x, y, z);
} }
int data = world.getBlockMetadata(x, y, z); int data = world.getBlockMetadata(x, y, z);
@ -235,55 +238,55 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock {
} }
@Override @Override
public int getRenderType() { public int getRenderType()
{
return FluidRegistry.renderIdFluid; return FluidRegistry.renderIdFluid;
} }
@Override @Override
public boolean isOpaqueCube() { public boolean isOpaqueCube()
{
return false; return false;
} }
@Override @Override
public boolean renderAsNormalBlock() { public boolean renderAsNormalBlock()
{
return false; return false;
} }
@Override @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 lightThis = world.getLightBrightness(x, y, z);
float lightUp = world.getLightBrightness(x, y + 1, z); float lightUp = world.getLightBrightness(x, y + 1, z);
return lightThis > lightUp ? lightThis : lightUp; return lightThis > lightUp ? lightThis : lightUp;
} }
@Override @Override
public int getMixedBrightnessForBlock(IBlockAccess world, int x, int y, int z) { public int getMixedBrightnessForBlock(IBlockAccess world, int x, int y, int z)
{
int lightThis = world.getLightBrightnessForSkyBlocks(x, y, z, 0); int lightThis = world.getLightBrightnessForSkyBlocks(x, y, z, 0);
int lightUp = world.getLightBrightnessForSkyBlocks(x, y + 1, z, 0); int lightUp = world.getLightBrightnessForSkyBlocks(x, y + 1, z, 0);
int lightThisBase = lightThis & 255; int lightThisBase = lightThis & 255;
int lightUpBase = lightUp & 255; int lightUpBase = lightUp & 255;
int lightThisExt = lightThis >> 16 & 255; int lightThisExt = lightThis >> 16 & 255;
int lightUpExt = lightUp >> 16 & 255; int lightUpExt = lightUp >> 16 & 255;
return (lightThisBase > lightUpBase ? lightThisBase : lightUpBase) |
return (lightThisBase > lightUpBase ? lightThisBase : lightUpBase) | (lightThisExt > lightUpExt ? lightThisExt : lightUpExt) << 16; ((lightThisExt > lightUpExt ? lightThisExt : lightUpExt) << 16);
} }
@Override @Override
public int getRenderBlockPass() { public int getRenderBlockPass()
{
return renderPass; return renderPass;
} }
@Override @Override
public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) { public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side)
{
if (world.getBlockId(x, y, z) != blockID) { if (world.getBlockId(x, y, z) != blockID)
{
return !world.isBlockOpaqueCube(x, y, z); return !world.isBlockOpaqueCube(x, y, z);
} }
Material mat = world.getBlockMaterial(x, y, z); Material mat = world.getBlockMaterial(x, y, z);
@ -291,114 +294,105 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock {
} }
/* FLUID FUNCTIONS */ /* 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)]; Block block = Block.blocksList[world.getBlockId(x, y, z)];
if (!(block instanceof BlockFluidBase))
if (!(block instanceof BlockFluidBase)) { {
return Integer.MAX_VALUE; 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)]; Block block = Block.blocksList[world.getBlockId(x, y, z)];
if (!(block instanceof BlockFluidBase))
if (!(Block.blocksList[world.getBlockId(x, y, z)] instanceof BlockFluidBase)) { {
return -1000.0; return -1000.0;
} }
Vec3 vec = ((BlockFluidBase) block).getFlowVector(world, x, y, z); 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; 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); int quantaRemaining = getQuantaValue(world, x, y, z);
if (quantaRemaining >= belowThis)
if (quantaRemaining >= belowThis) { {
return -1; return -1;
} }
return quantaRemaining; 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); int quantaRemaining = getQuantaValue(world, x, y, z);
if (quantaRemaining <= aboveThis)
if (quantaRemaining <= aboveThis) { {
return -1; return -1;
} }
return quantaRemaining; 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); int quantaRemaining = getQuantaValue(world, x, y, z);
return quantaRemaining / quantaPerBlockFloat; 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); Vec3 vec = world.getWorldVec3Pool().getVecFromPool(0.0D, 0.0D, 0.0D);
int decay = quantaPerBlock - getQuantaValue(world, x, y, z); 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 x2 = x;
int z2 = z; int z2 = z;
switch (side) { switch (side)
case 0: {
--x2; case 0: --x2; break;
break; case 1: --z2; break;
case 1: case 2: ++x2; break;
--z2; case 3: ++z2; break;
break;
case 2:
++x2;
break;
case 3:
++z2;
break;
} }
int otherDecay = quantaPerBlock - getQuantaValue(world, x2, y, z2); int otherDecay = quantaPerBlock - getQuantaValue(world, x2, y, z2);
if (otherDecay >= quantaPerBlock)
if (otherDecay >= quantaPerBlock) { {
if (!world.getBlockMaterial(x2, y, z2).blocksMovement()) { if (!world.getBlockMaterial(x2, y, z2).blocksMovement())
{
otherDecay = quantaPerBlock - getQuantaValue(world, x2, y - 1, z2); otherDecay = quantaPerBlock - getQuantaValue(world, x2, y - 1, z2);
if (otherDecay >= 0)
if (otherDecay >= 0) { {
int power = otherDecay - (decay - quantaPerBlock); int power = otherDecay - (decay - quantaPerBlock);
vec = vec.addVector((x2 - x) * power, (y - y) * power, (z2 - z) * power); vec = vec.addVector((x2 - x) * power, (y - y) * power, (z2 - z) * power);
} }
} }
} else if (otherDecay >= 0) { }
else if (otherDecay >= 0)
{
int power = otherDecay - decay; int power = otherDecay - decay;
vec = vec.addVector((x2 - x) * power, (y - y) * power, (z2 - z) * power); 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)) { if (world.getBlockId(x, y + 1, z) == blockID)
flag = true; {
} else if (this.isBlockSolid(world, x, y, z + 1, 3)) { boolean flag =
flag = true; isBlockSolid(world, x, y, z - 1, 2) ||
} else if (this.isBlockSolid(world, x - 1, y, z, 4)) { isBlockSolid(world, x, y, z + 1, 3) ||
flag = true; isBlockSolid(world, x - 1, y, z, 4) ||
} else if (this.isBlockSolid(world, x + 1, y, z, 5)) { isBlockSolid(world, x + 1, y, z, 5) ||
flag = true; isBlockSolid(world, x, y + 1, z - 1, 2) ||
} else if (this.isBlockSolid(world, x, y + 1, z - 1, 2)) { isBlockSolid(world, x, y + 1, z + 1, 3) ||
flag = true; isBlockSolid(world, x - 1, y + 1, z, 4) ||
} else if (this.isBlockSolid(world, x, y + 1, z + 1, 3)) { isBlockSolid(world, x + 1, y + 1, z, 5);
flag = true;
} else if (this.isBlockSolid(world, x - 1, y + 1, z, 4)) { if (flag)
flag = true; {
} else if (this.isBlockSolid(world, x + 1, y + 1, z, 5)) {
flag = true;
}
if (flag) {
vec = vec.normalize().addVector(0.0D, -6.0D, 0.0D); vec = vec.normalize().addVector(0.0D, -6.0D, 0.0D);
} }
} }
@ -408,9 +402,8 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock {
/* IFluidBlock */ /* IFluidBlock */
@Override @Override
public Fluid getFluid() { public Fluid getFluid()
{
return FluidRegistry.getFluid(fluidName); return FluidRegistry.getFluid(fluidName);
} }
} }

View file

@ -16,60 +16,65 @@ import net.minecraft.world.World;
* @author King Lemming * @author King Lemming
* *
*/ */
public class BlockFluidClassic extends BlockFluidBase { public class BlockFluidClassic extends BlockFluidBase
{
protected boolean[] isOptimalFlowDirection = new boolean[4]; protected boolean[] isOptimalFlowDirection = new boolean[4];
protected int[] flowCost = new int[4]; protected int[] flowCost = new int[4];
protected FluidStack stack; protected FluidStack stack;
public BlockFluidClassic(int id, Fluid fluid, Material material) { public BlockFluidClassic(int id, Fluid fluid, Material material)
{
super(id, fluid, material); super(id, fluid, material);
stack = new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME); stack = new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
} }
public BlockFluidClassic setFluidStack(FluidStack stack) { public BlockFluidClassic setFluidStack(FluidStack stack)
{
this.stack = stack; this.stack = stack;
return this; return this;
} }
public BlockFluidClassic setFluidStackAmount(int amount) { public BlockFluidClassic setFluidStackAmount(int amount)
{
this.stack.amount = amount; this.stack.amount = amount;
return this; return this;
} }
@Override @Override
public int getQuantaValue(IBlockAccess world, int x, int y, int z) { public int getQuantaValue(IBlockAccess world, int x, int y, int z)
{
if (world.getBlockId(x, y, z) == 0) { if (world.getBlockId(x, y, z) == 0)
{
return 0; return 0;
} }
if (world.getBlockId(x, y, z) != blockID) {
if (world.getBlockId(x, y, z) != blockID)
{
return -1; return -1;
} }
int quantaRemaining = quantaPerBlock - world.getBlockMetadata(x, y, z); int quantaRemaining = quantaPerBlock - world.getBlockMetadata(x, y, z);
return quantaRemaining; return quantaRemaining;
} }
@Override @Override
public boolean canCollideCheck(int meta, boolean fullHit) { public boolean canCollideCheck(int meta, boolean fullHit)
{
return fullHit && meta == 0; return fullHit && meta == 0;
} }
@Override @Override
public int getMaxRenderHeightMeta() { public int getMaxRenderHeightMeta()
{
return 0; return 0;
} }
@Override @Override
public int getLightValue(IBlockAccess world, int x, int y, int z) { public int getLightValue(IBlockAccess world, int x, int y, int z)
{
if (maxScaledLight == 0) { if (maxScaledLight == 0)
{
return super.getLightValue(world, x, y, z); return super.getLightValue(world, x, y, z);
} }
int data = quantaPerBlock - world.getBlockMetadata(x, y, z) - 1; int data = quantaPerBlock - world.getBlockMetadata(x, y, z) - 1;
@ -77,138 +82,155 @@ public class BlockFluidClassic extends BlockFluidBase {
} }
@Override @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 quantaRemaining = quantaPerBlock - world.getBlockMetadata(x, y, z);
int expQuanta = -101; int expQuanta = -101;
// check adjacent block levels if non-source // check adjacent block levels if non-source
if (quantaRemaining < quantaPerBlock) { if (quantaRemaining < quantaPerBlock)
{
int y2 = y - densityDir; 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 if (world.getBlockId(x, y2, z ) == blockID ||
|| world.getBlockId(x, y2, z - 1) == blockID || world.getBlockId(x, y2, z + 1) == 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; expQuanta = quantaPerBlock - 1;
}
} else { else
{
int maxQuanta = -100; int maxQuanta = -100;
maxQuanta = getLargerQuanta(world, x - 1, y, z, maxQuanta); maxQuanta = getLargerQuanta(world, x - 1, y, z, 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);
maxQuanta = getLargerQuanta(world, x, y, z + 1, maxQuanta); maxQuanta = getLargerQuanta(world, x, y, z + 1, maxQuanta);
expQuanta = maxQuanta - 1; expQuanta = maxQuanta - 1;
} }
// decay calculation // decay calculation
if (expQuanta != quantaRemaining) { if (expQuanta != quantaRemaining)
{
quantaRemaining = expQuanta; quantaRemaining = expQuanta;
if (expQuanta <= 0) { if (expQuanta <= 0)
{
world.setBlockToAir(x, y, z); world.setBlockToAir(x, y, z);
} else { }
else
{
world.setBlockMetadataWithNotify(x, y, z, quantaPerBlock - expQuanta, 3); world.setBlockMetadataWithNotify(x, y, z, quantaPerBlock - expQuanta, 3);
world.scheduleBlockUpdate(x, y, z, blockID, tickRate); world.scheduleBlockUpdate(x, y, z, blockID, tickRate);
world.notifyBlocksOfNeighborChange(x, y, z, blockID); world.notifyBlocksOfNeighborChange(x, y, z, blockID);
} }
} }
} else if (quantaRemaining > quantaPerBlock) { }
else if (quantaRemaining > quantaPerBlock)
{
world.setBlockMetadataWithNotify(x, y, z, 0, 3); world.setBlockMetadataWithNotify(x, y, z, 0, 3);
} }
// Flow vertically if possible // 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); flowIntoBlock(world, x, y + densityDir, z, 1);
return; return;
} }
// Flow outward if possible // Flow outward if possible
int flowMeta = quantaPerBlock - quantaRemaining + 1; int flowMeta = quantaPerBlock - quantaRemaining + 1;
if (flowMeta >= quantaPerBlock) { if (flowMeta >= quantaPerBlock)
{
return; return;
} }
if (isSourceBlock(world, x, y, z) || !isFlowingVertically(world, x, y, z)) { if (isSourceBlock(world, x, y, z) || !isFlowingVertically(world, x, y, z))
{
if (world.getBlockId(x, y - densityDir, z) == blockID) { if (world.getBlockId(x, y - densityDir, z) == blockID)
{
flowMeta = 1; flowMeta = 1;
} }
boolean flowTo[] = getOptimalFlowDirections(world, x, y, z); boolean flowTo[] = getOptimalFlowDirections(world, x, y, z);
if (flowTo[0]) { if (flowTo[0]) flowIntoBlock(world, x - 1, y, z, flowMeta);
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[1]) { if (flowTo[3]) flowIntoBlock(world, x, y, z + 1, flowMeta);
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) { 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); 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; return world.getBlockId(x, y, z) == blockID && world.getBlockMetadata(x, y, z) == 0;
} }
protected boolean[] getOptimalFlowDirections(World world, int x, int y, int z) { protected boolean[] getOptimalFlowDirections(World world, int x, int y, int z)
{
for (int side = 0; side < 4; side++) { for (int side = 0; side < 4; side++)
{
flowCost[side] = 1000; flowCost[side] = 1000;
int x2 = x; int x2 = x;
int y2 = y; int y2 = y;
int z2 = z; int z2 = z;
switch (side) { switch (side)
case 0: {
--x2; case 0: --x2; break;
break; case 1: ++x2; break;
case 1: case 2: --z2; break;
++x2; case 3: ++z2; break;
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; continue;
} }
if (canFlowInto(world, x2, y2 + densityDir, z2)) {
if (canFlowInto(world, x2, y2 + densityDir, z2))
{
flowCost[side] = 0; flowCost[side] = 0;
} else { }
else
{
flowCost[side] = calculateFlowCost(world, x2, y2, z2, 1, side); flowCost[side] = calculateFlowCost(world, x2, y2, z2, 1, side);
} }
} }
int min = flowCost[0]; int min = flowCost[0];
for (int side = 1; side < 4; side++) { for (int side = 1; side < 4; side++)
if (flowCost[side] < min) { {
if (flowCost[side] < min)
{
min = flowCost[side]; min = flowCost[side];
} }
} }
for (int side = 0; side < 4; side++) { for (int side = 0; side < 4; side++)
{
isOptimalFlowDirection[side] = flowCost[side] == min; isOptimalFlowDirection[side] = flowCost[side] == min;
} }
return isOptimalFlowDirection; 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; int cost = 1000;
for (int adjSide = 0; adjSide < 4; adjSide++)
for (int adjSide = 0; adjSide < 4; adjSide++) { {
if (adjSide == 0 && side == 1 || adjSide == 1 && side == 0 || adjSide == 2 && side == 3 || adjSide == 3 && side == 2) { if ((adjSide == 0 && side == 1) ||
(adjSide == 1 && side == 0) ||
(adjSide == 2 && side == 3) ||
(adjSide == 3 && side == 2))
{
continue; continue;
} }
@ -216,72 +238,78 @@ public class BlockFluidClassic extends BlockFluidBase {
int y2 = y; int y2 = y;
int z2 = z; int z2 = z;
switch (adjSide) { switch (adjSide)
case 0: {
--x2; case 0: --x2; break;
break; case 1: ++x2; break;
case 1: case 2: --z2; break;
++x2; case 3: ++z2; break;
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; continue;
} }
if (canFlowInto(world, x2, y2 + densityDir, z2)) {
if (canFlowInto(world, x2, y2 + densityDir, z2))
{
return recurseDepth; return recurseDepth;
} }
if (recurseDepth >= 4) {
if (recurseDepth >= 4)
{
continue; continue;
} }
int min = calculateFlowCost(world, x2, y2, z2, recurseDepth + 1, adjSide); int min = calculateFlowCost(world, x2, y2, z2, recurseDepth + 1, adjSide);
if (min < cost) { if (min < cost)
{
cost = min; cost = min;
} }
} }
return cost; return cost;
} }
protected void flowIntoBlock(World world, int x, int y, int z, int meta) { protected void flowIntoBlock(World world, int x, int y, int z, int meta)
{
if (meta < 0) { if (meta < 0) return;
return; if (displaceIfPossible(world, x, y, z))
} {
if (displaceIfPossible(world, x, y, z)) {
world.setBlock(x, y, z, this.blockID, meta, 3); 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); int bId = world.getBlockId(x, y, z);
if (bId == 0) { if (bId == blockID)
{
return true; return true;
} }
if (bId == blockID) {
return true; if (displacementIds.containsKey(bId))
} {
if (displacementIds.containsKey(bId)) {
return displacementIds.get(bId); return displacementIds.get(bId);
} }
Material material = Block.blocksList[bId].blockMaterial; 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 false;
} }
return true; 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); int quantaRemaining = getQuantaValue(world, x, y, z);
if (quantaRemaining <= 0)
if (quantaRemaining <= 0) { {
return compare; return compare;
} }
return quantaRemaining >= compare ? quantaRemaining : compare; return quantaRemaining >= compare ? quantaRemaining : compare;
@ -289,21 +317,24 @@ public class BlockFluidClassic extends BlockFluidBase {
/* IFluidBlock */ /* IFluidBlock */
@Override @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)
{
if (!isSourceBlock(world, x, y, z)) { if (!isSourceBlock(world, x, y, z))
{
return null; return null;
} }
if (doDrain) {
if (doDrain)
{
world.setBlockToAir(x, y, z); world.setBlockToAir(x, y, z);
} }
return stack.copy(); return stack.copy();
} }
@Override @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); return isSourceBlock(world, x, y, z);
} }
} }

View file

@ -16,41 +16,44 @@ import net.minecraft.world.World;
* @author OvermindDL1, KingLemming * @author OvermindDL1, KingLemming
* *
*/ */
public class BlockFluidFinite extends BlockFluidBase { public class BlockFluidFinite extends BlockFluidBase
{
public BlockFluidFinite(int id, Fluid fluid, Material material) { public BlockFluidFinite(int id, Fluid fluid, Material material)
{
super(id, fluid, material); super(id, fluid, material);
} }
@Override @Override
public int getQuantaValue(IBlockAccess world, int x, int y, int z) { public int getQuantaValue(IBlockAccess world, int x, int y, int z)
{
if (world.getBlockId(x, y, z) == 0) { if (world.isAirBlock(x, y, z))
{
return 0; return 0;
} }
if (world.getBlockId(x, y, z) != blockID) { if (world.getBlockId(x, y, z) != blockID) {
return -1; return -1;
} }
int quantaRemaining = world.getBlockMetadata(x, y, z) + 1; int quantaRemaining = world.getBlockMetadata(x, y, z) + 1;
return quantaRemaining; return quantaRemaining;
} }
@Override @Override
public boolean canCollideCheck(int meta, boolean fullHit) { public boolean canCollideCheck(int meta, boolean fullHit)
{
return fullHit && meta == quantaPerBlock - 1; return fullHit && meta == quantaPerBlock - 1;
} }
@Override @Override
public int getMaxRenderHeightMeta() { public int getMaxRenderHeightMeta()
{
return quantaPerBlock - 1; return quantaPerBlock - 1;
} }
@Override @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; boolean changed = false;
int quantaRemaining = world.getBlockMetadata(x, y, z) + 1; int quantaRemaining = world.getBlockMetadata(x, y, z) + 1;
@ -58,103 +61,124 @@ public class BlockFluidFinite extends BlockFluidBase {
int prevRemaining = quantaRemaining; int prevRemaining = quantaRemaining;
quantaRemaining = tryToFlowVerticallyInto(world, x, y, z, quantaRemaining); quantaRemaining = tryToFlowVerticallyInto(world, x, y, z, quantaRemaining);
if (quantaRemaining < 1) { if (quantaRemaining < 1)
{
return; return;
} else if (quantaRemaining != prevRemaining) { }
else if (quantaRemaining != prevRemaining)
{
changed = true; changed = true;
if (quantaRemaining == 1)
if (quantaRemaining == 1) { {
world.setBlockMetadataWithNotify(x, y, z, quantaRemaining - 1, 2); world.setBlockMetadataWithNotify(x, y, z, quantaRemaining - 1, 2);
return; return;
} }
} else if (quantaRemaining == 1) { }
else if (quantaRemaining == 1)
{
return; return;
} }
// Flow out if possible // Flow out if possible
int lowerthan = quantaRemaining - 1; 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)) { if (displaceIfPossible(world, x, y, z + 1)) world.setBlock(x, y, z + 1, 0);
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);
if (displaceIfPossible(world, x, y, z + 1)) { int north = getQuantaValueBelow(world, x, y, z - 1, lowerthan);
world.setBlock(x, y, z + 1, 0); int south = getQuantaValueBelow(world, x, y, z + 1, lowerthan);
} int west = getQuantaValueBelow(world, x - 1, y, z, lowerthan);
if (displaceIfPossible(world, x - 1, y, z)) { int east = getQuantaValueBelow(world, x + 1, y, z, lowerthan);
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 total = quantaRemaining;
int count = 1; int count = 1;
if (north >= 0) { if (north >= 0)
++count; {
count++;
total += north; total += north;
} }
if (south >= 0) {
++count; if (south >= 0)
{
count++;
total += south; total += south;
} }
if (west >= 0) {
++count; if (west >= 0)
{
count++;
total += west; total += west;
} }
if (east >= 0) { if (east >= 0) {
++count; ++count;
total += east; total += east;
} }
if (count == 1) {
if (changed) { if (count == 1)
{
if (changed)
{
world.setBlockMetadataWithNotify(x, y, z, quantaRemaining - 1, 2); world.setBlockMetadataWithNotify(x, y, z, quantaRemaining - 1, 2);
} }
return; return;
} }
int each = total / count; int each = total / count;
int rem = total % count; int rem = total % count;
if (north >= 0) { if (north >= 0)
{
int newnorth = each; int newnorth = each;
if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0)
if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0) { {
++newnorth; ++newnorth;
--rem; --rem;
} }
if (newnorth != north) {
if (newnorth == 0) { if (newnorth != north)
{
if (newnorth == 0)
{
world.setBlock(x, y, z - 1, 0); world.setBlock(x, y, z - 1, 0);
} else { }
else
{
world.setBlock(x, y, z - 1, blockID, newnorth - 1, 2); world.setBlock(x, y, z - 1, blockID, newnorth - 1, 2);
} }
world.scheduleBlockUpdate(x, y, z - 1, blockID, tickRate); world.scheduleBlockUpdate(x, y, z - 1, blockID, tickRate);
} }
--count; --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; ++newsouth;
--rem; --rem;
} }
if (newsouth != south) {
if (newsouth == 0) { if (newsouth != south)
{
if (newsouth == 0)
{
world.setBlock(x, y, z + 1, 0); world.setBlock(x, y, z + 1, 0);
} else { }
else
{
world.setBlock(x, y, z + 1, blockID, newsouth - 1, 2); world.setBlock(x, y, z + 1, blockID, newsouth - 1, 2);
} }
world.scheduleBlockUpdate(x, y, z + 1, blockID, tickRate); world.scheduleBlockUpdate(x, y, z + 1, blockID, tickRate);
} }
--count; --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; ++newwest;
--rem; --rem;
} }
@ -168,66 +192,86 @@ public class BlockFluidFinite extends BlockFluidBase {
} }
--count; --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; ++neweast;
--rem; --rem;
} }
if (neweast != east) {
if (neweast == 0) { if (neweast != east)
{
if (neweast == 0)
{
world.setBlock(x + 1, y, z, 0); world.setBlock(x + 1, y, z, 0);
} else { }
else
{
world.setBlock(x + 1, y, z, blockID, neweast - 1, 2); world.setBlock(x + 1, y, z, blockID, neweast - 1, 2);
} }
world.scheduleBlockUpdate(x + 1, y, z, blockID, tickRate); world.scheduleBlockUpdate(x + 1, y, z, blockID, tickRate);
} }
--count; --count;
} }
if (rem > 0) {
if (rem > 0)
{
++each; ++each;
} }
world.setBlockMetadataWithNotify(x, y, z, each - 1, 2); 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; int otherY = y + densityDir;
if (otherY < 0 || otherY >= world.getHeight())
if (otherY < 0 || otherY >= world.getHeight()) { {
world.setBlockToAir(x, y, z); world.setBlockToAir(x, y, z);
return 0; 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; amt += amtToInput;
if (amt > quantaPerBlock) { if (amt > quantaPerBlock)
{
world.setBlock(x, otherY, z, blockID, quantaPerBlock - 1, 3); world.setBlock(x, otherY, z, blockID, quantaPerBlock - 1, 3);
world.scheduleBlockUpdate(x, otherY, z, blockID, tickRate); world.scheduleBlockUpdate(x, otherY, z, blockID, tickRate);
return amt - quantaPerBlock; return amt - quantaPerBlock;
} else if (amt > 0) { }
else if (amt > 0)
{
world.setBlock(x, otherY, z, blockID, amt - 1, 3); world.setBlock(x, otherY, z, blockID, amt - 1, 3);
world.scheduleBlockUpdate(x, otherY, z, blockID, tickRate); world.scheduleBlockUpdate(x, otherY, z, blockID, tickRate);
world.setBlockToAir(x, y, z); world.setBlockToAir(x, y, z);
return 0; return 0;
} }
return amtToInput; return amtToInput;
} else { }
else
{
int density_other = getDensity(world, x, otherY, z); int density_other = getDensity(world, x, otherY, z);
if (density_other == Integer.MAX_VALUE)
if (density_other == Integer.MAX_VALUE) { {
if (displaceIfPossible(world, x, otherY, z)) { if (displaceIfPossible(world, x, otherY, z))
{
world.setBlock(x, otherY, z, blockID, amtToInput - 1, 3); world.setBlock(x, otherY, z, blockID, amtToInput - 1, 3);
world.scheduleBlockUpdate(x, otherY, z, blockID, tickRate); world.scheduleBlockUpdate(x, otherY, z, blockID, tickRate);
world.setBlockToAir(x, y, z); world.setBlockToAir(x, y, z);
return 0; return 0;
} else { }
else
{
return amtToInput; return amtToInput;
} }
} }
if (densityDir < 0) {
if (densityDir < 0)
{
if (density_other < density) // then swap if (density_other < density) // then swap
{ {
int bId = world.getBlockId(x, otherY, z); 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)); world.scheduleBlockUpdate(x, y, z, bId, block.tickRate(world));
return 0; return 0;
} }
} else { }
if (density_other > density) { else
{
if (density_other > density)
{
int bId = world.getBlockId(x, otherY, z); int bId = world.getBlockId(x, otherY, z);
BlockFluidBase block = (BlockFluidBase) Block.blocksList[bId]; BlockFluidBase block = (BlockFluidBase) Block.blocksList[bId];
int otherData = world.getBlockMetadata(x, otherY, z); int otherData = world.getBlockMetadata(x, otherY, z);
@ -257,15 +304,14 @@ public class BlockFluidFinite extends BlockFluidBase {
/* IFluidBlock */ /* IFluidBlock */
@Override @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; return null;
} }
@Override @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; return false;
} }
} }

View file

@ -31,8 +31,8 @@ import cpw.mods.fml.relauncher.SideOnly;
* @author King Lemming * @author King Lemming
* *
*/ */
public class Fluid { public class Fluid
{
/** The unique identification name for this fluid. */ /** The unique identification name for this fluid. */
protected final String fluidName; protected final String fluidName;
@ -40,9 +40,7 @@ public class Fluid {
protected String unlocalizedName; protected String unlocalizedName;
/** The Icons for this fluid. */ /** The Icons for this fluid. */
@SideOnly(Side.CLIENT)
protected Icon stillIcon; protected Icon stillIcon;
@SideOnly(Side.CLIENT)
protected Icon flowingIcon; protected Icon flowingIcon;
/** /**
@ -84,26 +82,31 @@ public class Fluid {
*/ */
protected int blockID = -1; protected int blockID = -1;
public Fluid(String fluidName) { public Fluid(String fluidName)
{
this.fluidName = fluidName.toLowerCase(Locale.ENGLISH); this.fluidName = fluidName.toLowerCase(Locale.ENGLISH);
this.unlocalizedName = fluidName; this.unlocalizedName = fluidName;
} }
public Fluid setUnlocalizedName(String unlocalizedName) { public Fluid setUnlocalizedName(String unlocalizedName)
{
this.unlocalizedName = unlocalizedName; this.unlocalizedName = unlocalizedName;
return this; return this;
} }
public Fluid setBlockID(int blockID) { public Fluid setBlockID(int blockID)
{
if (this.blockID == -1 || this.blockID == blockID) { if (this.blockID == -1 || this.blockID == blockID)
{
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 " 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."); + 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 " 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."); + 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 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; return this;
} }
public Fluid setBlockID(Block block) { public Fluid setBlockID(Block block)
{
return setBlockID(block.blockID); return setBlockID(block.blockID);
} }
public Fluid setLuminosity(int luminosity) { public Fluid setLuminosity(int luminosity)
{
this.luminosity = luminosity; this.luminosity = luminosity;
return this; return this;
} }
public Fluid setDensity(int density) { public Fluid setDensity(int density)
{
this.density = density; this.density = density;
return this; return this;
} }
public Fluid setViscosity(int viscosity) { public Fluid setViscosity(int viscosity)
{
this.viscosity = viscosity; this.viscosity = viscosity;
return this; return this;
} }
public Fluid setGaseous(boolean isGaseous) { public Fluid setGaseous(boolean isGaseous)
{
this.isGaseous = isGaseous; this.isGaseous = isGaseous;
return this; return this;
} }
public final String getName() { public final String getName()
{
return this.fluidName; return this.fluidName;
} }
public final int getID() { public final int getID()
{
return FluidRegistry.getFluidID(this.fluidName); return FluidRegistry.getFluidID(this.fluidName);
} }
public final int getBlockID() { public final int getBlockID()
{
return blockID; return blockID;
} }
public final boolean canBePlacedInWorld() { public final boolean canBePlacedInWorld()
{
return blockID != -1; return blockID != -1;
} }
/** /**
* Returns the localized name of this fluid. * Returns the localized name of this fluid.
*/ */
public String getLocalizedName() { public String getLocalizedName()
{
String s = this.getUnlocalizedName(); String s = this.getUnlocalizedName();
return s == null ? "" : StatCollector.translateToLocal(s); return s == null ? "" : StatCollector.translateToLocal(s);
} }
@ -173,155 +176,91 @@ public class Fluid {
/** /**
* Returns the unlocalized name of this fluid. * Returns the unlocalized name of this fluid.
*/ */
public String getUnlocalizedName() { public String getUnlocalizedName()
{
return "fluid." + this.unlocalizedName; return "fluid." + this.unlocalizedName;
} }
/** /**
* Returns 0 for "/terrain.png". ALL FLUID TEXTURES MUST BE ON THIS SHEET. * Returns 0 for "/terrain.png". ALL FLUID TEXTURES MUST BE ON THIS SHEET.
*/ */
public final int getSpriteNumber() { public final int getSpriteNumber()
{
return 0; return 0;
} }
/* Default Accessors */ /* Default Accessors */
public final int getLuminosity() { public final int getLuminosity()
{
return this.luminosity; return this.luminosity;
} }
public final int getDensity() { public final int getDensity()
{
return this.density; return this.density;
} }
public final int getViscosity() { public final int getViscosity()
{
return this.viscosity; return this.viscosity;
} }
public final boolean isGaseous() { public final boolean isGaseous()
{
return this.isGaseous; return this.isGaseous;
} }
public int getColor() { public int getColor()
{
return 0xFFFFFF; return 0xFFFFFF;
} }
/* Stack-based Accessors */ public final Fluid setStillIcon(Icon stillIcon)
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) {
this.stillIcon = stillIcon; this.stillIcon = stillIcon;
return this; return this;
} }
@SideOnly(Side.CLIENT) public final Fluid setFlowingIcon(Icon flowingIcon)
public final Fluid setFlowingIcon(Icon flowingIcon) { {
this.flowingIcon = flowingIcon; this.flowingIcon = flowingIcon;
return this; return this;
} }
@SideOnly(Side.CLIENT) public final Fluid setIcons(Icon stillIcon, Icon flowingIcon)
public final Fluid setIcons(Icon stillIcon, Icon flowingIcon) { {
return this.setStillIcon(stillIcon).setFlowingIcon(flowingIcon);
this.stillIcon = stillIcon;
this.flowingIcon = flowingIcon;
return this;
} }
@SideOnly(Side.CLIENT) public final Fluid setIcons(Icon commonIcon)
public final Fluid setIcons(Icon commonIcon) { {
return this.setStillIcon(commonIcon).setFlowingIcon(commonIcon);
this.stillIcon = commonIcon;
this.flowingIcon = commonIcon;
return this;
} }
@SideOnly(Side.CLIENT) public Icon getIcon(){ return getStillIcon(); }
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 getStillIcon()
{
return this.stillIcon; return this.stillIcon;
} }
@SideOnly(Side.CLIENT) public Icon getFlowingIcon()
public Icon getFlowingIcon() { {
return this.flowingIcon; 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(); }
} }

View file

@ -22,8 +22,8 @@ import net.minecraftforge.event.Event;
* @author King Lemming * @author King Lemming
* *
*/ */
public abstract class FluidContainerRegistry { public abstract class FluidContainerRegistry
{
private static Map<List, FluidContainerData> containerFluidMap = new HashMap(); private static Map<List, FluidContainerData> containerFluidMap = new HashMap();
private static Map<List, FluidContainerData> filledContainerMap = new HashMap(); private static Map<List, FluidContainerData> filledContainerMap = new HashMap();
private static Set<List> emptyContainers = new HashSet(); private static Set<List> 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_BUCKET = new ItemStack(Item.bucketEmpty);
public static final ItemStack EMPTY_BOTTLE = new ItemStack(Item.glassBottle); public static final ItemStack EMPTY_BOTTLE = new ItemStack(Item.glassBottle);
static { static
{
registerFluidContainer(FluidRegistry.WATER, new ItemStack(Item.bucketWater), EMPTY_BUCKET); registerFluidContainer(FluidRegistry.WATER, new ItemStack(Item.bucketWater), EMPTY_BUCKET);
registerFluidContainer(FluidRegistry.LAVA, new ItemStack(Item.bucketLava), EMPTY_BUCKET); registerFluidContainer(FluidRegistry.LAVA, new ItemStack(Item.bucketLava), EMPTY_BUCKET);
registerFluidContainer(FluidRegistry.WATER, new ItemStack(Item.potion), EMPTY_BOTTLE); registerFluidContainer(FluidRegistry.WATER, new ItemStack(Item.potion), EMPTY_BOTTLE);
} }
private FluidContainerRegistry() { private FluidContainerRegistry(){}
}
/** /**
* Register a new fluid containing item. * Register a new fluid containing item.
@ -53,8 +52,8 @@ public abstract class FluidContainerRegistry {
* ItemStack representing the container when it is empty. * ItemStack representing the container when it is empty.
* @return True if container was successfully registered; false if it already is. * @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)); return registerFluidContainer(new FluidContainerData(stack, filledContainer, emptyContainer));
} }
@ -70,9 +69,10 @@ public abstract class FluidContainerRegistry {
* ItemStack representing the container when it is empty. * ItemStack representing the container when it is empty.
* @return True if container was successfully registered; false if it already is. * @return True if container was successfully registered; false if it already is.
*/ */
public static boolean registerFluidContainer(Fluid fluid, ItemStack filledContainer, ItemStack emptyContainer) { public static boolean registerFluidContainer(Fluid fluid, ItemStack filledContainer, ItemStack emptyContainer)
{
if (!FluidRegistry.isFluidRegistered(fluid)) { if (!FluidRegistry.isFluidRegistered(fluid))
{
FluidRegistry.registerFluid(fluid); FluidRegistry.registerFluid(fluid);
} }
return registerFluidContainer(new FluidStack(fluid, BUCKET_VOLUME), filledContainer, emptyContainer); 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. * ItemStack representing the container when it is full.
* @return True if container was successfully registered; false if it already is. * @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)); return registerFluidContainer(new FluidContainerData(stack, filledContainer, null, true));
} }
@ -102,9 +102,10 @@ public abstract class FluidContainerRegistry {
* ItemStack representing the container when it is full. * ItemStack representing the container when it is full.
* @return True if container was successfully registered; false if it already is. * @return True if container was successfully registered; false if it already is.
*/ */
public static boolean registerFluidContainer(Fluid fluid, ItemStack filledContainer) { public static boolean registerFluidContainer(Fluid fluid, ItemStack filledContainer)
{
if (!FluidRegistry.isFluidRegistered(fluid)) { if (!FluidRegistry.isFluidRegistered(fluid))
{
FluidRegistry.registerFluid(fluid); FluidRegistry.registerFluid(fluid);
} }
return registerFluidContainer(new FluidStack(fluid, BUCKET_VOLUME), filledContainer); return registerFluidContainer(new FluidStack(fluid, BUCKET_VOLUME), filledContainer);
@ -117,17 +118,20 @@ public abstract class FluidContainerRegistry {
* See {@link FluidContainerData}. * See {@link FluidContainerData}.
* @return True if container was successfully registered; false if it already is. * @return True if container was successfully registered; false if it already is.
*/ */
public static boolean registerFluidContainer(FluidContainerData data) { public static boolean registerFluidContainer(FluidContainerData data)
{
if (isFilledContainer(data.filledContainer)) { if (isFilledContainer(data.filledContainer))
{
return false; return false;
} }
containerFluidMap.put(Arrays.asList(data.filledContainer.itemID, data.filledContainer.getItemDamage()), data); 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); filledContainerMap.put(Arrays.asList(data.emptyContainer.itemID, data.emptyContainer.getItemDamage(), data.fluid.fluidID), data);
emptyContainers.add(Arrays.asList(data.emptyContainer.itemID, data.emptyContainer.getItemDamage())); emptyContainers.add(Arrays.asList(data.emptyContainer.itemID, data.emptyContainer.getItemDamage()));
} }
MinecraftForge.EVENT_BUS.post(new FluidContainerRegisterEvent(data)); MinecraftForge.EVENT_BUS.post(new FluidContainerRegisterEvent(data));
return true; return true;
} }
@ -139,11 +143,13 @@ public abstract class FluidContainerRegistry {
* The fluid container. * The fluid container.
* @return FluidStack representing stored fluid. * @return FluidStack representing stored fluid.
*/ */
public static FluidStack getFluidForFilledItem(ItemStack container) { public static FluidStack getFluidForFilledItem(ItemStack container)
{
if (container == null) { if (container == null)
{
return null; return null;
} }
FluidContainerData data = containerFluidMap.get(Arrays.asList(container.itemID, container.getItemDamage())); FluidContainerData data = containerFluidMap.get(Arrays.asList(container.itemID, container.getItemDamage()));
return data == null ? null : data.fluid.copy(); return data == null ? null : data.fluid.copy();
} }
@ -159,13 +165,16 @@ public abstract class FluidContainerRegistry {
* ItemStack representing the empty container. * ItemStack representing the empty container.
* @return Filled container if successful, otherwise null. * @return Filled container if successful, otherwise null.
*/ */
public static ItemStack fillFluidContainer(FluidStack fluid, ItemStack container) { public static ItemStack fillFluidContainer(FluidStack fluid, ItemStack container)
{
if (container == null || fluid == null) { if (container == null || fluid == null)
{
return null; return null;
} }
FluidContainerData data = filledContainerMap.get(Arrays.asList(container.itemID, container.getItemDamage(), fluid.fluidID)); 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 data.filledContainer.copy();
} }
return null; return null;
@ -174,43 +183,50 @@ public abstract class FluidContainerRegistry {
/** /**
* Determines if a container holds a specific fluid. * Determines if a container holds a specific fluid.
*/ */
public static boolean containsFluid(ItemStack container, FluidStack fluid) { public static boolean containsFluid(ItemStack container, FluidStack fluid)
{
if (container == null || fluid == null) { if (container == null || fluid == null)
{
return false; return false;
} }
FluidContainerData data = filledContainerMap.get(Arrays.asList(container.itemID, container.getItemDamage(), fluid.fluidID)); FluidContainerData data = filledContainerMap.get(Arrays.asList(container.itemID, container.getItemDamage(), fluid.fluidID));
return data == null ? false : data.fluid.isFluidEqual(fluid); return data == null ? false : data.fluid.isFluidEqual(fluid);
} }
public static boolean isBucket(ItemStack container) { public static boolean isBucket(ItemStack container)
{
if (container == null) { if (container == null)
{
return false; return false;
} }
if (container.isItemEqual(EMPTY_BUCKET)) {
if (container.isItemEqual(EMPTY_BUCKET))
{
return true; return true;
} }
FluidContainerData data = containerFluidMap.get(Arrays.asList(container.itemID, container.getItemDamage())); FluidContainerData data = containerFluidMap.get(Arrays.asList(container.itemID, container.getItemDamage()));
return data != null && data.emptyContainer.isItemEqual(EMPTY_BUCKET); 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); 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())); 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; return container != null && getFluidForFilledItem(container) != null;
} }
public static FluidContainerData[] getRegisteredFluidContainerData() { public static FluidContainerData[] getRegisteredFluidContainerData()
{
return containerFluidMap.values().toArray(new FluidContainerData[containerFluidMap.size()]); 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 * Wrapper class for the registry entries. Ensures that none of the attempted registrations
* contain null references unless permitted. * contain null references unless permitted.
*/ */
public static class FluidContainerData { public static class FluidContainerData
{
public final FluidStack fluid; public final FluidStack fluid;
public final ItemStack filledContainer; public final ItemStack filledContainer;
public final ItemStack emptyContainer; 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); 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.fluid = stack;
this.filledContainer = filledContainer; this.filledContainer = filledContainer;
this.emptyContainer = emptyContainer; 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."); throw new RuntimeException("Invalid FluidContainerData - a parameter was null.");
} }
} }
public FluidContainerData copy() { public FluidContainerData copy()
{
return new FluidContainerData(fluid, filledContainer, emptyContainer, true); return new FluidContainerData(fluid, filledContainer, emptyContainer, true);
} }
} }
public static class FluidContainerRegisterEvent extends Event { public static class FluidContainerRegisterEvent extends Event
{
public final FluidContainerData data; public final FluidContainerData data;
public FluidContainerRegisterEvent(FluidContainerData data) { public FluidContainerRegisterEvent(FluidContainerData data)
{
this.data = data.copy(); this.data = data.copy();
} }
} }

View file

@ -5,16 +5,16 @@ import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event; import net.minecraftforge.event.Event;
public class FluidEvent extends Event { public class FluidEvent extends Event
{
public final FluidStack fluid; public final FluidStack fluid;
public final int x; public final int x;
public final int y; public final int y;
public final int z; public final int z;
public final World world; 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.fluid = fluid;
this.world = world; this.world = world;
this.x = x; this.x = x;
@ -28,10 +28,10 @@ public class FluidEvent extends Event {
* @author cpw * @author cpw
* *
*/ */
public static class FluidMotionEvent extends FluidEvent { public static class FluidMotionEvent extends FluidEvent
{
public FluidMotionEvent(FluidStack fluid, World world, int x, int y, int z) { public FluidMotionEvent(FluidStack fluid, World world, int x, int y, int z)
{
super(fluid, world, x, y, z); super(fluid, world, x, y, z);
} }
} }
@ -43,12 +43,11 @@ public class FluidEvent extends Event {
* @author cpw * @author cpw
* *
*/ */
public static class FluidFillingEvent extends FluidEvent { public static class FluidFillingEvent extends FluidEvent
{
public final IFluidTank tank; 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); super(fluid, world, x, y, z);
this.tank = tank; this.tank = tank;
} }
@ -61,12 +60,11 @@ public class FluidEvent extends Event {
* @author cpw * @author cpw
* *
*/ */
public static class FluidDrainingEvent extends FluidEvent { public static class FluidDrainingEvent extends FluidEvent
{
public final IFluidTank tank; 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); super(fluid, world, x, y, z);
this.tank = tank; this.tank = tank;
} }
@ -79,10 +77,10 @@ public class FluidEvent extends Event {
* @author cpw * @author cpw
* *
*/ */
public static class FluidSpilledEvent extends FluidEvent { public static class FluidSpilledEvent extends FluidEvent
{
public FluidSpilledEvent(FluidStack fluid, World world, int x, int y, int z) { public FluidSpilledEvent(FluidStack fluid, World world, int x, int y, int z)
{
super(fluid, world, x, y, z); super(fluid, world, x, y, z);
} }
} }
@ -92,9 +90,8 @@ public class FluidEvent extends Event {
* *
* @param event * @param event
*/ */
public static final void fireEvent(FluidEvent event) { public static final void fireEvent(FluidEvent event)
{
MinecraftForge.EVENT_BUS.post(event); MinecraftForge.EVENT_BUS.post(event);
} }
} }

View file

@ -13,17 +13,18 @@ import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
public class FluidIdMapPacket extends ForgePacket { public class FluidIdMapPacket extends ForgePacket
{
private BiMap<String, Integer> fluidIds = HashBiMap.create(); private BiMap<String, Integer> fluidIds = HashBiMap.create();
@Override @Override
public byte[] generatePacket() { public byte[] generatePacket()
{
ByteArrayDataOutput dat = ByteStreams.newDataOutput(); ByteArrayDataOutput dat = ByteStreams.newDataOutput();
dat.writeInt(FluidRegistry.maxID); dat.writeInt(FluidRegistry.maxID);
for (Map.Entry<String, Integer> entry : FluidRegistry.fluidIDs.entrySet()) { for (Map.Entry<String, Integer> entry : FluidRegistry.fluidIDs.entrySet())
{
dat.writeUTF(entry.getKey()); dat.writeUTF(entry.getKey());
dat.writeInt(entry.getValue()); dat.writeInt(entry.getValue());
} }
@ -31,8 +32,8 @@ public class FluidIdMapPacket extends ForgePacket {
} }
@Override @Override
public ForgePacket consumePacket(byte[] data) { public ForgePacket consumePacket(byte[] data)
{
ByteArrayDataInput dat = ByteStreams.newDataInput(data); ByteArrayDataInput dat = ByteStreams.newDataInput(data);
int listSize = dat.readInt(); int listSize = dat.readInt();
for (int i = 0; i < listSize; i++) { for (int i = 0; i < listSize; i++) {
@ -44,9 +45,8 @@ public class FluidIdMapPacket extends ForgePacket {
} }
@Override @Override
public void execute(INetworkManager network, EntityPlayer player) { public void execute(INetworkManager network, EntityPlayer player)
{
FluidRegistry.initFluidIDs(fluidIds); FluidRegistry.initFluidIDs(fluidIds);
} }
} }

View file

@ -18,8 +18,8 @@ import com.google.common.collect.ImmutableMap;
* @author King Lemming, CovertJaguar (LiquidDictionary) * @author King Lemming, CovertJaguar (LiquidDictionary)
* *
*/ */
public abstract class FluidRegistry { public abstract class FluidRegistry
{
static int maxID = 0; static int maxID = 0;
static HashMap<String, Fluid> fluids = new HashMap(); static HashMap<String, Fluid> fluids = new HashMap();
@ -30,20 +30,19 @@ public abstract class FluidRegistry {
public static int renderIdFluid = -1; public static int renderIdFluid = -1;
static { static
{
registerFluid(WATER); registerFluid(WATER);
registerFluid(LAVA); registerFluid(LAVA);
} }
private FluidRegistry() { private FluidRegistry(){}
}
/** /**
* Called by Forge to prepare the ID map for server -> client sync. * Called by Forge to prepare the ID map for server -> client sync.
*/ */
static void initFluidIDs(BiMap<String, Integer> newfluidIDs) { static void initFluidIDs(BiMap<String, Integer> newfluidIDs)
{
maxID = newfluidIDs.size(); maxID = newfluidIDs.size();
fluidIDs.clear(); fluidIDs.clear();
fluidIDs.putAll(newfluidIDs); fluidIDs.putAll(newfluidIDs);
@ -56,9 +55,10 @@ public abstract class FluidRegistry {
* The fluid to register. * The fluid to register.
* @return True if the fluid was successfully registered; false if there is a name clash. * @return True if the fluid was successfully registered; false if there is a name clash.
*/ */
public static boolean registerFluid(Fluid fluid) { public static boolean registerFluid(Fluid fluid)
{
if (fluidIDs.containsKey(fluid.getName())) { if (fluidIDs.containsKey(fluid.getName()))
{
return false; return false;
} }
fluids.put(fluid.getName(), fluid); fluids.put(fluid.getName(), fluid);
@ -68,44 +68,45 @@ public abstract class FluidRegistry {
return true; return true;
} }
public static boolean isFluidRegistered(Fluid fluid) { public static boolean isFluidRegistered(Fluid fluid)
{
return fluidIDs.containsKey(fluid.getName()); return fluidIDs.containsKey(fluid.getName());
} }
public static boolean isFluidRegistered(String fluidName) { public static boolean isFluidRegistered(String fluidName)
{
return fluidIDs.containsKey(fluidName); return fluidIDs.containsKey(fluidName);
} }
public static Fluid getFluid(String fluidName) { public static Fluid getFluid(String fluidName)
{
return fluids.get(fluidName); return fluids.get(fluidName);
} }
public static Fluid getFluid(int fluidID) { public static Fluid getFluid(int fluidID)
{
return fluids.get(getFluidName(fluidID)); return fluids.get(getFluidName(fluidID));
} }
public static String getFluidName(int fluidID) { public static String getFluidName(int fluidID)
{
return fluidIDs.inverse().get(fluidID); return fluidIDs.inverse().get(fluidID);
} }
public static String getFluidName(FluidStack stack) { public static String getFluidName(FluidStack stack)
{
return getFluidName(stack.fluidID); return getFluidName(stack.fluidID);
} }
public static int getFluidID(String fluidName) { public static int getFluidID(String fluidName)
{
return fluidIDs.get(fluidName); return fluidIDs.get(fluidName);
} }
public static FluidStack getFluidStack(String fluidName, int amount) { public static FluidStack getFluidStack(String fluidName, int amount)
{
if (!fluidIDs.containsKey(fluidName)) { if (!fluidIDs.containsKey(fluidName))
{
return null; return null;
} }
return new FluidStack(getFluidID(fluidName), amount); 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. * Returns a read-only map containing Fluid Names and their associated Fluids.
*/ */
public static Map<String, Fluid> getRegisteredFluids() { public static Map<String, Fluid> getRegisteredFluids()
{
return ImmutableMap.copyOf(fluids); return ImmutableMap.copyOf(fluids);
} }
/** /**
* Returns a read-only map containing Fluid Names and their associated IDs. * Returns a read-only map containing Fluid Names and their associated IDs.
*/ */
public static Map<String, Integer> getRegisteredFluidIDs() { public static Map<String, Integer> getRegisteredFluidIDs()
{
return ImmutableMap.copyOf(fluidIDs); return ImmutableMap.copyOf(fluidIDs);
} }
public static class FluidRegisterEvent extends Event { public static class FluidRegisterEvent extends Event
{
public final String fluidName; public final String fluidName;
public final int fluidID; public final int fluidID;
public FluidRegisterEvent(String fluidName, int fluidID) { public FluidRegisterEvent(String fluidName, int fluidID)
{
this.fluidName = fluidName; this.fluidName = fluidName;
this.fluidID = fluidID; this.fluidID = fluidID;
} }
} }
} }

View file

@ -14,35 +14,36 @@ import net.minecraft.nbt.NBTTagCompound;
* @author King Lemming, SirSengir (LiquidStack) * @author King Lemming, SirSengir (LiquidStack)
* *
*/ */
public class FluidStack { public class FluidStack
{
public int fluidID; public int fluidID;
public int amount; public int amount;
public NBTTagCompound tag; public NBTTagCompound tag;
public FluidStack(Fluid fluid, int amount) { public FluidStack(Fluid fluid, int amount)
{
this.fluidID = fluid.getID(); this.fluidID = fluid.getID();
this.amount = amount; this.amount = amount;
} }
public FluidStack(int fluidID, int amount) { public FluidStack(int fluidID, int amount)
{
this.fluidID = fluidID; this.fluidID = fluidID;
this.amount = amount; this.amount = amount;
} }
public FluidStack(int fluidID, int amount, NBTTagCompound nbt) { public FluidStack(int fluidID, int amount, NBTTagCompound nbt)
{
this(fluidID, amount); this(fluidID, amount);
if (nbt != null) { if (nbt != null)
{
tag = (NBTTagCompound) nbt.copy(); tag = (NBTTagCompound) nbt.copy();
} }
} }
public FluidStack(FluidStack stack, int amount) { public FluidStack(FluidStack stack, int amount)
{
this(stack.fluidID, amount, stack.tag); 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 * This provides a safe method for retrieving a FluidStack - if the Fluid is invalid, the stack
* will return as null. * will return as null.
*/ */
public static FluidStack loadFluidStackFromNBT(NBTTagCompound nbt) { public static FluidStack loadFluidStackFromNBT(NBTTagCompound nbt)
{
if (nbt == null || FluidRegistry.getFluid(nbt.getString("FluidName")) == null) { if (nbt == null || FluidRegistry.getFluid(nbt.getString("FluidName")) == null)
{
return null; return null;
} }
FluidStack stack = new FluidStack(FluidRegistry.getFluidID(nbt.getString("FluidName")), nbt.getInteger("Amount")); 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"); stack.tag = nbt.getCompoundTag("Tag");
} }
return stack; return stack;
} }
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
nbt.setString("FluidName", FluidRegistry.getFluidName(fluidID)); nbt.setString("FluidName", FluidRegistry.getFluidName(fluidID));
nbt.setInteger("Amount", amount); nbt.setInteger("Amount", amount);
if (tag != null) { if (tag != null)
{
nbt.setTag("Tag", tag); nbt.setTag("Tag", tag);
} }
return nbt; return nbt;
} }
public final Fluid getFluid() { public final Fluid getFluid()
{
return FluidRegistry.getFluid(fluidID); return FluidRegistry.getFluid(fluidID);
} }
/** /**
* @return A copy of this FluidStack * @return A copy of this FluidStack
*/ */
public FluidStack copy() { public FluidStack copy()
{
return new FluidStack(fluidID, amount, tag); return new FluidStack(fluidID, amount, tag);
} }
@ -94,21 +98,21 @@ public class FluidStack {
* The FluidStack for comparison * The FluidStack for comparison
* @return true if the Fluids (IDs and NBT Tags) are the same * @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); 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); 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. * 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); return stack1 == null && stack2 == null ? true : stack1 == null || stack2 == null ? false : stack1.isFluidStackTagEqual(stack2);
} }
@ -118,8 +122,8 @@ public class FluidStack {
* @param other * @param other
* @return true if this FluidStack contains the other FluidStack (same fluid and >= amount) * @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; return isFluidEqual(other) && amount >= other.amount;
} }
@ -130,8 +134,8 @@ public class FluidStack {
* - the FluidStack for comparison * - the FluidStack for comparison
* @return true if the two FluidStacks are exactly the same * @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; return isFluidEqual(other) && amount == other.amount;
} }
@ -143,20 +147,24 @@ public class FluidStack {
* The ItemStack for comparison * The ItemStack for comparison
* @return true if the Fluids (IDs and NBT Tags) are the same * @return true if the Fluids (IDs and NBT Tags) are the same
*/ */
public boolean isFluidEqual(ItemStack other) { public boolean isFluidEqual(ItemStack other)
{
if (other == null) { if (other == null)
{
return false; return false;
} }
if (other.getItem() instanceof IFluidContainerItem) {
if (other.getItem() instanceof IFluidContainerItem)
{
return isFluidEqual(((IFluidContainerItem) other.getItem()).getFluid(other)); return isFluidEqual(((IFluidContainerItem) other.getItem()).getFluid(other));
} }
return isFluidEqual(FluidContainerRegistry.getFluidForFilledItem(other)); return isFluidEqual(FluidContainerRegistry.getFluidForFilledItem(other));
} }
@Override @Override
public final int hashCode() { public final int hashCode()
{
return fluidID; return fluidID;
} }
@ -166,12 +174,13 @@ public class FluidStack {
* This is included for use in data structures. * This is included for use in data structures.
*/ */
@Override @Override
public final boolean equals(Object o) { public final boolean equals(Object o)
{
if (!(o instanceof FluidStack)) { if (!(o instanceof FluidStack))
{
return false; return false;
} }
return isFluidEqual((FluidStack) o); return isFluidEqual((FluidStack) o);
} }
} }

View file

@ -10,152 +10,179 @@ import net.minecraft.tileentity.TileEntity;
* @author King Lemming, cpw (LiquidTank) * @author King Lemming, cpw (LiquidTank)
* *
*/ */
public class FluidTank implements IFluidTank { public class FluidTank implements IFluidTank
{
protected FluidStack fluid; protected FluidStack fluid;
protected int capacity; protected int capacity;
protected TileEntity tile; protected TileEntity tile;
public FluidTank(int capacity) { public FluidTank(int capacity)
{
this(null, capacity); this(null, capacity);
} }
public FluidTank(FluidStack stack, int capacity) { public FluidTank(FluidStack stack, int capacity)
{
this.fluid = stack; this.fluid = stack;
this.capacity = capacity; 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); this(new FluidStack(fluid, amount), capacity);
} }
public FluidTank readFromNBT(NBTTagCompound nbt) { public FluidTank readFromNBT(NBTTagCompound nbt)
{
if (!nbt.hasKey("Empty")) { if (!nbt.hasKey("Empty"))
{
FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt); FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt);
if (fluid != null) { if (fluid != null)
{
setFluid(fluid); setFluid(fluid);
} }
} }
return this; return this;
} }
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
if (fluid != null) { if (fluid != null)
{
fluid.writeToNBT(nbt); fluid.writeToNBT(nbt);
} else { }
else
{
nbt.setString("Empty", ""); nbt.setString("Empty", "");
} }
return nbt; return nbt;
} }
public void setFluid(FluidStack fluid) { public void setFluid(FluidStack fluid)
{
this.fluid = fluid; this.fluid = fluid;
} }
public void setCapacity(int capacity) { public void setCapacity(int capacity)
{
this.capacity = capacity; this.capacity = capacity;
} }
/* IFluidTank */ /* IFluidTank */
@Override @Override
public FluidStack getFluid() { public FluidStack getFluid()
{
return fluid; return fluid;
} }
@Override @Override
public int getFluidAmount() { public int getFluidAmount()
{
if (fluid == null) { if (fluid == null)
{
return 0; return 0;
} }
return fluid.amount; return fluid.amount;
} }
@Override @Override
public int getCapacity() { public int getCapacity()
{
return capacity; return capacity;
} }
@Override @Override
public FluidTankInfo getInfo() { public FluidTankInfo getInfo()
{
return new FluidTankInfo(this); return new FluidTankInfo(this);
} }
@Override @Override
public int fill(FluidStack resource, boolean doFill) { public int fill(FluidStack resource, boolean doFill)
{
if (resource == null) { if (resource == null)
{
return 0; return 0;
} }
if (!doFill) {
if (fluid == null) { if (!doFill)
{
if (fluid == null)
{
return Math.min(capacity, resource.amount); return Math.min(capacity, resource.amount);
} }
if (!fluid.isFluidEqual(resource)) {
if (!fluid.isFluidEqual(resource))
{
return 0; return 0;
} }
return Math.min(capacity - fluid.amount, resource.amount); return Math.min(capacity - fluid.amount, resource.amount);
} }
if (fluid == null) {
if (fluid == null)
{
fluid = new FluidStack(resource, Math.min(capacity, resource.amount)); 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)); FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fluid, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this));
} }
return fluid.amount; return fluid.amount;
} }
if (!fluid.isFluidEqual(resource)) {
if (!fluid.isFluidEqual(resource))
{
return 0; return 0;
} }
int filled = capacity - fluid.amount; int filled = capacity - fluid.amount;
if (resource.amount < filled) { if (resource.amount < filled)
{
fluid.amount += resource.amount; fluid.amount += resource.amount;
filled = resource.amount; filled = resource.amount;
} else { }
else
{
fluid.amount = capacity; fluid.amount = capacity;
} }
if (tile != null) {
if (tile != null)
{
FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fluid, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this)); FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fluid, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this));
} }
return filled; return filled;
} }
@Override @Override
public FluidStack drain(int maxDrain, boolean doDrain) { public FluidStack drain(int maxDrain, boolean doDrain)
{
if (fluid == null) { if (fluid == null)
{
return null; return null;
} }
int drained = maxDrain;
if (fluid.amount < drained) { int drained = maxDrain;
if (fluid.amount < drained)
{
drained = fluid.amount; drained = fluid.amount;
} }
FluidStack stack = new FluidStack(fluid, drained); FluidStack stack = new FluidStack(fluid, drained);
if (doDrain)
if (doDrain) { {
fluid.amount -= drained; fluid.amount -= drained;
if (fluid.amount <= 0)
if (fluid.amount <= 0) { {
fluid = null; fluid = null;
} }
if (tile != null) {
if (tile != null)
{
FluidEvent.fireEvent(new FluidEvent.FluidDrainingEvent(fluid, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this)); FluidEvent.fireEvent(new FluidEvent.FluidDrainingEvent(fluid, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this));
} }
} }
return stack; return stack;
} }
} }

View file

@ -1,4 +1,3 @@
package net.minecraftforge.fluids; package net.minecraftforge.fluids;
/** /**
@ -7,21 +6,20 @@ package net.minecraftforge.fluids;
* @author King Lemming * @author King Lemming
* *
*/ */
public final class FluidTankInfo { public final class FluidTankInfo
{
public final FluidStack fluid; public final FluidStack fluid;
public final int capacity; public final int capacity;
public FluidTankInfo(FluidStack fluid, int capacity) { public FluidTankInfo(FluidStack fluid, int capacity)
{
this.fluid = fluid; this.fluid = fluid;
this.capacity = capacity; this.capacity = capacity;
} }
public FluidTankInfo(IFluidTank tank) { public FluidTankInfo(IFluidTank tank)
{
this.fluid = tank.getFluid(); this.fluid = tank.getFluid();
this.capacity = tank.getCapacity(); this.capacity = tank.getCapacity();
} }
} }

View file

@ -1,4 +1,3 @@
package net.minecraftforge.fluids; package net.minecraftforge.fluids;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -11,8 +10,8 @@ import net.minecraft.world.World;
* @author King Lemming * @author King Lemming
* *
*/ */
public interface IFluidBlock { public interface IFluidBlock
{
/** /**
* Returns the Fluid associated with this Block. * Returns the Fluid associated with this Block.
*/ */

View file

@ -1,4 +1,3 @@
package net.minecraftforge.fluids; package net.minecraftforge.fluids;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -14,8 +13,8 @@ import net.minecraft.item.ItemStack;
* @author King Lemming * @author King Lemming
* *
*/ */
public interface IFluidContainerItem { public interface IFluidContainerItem
{
/** /**
* *
* @param container * @param container
@ -57,5 +56,4 @@ public interface IFluidContainerItem {
* container. * container.
*/ */
FluidStack drain(ItemStack container, int maxDrain, boolean doDrain); FluidStack drain(ItemStack container, int maxDrain, boolean doDrain);
} }

View file

@ -1,4 +1,3 @@
package net.minecraftforge.fluids; package net.minecraftforge.fluids;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -12,8 +11,8 @@ import net.minecraftforge.common.ForgeDirection;
* @author King Lemming * @author King Lemming
* *
*/ */
public interface IFluidHandler { public interface IFluidHandler
{
/** /**
* Fills fluid into internal tanks, distribution is left entirely to the 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. * @return Info for the relevant internal tanks.
*/ */
FluidTankInfo[] getTankInfo(ForgeDirection from); FluidTankInfo[] getTankInfo(ForgeDirection from);
} }

View file

@ -1,4 +1,3 @@
package net.minecraftforge.fluids; package net.minecraftforge.fluids;
/** /**
@ -9,8 +8,8 @@ package net.minecraftforge.fluids;
* @author King Lemming, cpw (ILiquidTank) * @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. * @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. * @return Amount of fluid that was removed from the tank.
*/ */
FluidStack drain(int maxDrain, boolean doDrain); FluidStack drain(int maxDrain, boolean doDrain);
} }

View file

@ -1,4 +1,3 @@
package net.minecraftforge.fluids; package net.minecraftforge.fluids;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -11,122 +10,149 @@ import net.minecraft.nbt.NBTTagCompound;
* @author King Lemming * @author King Lemming
* *
*/ */
public class ItemFluidContainer extends Item implements IFluidContainerItem { public class ItemFluidContainer extends Item implements IFluidContainerItem
{
protected int capacity; protected int capacity;
public ItemFluidContainer(int itemID) { public ItemFluidContainer(int itemID)
{
super(itemID); super(itemID);
} }
public ItemFluidContainer(int itemID, int capacity) { public ItemFluidContainer(int itemID, int capacity)
{
super(itemID); super(itemID);
this.capacity = capacity; this.capacity = capacity;
} }
public ItemFluidContainer setCapacity(int capacity) { public ItemFluidContainer setCapacity(int capacity)
{
this.capacity = capacity; this.capacity = capacity;
return this; return this;
} }
/* IFluidContainerItem */ /* IFluidContainerItem */
@Override @Override
public FluidStack getFluid(ItemStack container) { public FluidStack getFluid(ItemStack container)
{
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) { if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid"))
{
return null; return null;
} }
return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid")); return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));
} }
@Override @Override
public int getCapacity(ItemStack container) { public int getCapacity(ItemStack container)
{
return capacity; return capacity;
} }
@Override @Override
public int fill(ItemStack container, FluidStack resource, boolean doFill) { public int fill(ItemStack container, FluidStack resource, boolean doFill)
{
if (resource == null) { if (resource == null)
{
return 0; 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); return Math.min(capacity, resource.amount);
} }
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid")); FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));
if (stack == null) { if (stack == null)
{
return Math.min(capacity, resource.amount); return Math.min(capacity, resource.amount);
} }
if (!stack.isFluidEqual(resource)) {
if (!stack.isFluidEqual(resource))
{
return 0; return 0;
} }
return Math.min(capacity - stack.amount, resource.amount); return Math.min(capacity - stack.amount, resource.amount);
} }
if (container.stackTagCompound == null) {
if (container.stackTagCompound == null)
{
container.stackTagCompound = new NBTTagCompound(); container.stackTagCompound = new NBTTagCompound();
} }
if (!container.stackTagCompound.hasKey("Fluid")) {
if (!container.stackTagCompound.hasKey("Fluid"))
{
NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound()); NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());
if (capacity < resource.amount) { if (capacity < resource.amount)
{
fluidTag.setInteger("Amount", capacity); fluidTag.setInteger("Amount", capacity);
container.stackTagCompound.setTag("Fluid", fluidTag); container.stackTagCompound.setTag("Fluid", fluidTag);
return capacity; return capacity;
} }
container.stackTagCompound.setTag("Fluid", fluidTag); container.stackTagCompound.setTag("Fluid", fluidTag);
return resource.amount; return resource.amount;
} }
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid"); NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid");
FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag); FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);
if (!stack.isFluidEqual(resource)) { if (!stack.isFluidEqual(resource))
{
return 0; return 0;
} }
int filled = capacity - resource.amount;
if (resource.amount < filled) { int filled = capacity - resource.amount;
if (resource.amount < filled)
{
stack.amount += resource.amount; stack.amount += resource.amount;
filled = resource.amount; filled = resource.amount;
} else { }
else
{
stack.amount = capacity; stack.amount = capacity;
} }
container.stackTagCompound.setTag("Fluid", stack.writeToNBT(fluidTag)); container.stackTagCompound.setTag("Fluid", stack.writeToNBT(fluidTag));
return filled; return filled;
} }
@Override @Override
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) { public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain)
{
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) { if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid"))
{
return null; return null;
} }
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid")); FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));
if (stack == null)
if (stack == null) { {
return null; return null;
} }
stack.amount = Math.min(stack.amount, maxDrain);
if (doDrain) { stack.amount = Math.min(stack.amount, maxDrain);
if (maxDrain >= capacity) { if (doDrain)
{
if (maxDrain >= capacity)
{
container.stackTagCompound.removeTag("Fluid"); container.stackTagCompound.removeTag("Fluid");
if (container.stackTagCompound.hasNoTags()) { if (container.stackTagCompound.hasNoTags())
{
container.stackTagCompound = null; container.stackTagCompound = null;
} }
return stack; return stack;
} }
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid"); NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid");
fluidTag.setInteger("Amount", fluidTag.getInteger("Amount") - maxDrain); fluidTag.setInteger("Amount", fluidTag.getInteger("Amount") - maxDrain);
container.stackTagCompound.setTag("Fluid", fluidTag); container.stackTagCompound.setTag("Fluid", fluidTag);
} }
return stack; return stack;
} }
} }

View file

@ -15,8 +15,8 @@ import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
* @author King Lemming * @author King Lemming
* *
*/ */
public class RenderBlockFluid implements ISimpleBlockRenderingHandler { public class RenderBlockFluid implements ISimpleBlockRenderingHandler
{
public static RenderBlockFluid instance = new RenderBlockFluid(); public static RenderBlockFluid instance = new RenderBlockFluid();
static final float LIGHT_Y_NEG = 0.5F; 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 float LIGHT_XZ_POS = 0.6F;
static final double RENDER_OFFSET = 0.0010000000474974513D; static final double RENDER_OFFSET = 0.0010000000474974513D;
public float getFluidHeightAverage(float[] flow) { public float getFluidHeightAverage(float[] flow)
{
float total = 0; float total = 0;
int count = 0; int count = 0;
for (int i = 0; i < flow.length; i++) { for (int i = 0; i < flow.length; i++)
if (flow[i] >= 0.875F) { {
if (flow[i] >= 0.875F)
{
return flow[i]; return flow[i];
} }
if (flow[i] >= 0) {
if (flow[i] >= 0)
{
total += flow[i]; total += flow[i];
count++; count++;
} }
@ -42,14 +46,17 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler {
return total / count; return total / count;
} }
public float getFluidHeightForRender(IBlockAccess world, int x, int y, int z, BlockFluidBase block) { 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, z) == block.blockID)
{
if (world.getBlockId(x, y - block.densityDir, z) == block.blockID) { if (world.getBlockId(x, y - block.densityDir, z) == block.blockID)
{
return 1; return 1;
} }
if (world.getBlockMetadata(x, y, z) == block.getMaxRenderHeightMeta()) {
if (world.getBlockMetadata(x, y, z) == block.getMaxRenderHeightMeta())
{
return 0.875F; return 0.875F;
} }
} }
@ -58,16 +65,16 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler {
/* ISimpleBlockRenderingHandler */ /* ISimpleBlockRenderingHandler */
@Override @Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer){}
}
@Override @Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)
{
if (!(block instanceof BlockFluidBase)) { if (!(block instanceof BlockFluidBase))
{
return false; return false;
} }
Tessellator tessellator = Tessellator.instance; Tessellator tessellator = Tessellator.instance;
int color = block.colorMultiplier(world, x, y, z); int color = block.colorMultiplier(world, x, y, z);
float red = (color >> 16 & 255) / 255.0F; 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 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), boolean[] renderSides = new boolean[]
block.shouldSideBeRendered(world, x - 1, y, z, 4), block.shouldSideBeRendered(world, x + 1, y, z, 5) }; {
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; return false;
} else { }
else
{
boolean rendered = false; boolean rendered = false;
double heightNW, heightSW, heightSE, heightNE; double heightNW, heightSW, heightSE, heightNE;
float flow11 = getFluidHeightForRender(world, x, y, z, theFluid); 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 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 flow02 = getFluidHeightForRender(world, x - 1, y, z + 1, theFluid);
float flow10 = 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 flow12 = getFluidHeightForRender(world, x, y, z + 1, theFluid);
float flow20 = getFluidHeightForRender(world, x + 1, 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); float flow22 = getFluidHeightForRender(world, x + 1, y, z + 1, theFluid);
heightNW = getFluidHeightAverage(new float[] { flow00, flow01, flow10, flow11 }); heightNW = getFluidHeightAverage(new float[]{ flow00, flow01, flow10, flow11 });
heightSW = getFluidHeightAverage(new float[] { flow01, flow02, flow12, flow11 }); heightSW = getFluidHeightAverage(new float[]{ flow01, flow02, flow12, flow11 });
heightSE = getFluidHeightAverage(new float[] { flow12, flow21, flow22, flow11 }); heightSE = getFluidHeightAverage(new float[]{ flow12, flow21, flow22, flow11 });
heightNE = getFluidHeightAverage(new float[] { flow10, flow20, flow21, flow11 }); heightNE = getFluidHeightAverage(new float[]{ flow10, flow20, flow21, flow11 });
} else { }
else
{
heightNW = flow11; heightNW = flow11;
heightSW = flow11; heightSW = flow11;
heightSE = flow11; heightSE = flow11;
@ -115,16 +131,17 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler {
} }
boolean rises = theFluid.densityDir == 1; boolean rises = theFluid.densityDir == 1;
if (renderer.renderAllFaces || renderTop)
if (renderer.renderAllFaces || renderTop) { {
rendered = true; rendered = true;
Icon iconStill = block.getIcon(1, bMeta); Icon iconStill = block.getIcon(1, bMeta);
float flowDir = (float) BlockFluidBase.getFlowDirection(world, x, y, z); float flowDir = (float) BlockFluidBase.getFlowDirection(world, x, y, z);
if (flowDir > -999.0F) { if (flowDir > -999.0F)
{
iconStill = block.getIcon(2, bMeta); iconStill = block.getIcon(2, bMeta);
} }
heightNW -= RENDER_OFFSET; heightNW -= RENDER_OFFSET;
heightSW -= RENDER_OFFSET; heightSW -= RENDER_OFFSET;
heightSE -= RENDER_OFFSET; heightSE -= RENDER_OFFSET;
@ -132,7 +149,8 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler {
double u1, u2, u3, u4, v1, v2, v3, v4; double u1, u2, u3, u4, v1, v2, v3, v4;
if (flowDir < -999.0F) { if (flowDir < -999.0F)
{
u2 = iconStill.getInterpolatedU(0.0D); u2 = iconStill.getInterpolatedU(0.0D);
v2 = iconStill.getInterpolatedV(0.0D); v2 = iconStill.getInterpolatedV(0.0D);
u1 = u2; u1 = u2;
@ -141,7 +159,9 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler {
v4 = v1; v4 = v1;
u3 = u4; u3 = u4;
v3 = v2; v3 = v2;
} else { }
else
{
float xFlow = MathHelper.sin(flowDir) * 0.25F; float xFlow = MathHelper.sin(flowDir) * 0.25F;
float zFlow = MathHelper.cos(flowDir) * 0.25F; float zFlow = MathHelper.cos(flowDir) * 0.25F;
u2 = iconStill.getInterpolatedU(8.0F + (-zFlow - xFlow) * 16.0F); 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); u3 = iconStill.getInterpolatedU(8.0F + (zFlow - xFlow) * 16.0F);
v3 = iconStill.getInterpolatedV(8.0F + (-zFlow - xFlow) * 16.0F); v3 = iconStill.getInterpolatedV(8.0F + (-zFlow - xFlow) * 16.0F);
} }
tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z)); tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
tessellator.setColorOpaque_F(LIGHT_Y_POS * red, LIGHT_Y_POS * green, LIGHT_Y_POS * blue); 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 + heightNW, z + 0, u2, v2);
tessellator.addVertexWithUV(x + 0, y + heightSW, z + 1, u1, v1); 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 + heightSE, z + 1, u4, v4);
tessellator.addVertexWithUV(x + 1, y + heightNE, z + 0, u3, v3); 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 - heightNE, z + 0, u3, v3);
tessellator.addVertexWithUV(x + 1, y + 1 - heightSE, z + 1, u4, v4); tessellator.addVertexWithUV(x + 1, y + 1 - heightSE, z + 1, u4, v4);
tessellator.addVertexWithUV(x + 0, y + 1 - heightSW, z + 1, u1, v1); 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; rendered = true;
tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y - 1, z)); 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); tessellator.setColorOpaque_F(LIGHT_Y_NEG, LIGHT_Y_NEG, LIGHT_Y_NEG);
renderer.renderFaceYNeg(block, x, y + RENDER_OFFSET, z, block.getIcon(0, bMeta)); 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); tessellator.setColorOpaque_F(LIGHT_Y_POS, LIGHT_Y_POS, LIGHT_Y_POS);
renderer.renderFaceYPos(block, x, y + RENDER_OFFSET, z, block.getIcon(1, bMeta)); 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 x2 = x;
int z2 = z; int z2 = z;
switch (side) { switch (side)
case 0: {
--z2; case 0: --z2; break;
break; case 1: ++z2; break;
case 1: case 2: --x2; break;
++z2; case 3: ++x2; break;
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; rendered = true;
double ty1; double ty1;
@ -212,28 +234,35 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler {
double tz1; double tz1;
double tz2; double tz2;
if (side == 0) { if (side == 0)
{
ty1 = heightNW; ty1 = heightNW;
ty2 = heightNE; ty2 = heightNE;
tx1 = x; tx1 = x;
tx2 = x + 1; tx2 = x + 1;
tz1 = z + RENDER_OFFSET; tz1 = z + RENDER_OFFSET;
tz2 = z + RENDER_OFFSET; tz2 = z + RENDER_OFFSET;
} else if (side == 1) { }
else if (side == 1)
{
ty1 = heightSE; ty1 = heightSE;
ty2 = heightSW; ty2 = heightSW;
tx1 = x + 1; tx1 = x + 1;
tx2 = x; tx2 = x;
tz1 = z + 1 - RENDER_OFFSET; tz1 = z + 1 - RENDER_OFFSET;
tz2 = z + 1 - RENDER_OFFSET; tz2 = z + 1 - RENDER_OFFSET;
} else if (side == 2) { }
else if (side == 2)
{
ty1 = heightSW; ty1 = heightSW;
ty2 = heightNW; ty2 = heightNW;
tx1 = x + RENDER_OFFSET; tx1 = x + RENDER_OFFSET;
tx2 = x + RENDER_OFFSET; tx2 = x + RENDER_OFFSET;
tz1 = z + 1; tz1 = z + 1;
tz2 = z; tz2 = z;
} else { }
else
{
ty1 = heightNE; ty1 = heightNE;
ty2 = heightSE; ty2 = heightSE;
tx1 = x + 1 - RENDER_OFFSET; tx1 = x + 1 - RENDER_OFFSET;
@ -241,6 +270,7 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler {
tz1 = z; tz1 = z;
tz2 = z + 1; tz2 = z + 1;
} }
float u1Flow = iconFlow.getInterpolatedU(0.0D); float u1Flow = iconFlow.getInterpolatedU(0.0D);
float u2Flow = iconFlow.getInterpolatedU(8.0D); float u2Flow = iconFlow.getInterpolatedU(8.0D);
float v1Flow = iconFlow.getInterpolatedV((1.0D - ty1) * 16.0D * 0.5D); 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)); tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x2, y, z2));
float sideLighting = 1.0F; float sideLighting = 1.0F;
if (side < 2) { if (side < 2)
{
sideLighting = LIGHT_XZ_NEG; sideLighting = LIGHT_XZ_NEG;
} else { }
else
{
sideLighting = LIGHT_XZ_POS; sideLighting = LIGHT_XZ_POS;
} }
tessellator.setColorOpaque_F(LIGHT_Y_POS * sideLighting * red, LIGHT_Y_POS * sideLighting * green, LIGHT_Y_POS * sideLighting * blue); 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(tx1, y + ty1, tz1, u1Flow, v1Flow);
tessellator.addVertexWithUV(tx2, y + ty2, tz2, u2Flow, v2Flow); tessellator.addVertexWithUV(tx2, y + ty2, tz2, u2Flow, v2Flow);
tessellator.addVertexWithUV(tx2, y + 0, tz2, u2Flow, v3Flow); tessellator.addVertexWithUV(tx2, y + 0, tz2, u2Flow, v3Flow);
tessellator.addVertexWithUV(tx1, y + 0, tz1, u1Flow, v3Flow); tessellator.addVertexWithUV(tx1, y + 0, tz1, u1Flow, v3Flow);
} else { }
else
{
tessellator.addVertexWithUV(tx1, y + 1 - 0, tz1, u1Flow, v3Flow); tessellator.addVertexWithUV(tx1, y + 1 - 0, tz1, u1Flow, v3Flow);
tessellator.addVertexWithUV(tx2, y + 1 - 0, tz2, u2Flow, v3Flow); tessellator.addVertexWithUV(tx2, y + 1 - 0, tz2, u2Flow, v3Flow);
tessellator.addVertexWithUV(tx2, y + 1 - ty2, tz2, u2Flow, v2Flow); tessellator.addVertexWithUV(tx2, y + 1 - ty2, tz2, u2Flow, v2Flow);
@ -276,15 +313,10 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler {
} }
@Override @Override
public boolean shouldRender3DInInventory() { public boolean shouldRender3DInInventory(){ return false; }
return false;
}
@Override @Override
public int getRenderId() { public int getRenderId()
{
return FluidRegistry.renderIdFluid; return FluidRegistry.renderIdFluid;
} }
} }

View file

@ -11,62 +11,62 @@ import net.minecraftforge.common.ForgeDirection;
* @author King Lemming * @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); protected FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
@Override @Override
public void readFromNBT(NBTTagCompound tag) { public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag); super.readFromNBT(tag);
tank.writeToNBT(tag); tank.writeToNBT(tag);
} }
@Override @Override
public void writeToNBT(NBTTagCompound tag) { public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(tag); super.writeToNBT(tag);
tank.readFromNBT(tag); tank.readFromNBT(tag);
} }
/* IFluidHandler */ /* IFluidHandler */
@Override @Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
return tank.fill(resource, doFill); return tank.fill(resource, doFill);
} }
@Override @Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
if (resource == null || !resource.isFluidEqual(tank.getFluid())) { if (resource == null || !resource.isFluidEqual(tank.getFluid()))
{
return null; return null;
} }
return tank.drain(resource.amount, doDrain); return tank.drain(resource.amount, doDrain);
} }
@Override @Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return tank.drain(maxDrain, doDrain); return tank.drain(maxDrain, doDrain);
} }
@Override @Override
public boolean canFill(ForgeDirection from, Fluid fluid) { public boolean canFill(ForgeDirection from, Fluid fluid)
{
return true; return true;
} }
@Override @Override
public boolean canDrain(ForgeDirection from, Fluid fluid) { public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return true; return true;
} }
@Override @Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) { public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return new FluidTankInfo[] { tank.getInfo() }; return new FluidTankInfo[] { tank.getInfo() };
} }
} }