Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.

Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
This commit is contained in:
Lex Manos committed 2014-11-26 00:00:54 -08:00
1 parent 0e91787efb
commit 53659fca06
410 files changed
+8717 -14103

No files matched your search

@@ -8,13 +8,22 @@ import com.google.common.collect.Maps;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* This is a base implementation for Fluid blocks.
@@ -30,7 +39,43 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
static
{
defaultDisplacements.put(Blocks.wooden_door, false);
defaultDisplacements.put(Blocks.oak_door, false);
defaultDisplacements.put(Blocks.spruce_door, false);
defaultDisplacements.put(Blocks.birch_door, false);
defaultDisplacements.put(Blocks.jungle_door, false);
defaultDisplacements.put(Blocks.acacia_door, false);
defaultDisplacements.put(Blocks.dark_oak_door, false);
defaultDisplacements.put(Blocks.trapdoor, false);
defaultDisplacements.put(Blocks.iron_trapdoor, false);
defaultDisplacements.put(Blocks.oak_fence, false);
defaultDisplacements.put(Blocks.spruce_fence, false);
defaultDisplacements.put(Blocks.birch_fence, false);
defaultDisplacements.put(Blocks.jungle_fence, false);
defaultDisplacements.put(Blocks.dark_oak_fence, false);
defaultDisplacements.put(Blocks.acacia_fence, false);
defaultDisplacements.put(Blocks.nether_brick_fence, false);
defaultDisplacements.put(Blocks.oak_fence_gate, false);
defaultDisplacements.put(Blocks.spruce_fence_gate, false);
defaultDisplacements.put(Blocks.birch_fence_gate, false);
defaultDisplacements.put(Blocks.jungle_fence_gate, false);
defaultDisplacements.put(Blocks.dark_oak_fence_gate, false);
defaultDisplacements.put(Blocks.acacia_fence_gate, false);
defaultDisplacements.put(Blocks.wooden_pressure_plate, false);
defaultDisplacements.put(Blocks.stone_pressure_plate, false);
defaultDisplacements.put(Blocks.light_weighted_pressure_plate, false);
defaultDisplacements.put(Blocks.heavy_weighted_pressure_plate, false);
defaultDisplacements.put(Blocks.ladder, false);
defaultDisplacements.put(Blocks.iron_bars, false);
defaultDisplacements.put(Blocks.glass_pane, false);
defaultDisplacements.put(Blocks.stained_glass_pane, false);
defaultDisplacements.put(Blocks.portal, false);
defaultDisplacements.put(Blocks.end_portal, false);
defaultDisplacements.put(Blocks.cobblestone_wall, false);
defaultDisplacements.put(Blocks.barrier, false);
defaultDisplacements.put(Blocks.standing_banner, false);
defaultDisplacements.put(Blocks.wall_banner, false);
defaultDisplacements.put(Blocks.cake, false);
defaultDisplacements.put(Blocks.iron_door, false);
defaultDisplacements.put(Blocks.standing_sign, false);
defaultDisplacements.put(Blocks.wall_sign, false);
@@ -38,6 +83,7 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
protected Map<Block, Boolean> displacements = Maps.newHashMap();
public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 15);
protected int quantaPerBlock = 8;
protected float quantaPerBlockFloat = 8F;
protected int density = 1;
@@ -45,7 +91,7 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
protected int temperature = 295;
protected int tickRate = 20;
protected int renderPass = 1;
protected EnumWorldBlockLayer renderLayer = EnumWorldBlockLayer.TRANSLUCENT;
protected int maxScaledLight = 0;
protected final String fluidName;
@@ -66,8 +112,20 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
fluid.setBlock(this);
displacements.putAll(defaultDisplacements);
this.setDefaultState(blockState.getBaseState().withProperty(LEVEL, 0));
}
@Override
protected BlockState createBlockState()
{
return new BlockState(this, LEVEL);
}
@Override
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(LEVEL)).intValue();
}
public BlockFluidBase setQuantaPerBlock(int quantaPerBlock)
{
if (quantaPerBlock > 16 || quantaPerBlock < 1) quantaPerBlock = 8;
@@ -97,9 +155,9 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
return this;
}
public BlockFluidBase setRenderPass(int renderPass)
public BlockFluidBase setRenderLayer(EnumWorldBlockLayer renderLayer)
{
this.renderPass = renderPass;
this.renderLayer = renderLayer;
return this;
}
@@ -110,13 +168,13 @@ 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 (pos) is displaceable. Does not displace the block.
*/
public boolean canDisplace(IBlockAccess world, int x, int y, int z)
public boolean canDisplace(IBlockAccess world, BlockPos pos)
{
if (world.getBlock(x, y, z).isAir(world, x, y, z)) return true;
if (world.isAirBlock(pos)) return true;
Block block = world.getBlock(x, y, z);
Block block = world.getBlockState(pos).getBlock();
if (block == this)
{
@@ -134,12 +192,12 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
return false;
}
int density = getDensity(world, x, y, z);
if (density == Integer.MAX_VALUE)
int density = getDensity(world, pos);
if (density == Integer.MAX_VALUE)
{
return true;
}
if (this.density > density)
{
return true;
@@ -151,16 +209,17 @@ 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 (pos), return true if it was displaced.
*/
public boolean displaceIfPossible(World world, int x, int y, int z)
public boolean displaceIfPossible(World world, BlockPos pos)
{
if (world.getBlock(x, y, z).isAir(world, x, y, z))
if (world.isAirBlock(pos))
{
return true;
}
Block block = world.getBlock(x, y, z);
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block == this)
{
return false;
@@ -170,7 +229,7 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
{
if (displacements.get(block))
{
block.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
block.dropBlockAsItem(world, pos, state, 0);
return true;
}
return false;
@@ -182,13 +241,13 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
return false;
}
int density = getDensity(world, x, y, z);
if (density == Integer.MAX_VALUE)
int density = getDensity(world, pos);
if (density == Integer.MAX_VALUE)
{
block.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
block.dropBlockAsItem(world, pos, state, 0);
return true;
}
if (this.density > density)
{
return true;
@@ -199,47 +258,47 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
}
public abstract int getQuantaValue(IBlockAccess world, int x, int y, int z);
public abstract int getQuantaValue(IBlockAccess world, BlockPos pos);
@Override
public abstract boolean canCollideCheck(int meta, boolean fullHit);
public abstract boolean canCollideCheck(IBlockState state, boolean fullHit);
public abstract int getMaxRenderHeightMeta();
/* BLOCK FUNCTIONS */
@Override
public void onBlockAdded(World world, int x, int y, int z)
public void onBlockAdded(World world, BlockPos pos, IBlockState state)
{
world.scheduleBlockUpdate(x, y, z, this, tickRate);
world.scheduleUpdate(pos, this, tickRate);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block neighborBlock)
{
world.scheduleBlockUpdate(x, y, z, this, tickRate);
world.scheduleUpdate(pos, this, tickRate);
}
// Used to prevent updates on chunk generation
@Override
public boolean func_149698_L()
public boolean requiresUpdates()
{
return false;
}
@Override
public boolean getBlocksMovement(IBlockAccess world, int x, int y, int z)
public boolean isPassable(IBlockAccess world, BlockPos pos)
{
return true;
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
public AxisAlignedBB getCollisionBoundingBox(World world, BlockPos pos, IBlockState state)
{
return null;
}
@Override
public Item getItemDropped(int par1, Random par2Random, int par3)
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return null;
}
@@ -257,23 +316,24 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
@Override
public void velocityToAddToEntity(World world, int x, int y, int z, Entity entity, Vec3 vec)
public Vec3 modifyAcceleration(World world, BlockPos pos, Entity entity, Vec3 vec)
{
if (densityDir > 0) return;
Vec3 vec_flow = this.getFlowVector(world, x, y, z);
vec.xCoord += vec_flow.xCoord * (quantaPerBlock * 4);
vec.yCoord += vec_flow.yCoord * (quantaPerBlock * 4);
vec.zCoord += vec_flow.zCoord * (quantaPerBlock * 4);
if (densityDir > 0) return vec;
Vec3 vec_flow = this.getFlowVector(world, pos);
return vec.addVector(
vec_flow.xCoord * (quantaPerBlock * 4),
vec_flow.yCoord * (quantaPerBlock * 4),
vec_flow.zCoord * (quantaPerBlock * 4));
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)
public int getLightValue(IBlockAccess world, BlockPos pos)
{
if (maxScaledLight == 0)
{
return super.getLightValue(world, x, y, z);
return super.getLightValue(world, pos);
}
int data = world.getBlockMetadata(x, y, z);
int data = ((Integer)world.getBlockState(pos).getValue(LEVEL)).intValue();
return (int) (data / quantaPerBlockFloat * maxScaledLight);
}
@@ -290,26 +350,26 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
@Override
public boolean renderAsNormalBlock()
public boolean isFullCube()
{
return false;
}
/* Never used...?
@Override
public float getBlockBrightness(World world, int x, int y, int z)
public float getBlockBrightness(World world, BlockPos pos)
{
float lightThis = world.getLightBrightness(x, y, z);
float lightThis = world.getLightBrightness(pos);
float lightUp = world.getLightBrightness(x, y + 1, z);
return lightThis > lightUp ? lightThis : lightUp;
}
*/
@Override
public int getMixedBrightnessForBlock(IBlockAccess world, int x, int y, int z)
public int getMixedBrightnessForBlock(IBlockAccess world, BlockPos pos)
{
int lightThis = world.getLightBrightnessForSkyBlocks(x, y, z, 0);
int lightUp = world.getLightBrightnessForSkyBlocks(x, y + 1, z, 0);
int lightThis = world.getCombinedLight(pos, 0);
int lightUp = world.getCombinedLight(pos.offsetUp(), 0);
int lightThisBase = lightThis & 255;
int lightUpBase = lightUp & 255;
int lightThisExt = lightThis >> 16 & 255;
@@ -319,36 +379,37 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
@Override
public int getRenderBlockPass()
@SideOnly(Side.CLIENT)
public EnumWorldBlockLayer getBlockLayer()
{
return renderPass;
return this.renderLayer;
}
@Override
public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side)
public boolean shouldSideBeRendered(IBlockAccess world, BlockPos pos, EnumFacing side)
{
Block block = world.getBlock(x, y, z);
Block block = world.getBlockState(pos).getBlock();
if (block != this)
{
return !block.isOpaqueCube();
}
return block.getMaterial() == this.getMaterial() ? false : super.shouldSideBeRendered(world, x, y, z, side);
return block.getMaterial() == this.getMaterial() ? false : super.shouldSideBeRendered(world, pos, side);
}
/* FLUID FUNCTIONS */
public static final int getDensity(IBlockAccess world, int x, int y, int z)
public static final int getDensity(IBlockAccess world, BlockPos pos)
{
Block block = world.getBlock(x, y, z);
Block block = world.getBlockState(pos).getBlock();
if (!(block instanceof BlockFluidBase))
{
return Integer.MAX_VALUE;
}
return ((BlockFluidBase)block).density;
}
public static final int getTemperature(IBlockAccess world, int x, int y, int z)
public static final int getTemperature(IBlockAccess world, BlockPos pos)
{
Block block = world.getBlock(x, y, z);
Block block = world.getBlockState(pos).getBlock();
if (!(block instanceof BlockFluidBase))
{
return Integer.MAX_VALUE;
@@ -356,20 +417,20 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
return ((BlockFluidBase)block).temperature;
}
public static double getFlowDirection(IBlockAccess world, int x, int y, int z)
public static double getFlowDirection(IBlockAccess world, BlockPos pos)
{
Block block = world.getBlock(x, y, z);
Block block = world.getBlockState(pos).getBlock();
if (!block.getMaterial().isLiquid())
{
return -1000.0;
}
Vec3 vec = ((BlockFluidBase) block).getFlowVector(world, x, y, z);
Vec3 vec = ((BlockFluidBase) block).getFlowVector(world, pos);
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, BlockPos pos, int belowThis)
{
int quantaRemaining = getQuantaValue(world, x, y, z);
int quantaRemaining = getQuantaValue(world, pos);
if (quantaRemaining >= belowThis)
{
return -1;
@@ -377,9 +438,9 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
return quantaRemaining;
}
public final int getQuantaValueAbove(IBlockAccess world, int x, int y, int z, int aboveThis)
public final int getQuantaValueAbove(IBlockAccess world, BlockPos pos, int aboveThis)
{
int quantaRemaining = getQuantaValue(world, x, y, z);
int quantaRemaining = getQuantaValue(world, pos);
if (quantaRemaining <= aboveThis)
{
return -1;
@@ -387,21 +448,21 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
return quantaRemaining;
}
public final float getQuantaPercentage(IBlockAccess world, int x, int y, int z)
public final float getQuantaPercentage(IBlockAccess world, BlockPos pos)
{
int quantaRemaining = getQuantaValue(world, x, y, z);
int quantaRemaining = getQuantaValue(world, pos);
return quantaRemaining / quantaPerBlockFloat;
}
public Vec3 getFlowVector(IBlockAccess world, int x, int y, int z)
public Vec3 getFlowVector(IBlockAccess world, BlockPos pos)
{
Vec3 vec = Vec3.createVectorHelper(0.0D, 0.0D, 0.0D);
int decay = quantaPerBlock - getQuantaValue(world, x, y, z);
Vec3 vec = new Vec3(0.0D, 0.0D, 0.0D);
int decay = quantaPerBlock - getQuantaValue(world, pos);
for (int side = 0; side < 4; ++side)
{
int x2 = x;
int z2 = z;
int x2 = pos.getX();
int z2 = pos.getZ();
switch (side)
{
@@ -411,37 +472,38 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
case 3: ++z2; break;
}
int otherDecay = quantaPerBlock - getQuantaValue(world, x2, y, z2);
BlockPos pos2 = new BlockPos(x2, pos.getY(), z2);
int otherDecay = quantaPerBlock - getQuantaValue(world, pos2);
if (otherDecay >= quantaPerBlock)
{
if (!world.getBlock(x2, y, z2).getMaterial().blocksMovement())
if (!world.getBlockState(pos2).getBlock().getMaterial().blocksMovement())
{
otherDecay = quantaPerBlock - getQuantaValue(world, x2, y - 1, z2);
otherDecay = quantaPerBlock - getQuantaValue(world, pos2.offsetDown());
if (otherDecay >= 0)
{
int power = otherDecay - (decay - quantaPerBlock);
vec = vec.addVector((x2 - x) * power, (y - y) * power, (z2 - z) * power);
vec = vec.addVector((pos2.getX() - pos.getX()) * power, 0, (pos2.getZ() - pos.getZ()) * power);
}
}
}
else if (otherDecay >= 0)
{
int power = otherDecay - decay;
vec = vec.addVector((x2 - x) * power, (y - y) * power, (z2 - z) * power);
vec = vec.addVector((pos2.getX() - pos.getX()) * power, 0, (pos2.getZ() - pos.getZ()) * power);
}
}
if (world.getBlock(x, y + 1, z) == this)
if (world.getBlockState(pos.offsetUp()).getBlock() == this)
{
boolean flag =
isBlockSolid(world, x, y, z - 1, 2) ||
isBlockSolid(world, x, y, z + 1, 3) ||
isBlockSolid(world, x - 1, y, z, 4) ||
isBlockSolid(world, x + 1, y, z, 5) ||
isBlockSolid(world, x, y + 1, z - 1, 2) ||
isBlockSolid(world, x, y + 1, z + 1, 3) ||
isBlockSolid(world, x - 1, y + 1, z, 4) ||
isBlockSolid(world, x + 1, y + 1, z, 5);
isBlockSolid(world, pos.add( 0, 0, -1), EnumFacing.NORTH) ||
isBlockSolid(world, pos.add( 0, 0, 1), EnumFacing.SOUTH) ||
isBlockSolid(world, pos.add(-1, 0, 0), EnumFacing.WEST) ||
isBlockSolid(world, pos.add( 1, 0, 0), EnumFacing.EAST) ||
isBlockSolid(world, pos.add( 0, 1, -1), EnumFacing.NORTH) ||
isBlockSolid(world, pos.add( 0, 1, 1), EnumFacing.SOUTH) ||
isBlockSolid(world, pos.add(-1, 1, 0), EnumFacing.WEST) ||
isBlockSolid(world, pos.add( 1, 1, 0), EnumFacing.EAST);
if (flag)
{
@@ -460,11 +522,11 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
@Override
public float getFilledPercentage(World world, int x, int y, int z)
public float getFilledPercentage(World world, BlockPos pos)
{
int quantaRemaining = getQuantaValue(world, x, y, z) + 1;
int quantaRemaining = getQuantaValue(world, pos) + 1;
float remaining = quantaRemaining / quantaPerBlockFloat;
if (remaining > 1) remaining = 1.0f;
return remaining * (density > 0 ? 1 : -1);
}
}
}
@@ -4,7 +4,9 @@ import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@@ -41,26 +43,27 @@ public class BlockFluidClassic extends BlockFluidBase
}
@Override
public int getQuantaValue(IBlockAccess world, int x, int y, int z)
public int getQuantaValue(IBlockAccess world, BlockPos pos)
{
if (world.getBlock(x, y, z) == Blocks.air)
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == Blocks.air)
{
return 0;
}
if (world.getBlock(x, y, z) != this)
if (state.getBlock() != this)
{
return -1;
}
int quantaRemaining = quantaPerBlock - world.getBlockMetadata(x, y, z);
int quantaRemaining = quantaPerBlock - ((Integer)state.getValue(LEVEL)).intValue();
return quantaRemaining;
}
@Override
public boolean canCollideCheck(int meta, boolean fullHit)
public boolean canCollideCheck(IBlockState state, boolean fullHit)
{
return fullHit && meta == 0;
return fullHit && ((Integer)state.getValue(LEVEL)).intValue() == 0;
}
@Override
@@ -70,42 +73,40 @@ public class BlockFluidClassic extends BlockFluidBase
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)
public int getLightValue(IBlockAccess world, BlockPos pos)
{
if (maxScaledLight == 0)
{
return super.getLightValue(world, x, y, z);
return super.getLightValue(world, pos);
}
int data = quantaPerBlock - world.getBlockMetadata(x, y, z) - 1;
int data = quantaPerBlock - ((Integer)world.getBlockState(pos).getValue(LEVEL)).intValue() - 1;
return (int) (data / quantaPerBlockFloat * maxScaledLight);
}
@Override
public void updateTick(World world, int x, int y, int z, Random rand)
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
{
int quantaRemaining = quantaPerBlock - world.getBlockMetadata(x, y, z);
int quantaRemaining = quantaPerBlock - ((Integer)state.getValue(LEVEL)).intValue();
int expQuanta = -101;
// check adjacent block levels if non-source
if (quantaRemaining < quantaPerBlock)
{
int y2 = y - densityDir;
if (world.getBlock(x, y2, z ) == this ||
world.getBlock(x - 1, y2, z ) == this ||
world.getBlock(x + 1, y2, z ) == this ||
world.getBlock(x, y2, z - 1) == this ||
world.getBlock(x, y2, z + 1) == this)
if (world.getBlockState(pos.add( 0, -densityDir, 0)).getBlock() == this ||
world.getBlockState(pos.add(-1, -densityDir, 0)).getBlock() == this ||
world.getBlockState(pos.add( 1, -densityDir, 0)).getBlock() == this ||
world.getBlockState(pos.add( 0, -densityDir, -1)).getBlock() == this ||
world.getBlockState(pos.add( 0, -densityDir, 1)).getBlock() == this)
{
expQuanta = quantaPerBlock - 1;
}
else
{
int maxQuanta = -100;
maxQuanta = getLargerQuanta(world, x - 1, y, z, maxQuanta);
maxQuanta = getLargerQuanta(world, x + 1, y, z, maxQuanta);
maxQuanta = getLargerQuanta(world, x, y, z - 1, maxQuanta);
maxQuanta = getLargerQuanta(world, x, y, z + 1, maxQuanta);
maxQuanta = getLargerQuanta(world, pos.add(-1, 0, 0), maxQuanta);
maxQuanta = getLargerQuanta(world, pos.add( 1, 0, 0), maxQuanta);
maxQuanta = getLargerQuanta(world, pos.add( 0, 0, -1), maxQuanta);
maxQuanta = getLargerQuanta(world, pos.add( 0, 0, 1), maxQuanta);
expQuanta = maxQuanta - 1;
}
@@ -117,26 +118,26 @@ public class BlockFluidClassic extends BlockFluidBase
if (expQuanta <= 0)
{
world.setBlock(x, y, z, Blocks.air);
world.setBlockToAir(pos);
}
else
{
world.setBlockMetadataWithNotify(x, y, z, quantaPerBlock - expQuanta, 3);
world.scheduleBlockUpdate(x, y, z, this, tickRate);
world.notifyBlocksOfNeighborChange(x, y, z, this);
world.setBlockState(pos, state.withProperty(LEVEL, quantaPerBlock - expQuanta), 2);
world.scheduleUpdate(pos, this, tickRate);
world.notifyNeighborsOfStateChange(pos, this);
}
}
}
// This is a "source" block, set meta to zero, and send a server only update
else if (quantaRemaining >= quantaPerBlock)
{
world.setBlockMetadataWithNotify(x, y, z, 0, 2);
world.setBlockState(pos, this.getDefaultState(), 2);
}
// Flow vertically if possible
if (canDisplace(world, x, y + densityDir, z))
if (canDisplace(world, pos.offsetUp(densityDir)))
{
flowIntoBlock(world, x, y + densityDir, z, 1);
flowIntoBlock(world, pos.offsetUp(densityDir), 1);
return;
}
@@ -147,62 +148,60 @@ public class BlockFluidClassic extends BlockFluidBase
return;
}
if (isSourceBlock(world, x, y, z) || !isFlowingVertically(world, x, y, z))
if (isSourceBlock(world, pos) || !isFlowingVertically(world, pos))
{
if (world.getBlock(x, y - densityDir, z) == this)
if (world.getBlockState(pos.offsetDown(densityDir)).getBlock() == this)
{
flowMeta = 1;
}
boolean flowTo[] = getOptimalFlowDirections(world, x, y, z);
boolean flowTo[] = getOptimalFlowDirections(world, pos);
if (flowTo[0]) flowIntoBlock(world, x - 1, y, z, flowMeta);
if (flowTo[1]) flowIntoBlock(world, x + 1, y, z, flowMeta);
if (flowTo[2]) flowIntoBlock(world, x, y, z - 1, flowMeta);
if (flowTo[3]) flowIntoBlock(world, x, y, z + 1, flowMeta);
if (flowTo[0]) flowIntoBlock(world, pos.add(-1, 0, 0), flowMeta);
if (flowTo[1]) flowIntoBlock(world, pos.add( 1, 0, 0), flowMeta);
if (flowTo[2]) flowIntoBlock(world, pos.add( 0, 0, -1), flowMeta);
if (flowTo[3]) flowIntoBlock(world, pos.add( 0, 0, 1), flowMeta);
}
}
public boolean isFlowingVertically(IBlockAccess world, int x, int y, int z)
public boolean isFlowingVertically(IBlockAccess world, BlockPos pos)
{
return world.getBlock(x, y + densityDir, z) == this ||
(world.getBlock(x, y, z) == this && canFlowInto(world, x, y + densityDir, z));
return world.getBlockState(pos.offsetUp(densityDir)).getBlock() == this ||
(world.getBlockState(pos).getBlock() == this && canFlowInto(world, pos.offsetUp(densityDir)));
}
public boolean isSourceBlock(IBlockAccess world, int x, int y, int z)
public boolean isSourceBlock(IBlockAccess world, BlockPos pos)
{
return world.getBlock(x, y, z) == this && world.getBlockMetadata(x, y, z) == 0;
return world.getBlockState(pos) == this && ((Integer)world.getBlockState(pos).getValue(LEVEL)).intValue() == 0;
}
protected boolean[] getOptimalFlowDirections(World world, int x, int y, int z)
protected boolean[] getOptimalFlowDirections(World world, BlockPos pos)
{
for (int side = 0; side < 4; side++)
{
flowCost[side] = 1000;
int x2 = x;
int y2 = y;
int z2 = z;
BlockPos pos2 = pos;
switch (side)
{
case 0: --x2; break;
case 1: ++x2; break;
case 2: --z2; break;
case 3: ++z2; break;
case 0: pos2 = pos2.add(-1, 0, 0); break;
case 1: pos2 = pos2.add( 1, 0, 0); break;
case 2: pos2 = pos2.add( 0, 0, -1); break;
case 3: pos2 = pos2.add( 0, 0, 1); break;
}
if (!canFlowInto(world, x2, y2, z2) || isSourceBlock(world, x2, y2, z2))
if (!canFlowInto(world, pos2) || isSourceBlock(world, pos2))
{
continue;
}
if (canFlowInto(world, x2, y2 + densityDir, z2))
if (canFlowInto(world, pos2.add(0, densityDir, 0)))
{
flowCost[side] = 0;
}
else
{
flowCost[side] = calculateFlowCost(world, x2, y2, z2, 1, side);
flowCost[side] = calculateFlowCost(world, pos2, 1, side);
}
}
@@ -221,7 +220,7 @@ public class BlockFluidClassic extends BlockFluidBase
return isOptimalFlowDirection;
}
protected int calculateFlowCost(World world, int x, int y, int z, int recurseDepth, int side)
protected int calculateFlowCost(World world, BlockPos pos, int recurseDepth, int side)
{
int cost = 1000;
for (int adjSide = 0; adjSide < 4; adjSide++)
@@ -234,24 +233,22 @@ public class BlockFluidClassic extends BlockFluidBase
continue;
}
int x2 = x;
int y2 = y;
int z2 = z;
BlockPos pos2 = pos;
switch (adjSide)
{
case 0: --x2; break;
case 1: ++x2; break;
case 2: --z2; break;
case 3: ++z2; break;
case 0: pos2 = pos2.add(-1, 0, 0); break;
case 1: pos2 = pos2.add( 1, 0, 0); break;
case 2: pos2 = pos2.add( 0, 0, -1); break;
case 3: pos2 = pos2.add( 0, 0, 1); break;
}
if (!canFlowInto(world, x2, y2, z2) || isSourceBlock(world, x2, y2, z2))
if (!canFlowInto(world, pos2) || isSourceBlock(world, pos2))
{
continue;
}
if (canFlowInto(world, x2, y2 + densityDir, z2))
if (canFlowInto(world, pos2.add(0, densityDir, 0)))
{
return recurseDepth;
}
@@ -261,7 +258,7 @@ public class BlockFluidClassic extends BlockFluidBase
continue;
}
int min = calculateFlowCost(world, x2, y2, z2, recurseDepth + 1, adjSide);
int min = calculateFlowCost(world, pos2, recurseDepth + 1, adjSide);
if (min < cost)
{
cost = min;
@@ -270,20 +267,20 @@ public class BlockFluidClassic extends BlockFluidBase
return cost;
}
protected void flowIntoBlock(World world, int x, int y, int z, int meta)
protected void flowIntoBlock(World world, BlockPos pos, int meta)
{
if (meta < 0) return;
if (displaceIfPossible(world, x, y, z))
if (displaceIfPossible(world, pos))
{
world.setBlock(x, y, z, this, meta, 3);
world.setBlockState(pos, world.getBlockState(pos).withProperty(LEVEL, meta), 3);
}
}
protected boolean canFlowInto(IBlockAccess world, int x, int y, int z)
protected boolean canFlowInto(IBlockAccess world, BlockPos pos)
{
if (world.getBlock(x, y, z).isAir(world, x, y, z)) return true;
if (world.isAirBlock(pos)) return true;
Block block = world.getBlock(x, y, z);
Block block = world.getBlockState(pos).getBlock();
if (block == this)
{
return true;
@@ -303,12 +300,12 @@ public class BlockFluidClassic extends BlockFluidBase
return false;
}
int density = getDensity(world, x, y, z);
if (density == Integer.MAX_VALUE)
int density = getDensity(world, pos);
if (density == Integer.MAX_VALUE)
{
return true;
}
if (this.density > density)
{
return true;
@@ -319,9 +316,9 @@ public class BlockFluidClassic extends BlockFluidBase
}
}
protected int getLargerQuanta(IBlockAccess world, int x, int y, int z, int compare)
protected int getLargerQuanta(IBlockAccess world, BlockPos pos, int compare)
{
int quantaRemaining = getQuantaValue(world, x, y, z);
int quantaRemaining = getQuantaValue(world, pos);
if (quantaRemaining <= 0)
{
return compare;
@@ -331,24 +328,24 @@ public class BlockFluidClassic extends BlockFluidBase
/* IFluidBlock */
@Override
public FluidStack drain(World world, int x, int y, int z, boolean doDrain)
public FluidStack drain(World world, BlockPos pos, boolean doDrain)
{
if (!isSourceBlock(world, x, y, z))
if (!isSourceBlock(world, pos))
{
return null;
}
if (doDrain)
{
world.setBlock(x, y, z, Blocks.air);
world.setBlockToAir(pos);
}
return stack.copy();
}
@Override
public boolean canDrain(World world, int x, int y, int z)
public boolean canDrain(World world, BlockPos pos)
{
return isSourceBlock(world, x, y, z);
return isSourceBlock(world, pos);
}
}
}
@@ -4,18 +4,20 @@ package net.minecraftforge.fluids;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
/**
* This is a cellular-automata based finite fluid block implementation.
*
*
* It is highly recommended that you use/extend this class for finite fluid blocks.
*
*
* @author OvermindDL1, KingLemming
*
*
*/
public class BlockFluidFinite extends BlockFluidBase
{
@@ -25,26 +27,25 @@ public class BlockFluidFinite extends BlockFluidBase
}
@Override
public int getQuantaValue(IBlockAccess world, int x, int y, int z)
public int getQuantaValue(IBlockAccess world, BlockPos pos)
{
if (world.getBlock(x, y, z).isAir(world, x, y, z))
IBlockState state = world.getBlockState(pos);
if (state.getBlock().isAir(world, pos))
{
return 0;
}
if (world.getBlock(x, y, z) != this)
if (state.getBlock() != this)
{
return -1;
}
int quantaRemaining = world.getBlockMetadata(x, y, z) + 1;
return quantaRemaining;
return ((Integer)state.getValue(LEVEL)) + 1;
}
@Override
public boolean canCollideCheck(int meta, boolean fullHit)
public boolean canCollideCheck(IBlockState state, boolean fullHit)
{
return fullHit && meta == quantaPerBlock - 1;
return fullHit && ((Integer)state.getValue(LEVEL)) == quantaPerBlock - 1;
}
@Override
@@ -54,14 +55,14 @@ public class BlockFluidFinite extends BlockFluidBase
}
@Override
public void updateTick(World world, int x, int y, int z, Random rand)
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
{
boolean changed = false;
int quantaRemaining = world.getBlockMetadata(x, y, z) + 1;
int quantaRemaining = ((Integer)state.getValue(LEVEL)) + 1;
// Flow vertically if possible
int prevRemaining = quantaRemaining;
quantaRemaining = tryToFlowVerticallyInto(world, x, y, z, quantaRemaining);
quantaRemaining = tryToFlowVerticallyInto(world, pos, quantaRemaining);
if (quantaRemaining < 1)
{
@@ -72,7 +73,7 @@ public class BlockFluidFinite extends BlockFluidBase
changed = true;
if (quantaRemaining == 1)
{
world.setBlockMetadataWithNotify(x, y, z, quantaRemaining - 1, 2);
world.setBlockState(pos, state.withProperty(LEVEL, quantaRemaining - 1), 2);
return;
}
}
@@ -83,192 +84,110 @@ public class BlockFluidFinite extends BlockFluidBase
// Flow out if possible
int lowerthan = quantaRemaining - 1;
if (displaceIfPossible(world, x, y, z - 1)) world.setBlock(x, y, z - 1, Blocks.air);
if (displaceIfPossible(world, x, y, z + 1)) world.setBlock(x, y, z + 1, Blocks.air);
if (displaceIfPossible(world, x - 1, y, z )) world.setBlock(x - 1, y, z, Blocks.air);
if (displaceIfPossible(world, x + 1, y, z )) world.setBlock(x + 1, y, z, Blocks.air);
int north = getQuantaValueBelow(world, x, y, z - 1, lowerthan);
int south = getQuantaValueBelow(world, x, y, z + 1, lowerthan);
int west = getQuantaValueBelow(world, x - 1, y, z, lowerthan);
int east = getQuantaValueBelow(world, x + 1, y, z, lowerthan);
int total = quantaRemaining;
int count = 1;
if (north >= 0)
for (EnumFacing side : EnumFacing.Plane.HORIZONTAL)
{
count++;
total += north;
}
BlockPos off = pos.offset(side);
if (displaceIfPossible(world, off))
world.setBlockToAir(off);
if (south >= 0)
{
count++;
total += south;
}
if (west >= 0)
{
count++;
total += west;
}
if (east >= 0)
{
++count;
total += east;
int quanta = getQuantaValueBelow(world, off, lowerthan);
if (quanta >= 0)
{
count++;
total += quanta;
}
}
if (count == 1)
{
if (changed)
{
world.setBlockMetadataWithNotify(x, y, z, quantaRemaining - 1, 2);
world.setBlockState(pos, state.withProperty(LEVEL, quantaRemaining - 1), 2);
}
return;
}
int each = total / count;
int rem = total % count;
if (north >= 0)
for (EnumFacing side : EnumFacing.Plane.HORIZONTAL)
{
int newnorth = each;
if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0)
BlockPos off = pos.offset(side);
int quanta = getQuantaValueBelow(world, off, lowerthan);
if (quanta >= 0)
{
++newnorth;
--rem;
}
int newquanta = each;
if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0)
{
++newquanta;
--rem;
}
if (newnorth != north)
{
if (newnorth == 0)
if (newquanta != quanta)
{
world.setBlock(x, y, z - 1, Blocks.air);
if (newquanta == 0)
{
world.setBlockToAir(off);
}
else
{
world.setBlockState(off, getDefaultState().withProperty(LEVEL, newquanta - 1), 2);
}
world.scheduleUpdate(off, this, tickRate);
}
else
{
world.setBlock(x, y, z - 1, this, newnorth - 1, 2);
}
world.scheduleBlockUpdate(x, y, z - 1, this, tickRate);
--count;
}
--count;
}
if (south >= 0)
{
int newsouth = each;
if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0)
{
++newsouth;
--rem;
}
if (newsouth != south)
{
if (newsouth == 0)
{
world.setBlock(x, y, z + 1, Blocks.air);
}
else
{
world.setBlock(x, y, z + 1, this, newsouth - 1, 2);
}
world.scheduleBlockUpdate(x, y, z + 1, this, tickRate);
}
--count;
}
if (west >= 0)
{
int newwest = each;
if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0)
{
++newwest;
--rem;
}
if (newwest != west)
{
if (newwest == 0)
{
world.setBlock(x - 1, y, z, Blocks.air);
}
else
{
world.setBlock(x - 1, y, z, this, newwest - 1, 2);
}
world.scheduleBlockUpdate(x - 1, y, z, this, tickRate);
}
--count;
}
if (east >= 0)
{
int neweast = each;
if (rem == count || rem > 1 && rand.nextInt(count - rem) != 0)
{
++neweast;
--rem;
}
if (neweast != east)
{
if (neweast == 0)
{
world.setBlock(x + 1, y, z, Blocks.air);
}
else
{
world.setBlock(x + 1, y, z, this, neweast - 1, 2);
}
world.scheduleBlockUpdate(x + 1, y, z, this, tickRate);
}
--count;
}
if (rem > 0)
{
++each;
}
world.setBlockMetadataWithNotify(x, y, z, each - 1, 2);
world.setBlockState(pos, state.withProperty(LEVEL, each - 1), 2);
}
public int tryToFlowVerticallyInto(World world, int x, int y, int z, int amtToInput)
public int tryToFlowVerticallyInto(World world, BlockPos pos, int amtToInput)
{
int otherY = y + densityDir;
if (otherY < 0 || otherY >= world.getHeight())
IBlockState myState = world.getBlockState(pos);
BlockPos other = pos.add(0, densityDir, 0);
if (other.getY() < 0 || other.getY() >= world.getHeight())
{
world.setBlock(x, y, z, Blocks.air);
world.setBlockToAir(pos);
return 0;
}
int amt = getQuantaValueBelow(world, x, otherY, z, quantaPerBlock);
int amt = getQuantaValueBelow(world, other, quantaPerBlock);
if (amt >= 0)
{
amt += amtToInput;
if (amt > quantaPerBlock)
{
world.setBlock(x, otherY, z, this, quantaPerBlock - 1, 3);
world.scheduleBlockUpdate(x, otherY, z, this, tickRate);
world.setBlockState(other, myState.withProperty(LEVEL, quantaPerBlock - 1), 3);
world.scheduleUpdate(other, this, tickRate);
return amt - quantaPerBlock;
}
else if (amt > 0)
{
world.setBlock(x, otherY, z, this, amt - 1, 3);
world.scheduleBlockUpdate(x, otherY, z, this, tickRate);
world.setBlock(x, y, z, Blocks.air);
world.setBlockState(other, myState.withProperty(LEVEL, amt - 1), 3);
world.scheduleUpdate(other, this, tickRate);
world.setBlockToAir(pos);
return 0;
}
return amtToInput;
}
else
{
int density_other = getDensity(world, x, otherY, z);
int density_other = getDensity(world, other);
if (density_other == Integer.MAX_VALUE)
{
if (displaceIfPossible(world, x, otherY, z))
if (displaceIfPossible(world, other))
{
world.setBlock(x, otherY, z, this, amtToInput - 1, 3);
world.scheduleBlockUpdate(x, otherY, z, this, tickRate);
world.setBlock(x, y, z, Blocks.air);
world.setBlockState(other, myState.withProperty(LEVEL, amtToInput - 1), 3);
world.scheduleUpdate(other, this, tickRate);
world.setBlockToAir(pos);
return 0;
}
else
@@ -281,12 +200,11 @@ public class BlockFluidFinite extends BlockFluidBase
{
if (density_other < density) // then swap
{
BlockFluidBase block = (BlockFluidBase)world.getBlock(x, otherY, z);
int otherData = world.getBlockMetadata(x, otherY, z);
world.setBlock(x, otherY, z, this, amtToInput - 1, 3);
world.setBlock(x, y, z, block, otherData, 3);
world.scheduleBlockUpdate(x, otherY, z, this, tickRate);
world.scheduleBlockUpdate(x, y, z, block, block.tickRate(world));
IBlockState state = world.getBlockState(other);
world.setBlockState(other, myState.withProperty(LEVEL, amtToInput - 1), 3);
world.setBlockState(pos, state, 3);
world.scheduleUpdate(other, this, tickRate);
world.scheduleUpdate(pos, state.getBlock(), state.getBlock().tickRate(world));
return 0;
}
}
@@ -294,12 +212,11 @@ public class BlockFluidFinite extends BlockFluidBase
{
if (density_other > density)
{
BlockFluidBase block = (BlockFluidBase)world.getBlock(x, otherY, z);
int otherData = world.getBlockMetadata(x, otherY, z);
world.setBlock(x, otherY, z, this, amtToInput - 1, 3);
world.setBlock(x, y, z, block, otherData, 3);
world.scheduleBlockUpdate(x, otherY, z, this, tickRate);
world.scheduleBlockUpdate(x, y, z, block, block.tickRate(world));
IBlockState state = world.getBlockState(other);
world.setBlockState(other, myState.withProperty(LEVEL, amtToInput - 1), 3);
world.setBlockState(other, state, 3);
world.scheduleUpdate(other, this, tickRate);
world.scheduleUpdate(other, state.getBlock(), state.getBlock().tickRate(world));
return 0;
}
}
@@ -309,20 +226,20 @@ public class BlockFluidFinite extends BlockFluidBase
/* IFluidBlock */
@Override
public FluidStack drain(World world, int x, int y, int z, boolean doDrain)
public FluidStack drain(World world, BlockPos pos, boolean doDrain)
{
if (doDrain)
{
world.setBlock(x, y, z, Blocks.air);
world.setBlockToAir(pos);
}
return new FluidStack(getFluid(),
MathHelper.floor_float(getQuantaPercentage(world, x, y, z) * FluidContainerRegistry.BUCKET_VOLUME));
MathHelper.floor_float(getQuantaPercentage(world, pos) * FluidContainerRegistry.BUCKET_VOLUME));
}
@Override
public boolean canDrain(World world, int x, int y, int z)
public boolean canDrain(World world, BlockPos pos)
{
return true;
}
}
}
@@ -6,12 +6,12 @@ import java.util.Map;
import com.google.common.collect.Maps;
import net.minecraft.block.Block;
import net.minecraft.util.IIcon;
import net.minecraft.util.BlockPos;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeModContainer;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.LoaderException;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.LoaderException;
import net.minecraft.item.EnumRarity;
/**
@@ -41,8 +41,8 @@ public class Fluid
protected String unlocalizedName;
/** The Icons for this fluid. */
protected IIcon stillIcon;
protected IIcon flowingIcon;
//protected IIcon stillIcon;
//protected IIcon flowingIcon;
/**
* The light level emitted by this fluid.
@@ -62,7 +62,7 @@ public class Fluid
/**
* Temperature of the fluid - completely arbitrary; higher temperature indicates that the fluid is
* hotter than air.
*
*
* Default value is approximately the real-life room temperature of water in degrees Kelvin.
*/
protected int temperature = 295;
@@ -89,7 +89,7 @@ public class Fluid
*
* Used primarily in tool tips.
*/
protected EnumRarity rarity = EnumRarity.common;
protected EnumRarity rarity = EnumRarity.COMMON;
/**
* If there is a Block implementation of the Fluid, the Block is linked here.
@@ -194,7 +194,7 @@ public class Fluid
{
return getLocalizedName();
}
/**
* Use the FluidStack sensitive version above
*/
@@ -254,7 +254,7 @@ public class Fluid
{
return this.isGaseous;
}
public EnumRarity getRarity()
{
return rarity;
@@ -265,6 +265,7 @@ public class Fluid
return 0xFFFFFF;
}
/*
public final Fluid setStillIcon(IIcon stillIcon)
{
this.stillIcon = stillIcon;
@@ -298,6 +299,7 @@ public class Fluid
{
return this.flowingIcon;
}
*/
/* Stack-based Accessors */
public int getLuminosity(FluidStack stack){ return getLuminosity(); }
@@ -307,16 +309,16 @@ public class Fluid
public boolean isGaseous(FluidStack stack){ return isGaseous(); }
public EnumRarity getRarity(FluidStack stack){ return getRarity(); }
public int getColor(FluidStack stack){ return getColor(); }
public IIcon getIcon(FluidStack stack){ return getIcon(); }
//public IIcon 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 getTemperature(World world, int x, int y, int z){ return getTemperature(); }
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 EnumRarity getRarity(World world, int x, int y, int z){ return getRarity(); }
public int getColor(World world, int x, int y, int z){ return getColor(); }
public IIcon getIcon(World world, int x, int y, int z){ return getIcon(); }
public int getLuminosity(World world, BlockPos pos){ return getLuminosity(); }
public int getDensity(World world, BlockPos pos){ return getDensity(); }
public int getTemperature(World world, BlockPos pos){ return getTemperature(); }
public int getViscosity(World world, BlockPos pos){ return getViscosity(); }
public boolean isGaseous(World world, BlockPos pos){ return isGaseous(); }
public EnumRarity getRarity(World world, BlockPos pos){ return getRarity(); }
public int getColor(World world, BlockPos pos){ return getColor(); }
//public IIcon getIcon(World world, BlockPos pos){ return getIcon(); }
private static Map<String, String> legacyNames = Maps.newHashMap();
static String convertLegacyName(String fluidName)
@@ -11,7 +11,7 @@ import java.util.Set;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -1,66 +1,49 @@
package net.minecraftforge.fluids;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event;
public class FluidEvent extends Event
{
public final FluidStack fluid;
public final int x;
public final int y;
public final int z;
public final World world;
public final BlockPos pos;
public FluidEvent(FluidStack fluid, World world, int x, int y, int z)
public FluidEvent(FluidStack fluid, World world, BlockPos pos)
{
this.fluid = fluid;
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.pos = pos;
}
/**
* Mods should fire this event when they move fluids around.
*
* @author cpw
*
*
*/
public static class FluidMotionEvent extends FluidEvent
{
public FluidMotionEvent(FluidStack fluid, World world, int x, int y, int z)
public FluidMotionEvent(FluidStack fluid, World world, BlockPos pos)
{
super(fluid, world, x, y, z);
super(fluid, world, pos);
}
}
/**
* Mods should fire this event when a fluid is {@link IFluidTank#fill(FluidStack, boolean)}
* their tank implementation. {@link FluidTank} does.
*
* @author cpw
*
*
*/
public static class FluidFillingEvent extends FluidEvent
{
public final IFluidTank tank;
public final int amount;
/**
* @deprecated Will be removed in 1.8
*
*/
@Deprecated
public FluidFillingEvent(FluidStack fluid, World world, int x, int y, int z, IFluidTank tank)
public FluidFillingEvent(FluidStack fluid, World world, BlockPos pos, IFluidTank tank, int amount)
{
this(fluid, world, x, y, z, tank, -1);
}
public FluidFillingEvent(FluidStack fluid, World world, int x, int y, int z, IFluidTank tank, int amount)
{
super(fluid, world, x, y, z);
super(fluid, world, pos);
this.tank = tank;
this.amount = amount;
}
@@ -69,28 +52,16 @@ public class FluidEvent extends Event
/**
* Mods should fire this event when a fluid is {@link IFluidTank#drain(int, boolean)} from their
* tank.
*
* @author cpw
*
*
*/
public static class FluidDrainingEvent extends FluidEvent
{
public final IFluidTank tank;
public final int amount;
/**
* @deprecated Will be removed in 1.8
*
*/
@Deprecated
public FluidDrainingEvent(FluidStack fluid, World world, int x, int y, int z, IFluidTank tank)
public FluidDrainingEvent(FluidStack fluid, World world, BlockPos pos, IFluidTank tank, int amount)
{
this(fluid, world, x, y, z, tank, -1);
}
public FluidDrainingEvent(FluidStack fluid, World world, int x, int y, int z, IFluidTank tank, int amount)
{
super(fluid, world, x, y, z);
super(fluid, world, pos);
this.amount = amount;
this.tank = tank;
}
@@ -99,21 +70,19 @@ public class FluidEvent extends Event
/**
* Mods should fire this event when a fluid "spills", for example, if a block containing fluid
* is broken.
*
* @author cpw
*
*
*/
public static class FluidSpilledEvent extends FluidEvent
{
public FluidSpilledEvent(FluidStack fluid, World world, int x, int y, int z)
public FluidSpilledEvent(FluidStack fluid, World world, BlockPos pos)
{
super(fluid, world, x, y, z);
super(fluid, world, pos);
}
}
/**
* A handy shortcut for firing the various fluid events.
*
*
* @param event
*/
public static final void fireEvent(FluidEvent event)
@@ -13,7 +13,7 @@ import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* Handles Fluid registrations. Fluids MUST be registered in order to function.
@@ -6,9 +6,9 @@ import net.minecraft.tileentity.TileEntity;
/**
* Reference implementation of {@link IFluidTank}. Use/extend this or implement your own.
*
*
* @author King Lemming, cpw (LiquidTank)
*
*
*/
public class FluidTank implements IFluidTank
{
@@ -127,7 +127,7 @@ public class FluidTank implements IFluidTank
if (tile != null)
{
FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fluid, tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, this, fluid.amount));
FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fluid, tile.getWorld(), tile.getPos(), this, fluid.amount));
}
return fluid.amount;
}
@@ -150,7 +150,7 @@ public class FluidTank implements IFluidTank
if (tile != null)
{
FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fluid, tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, this, filled));
FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fluid, tile.getWorld(), tile.getPos(), this, filled));
}
return filled;
}
@@ -180,9 +180,9 @@ public class FluidTank implements IFluidTank
if (tile != null)
{
FluidEvent.fireEvent(new FluidEvent.FluidDrainingEvent(fluid, tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, this, drained));
FluidEvent.fireEvent(new FluidEvent.FluidDrainingEvent(fluid, tile.getWorld(), tile.getPos(), this, drained));
}
}
return stack;
}
}
}
@@ -1,14 +1,15 @@
package net.minecraftforge.fluids;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
/**
* Implement this interface on Block classes which represent world-placeable Fluids.
*
*
* NOTE: Using/extending the reference implementations {@link BlockFluidBase} is encouraged.
*
*
* @author King Lemming
*
*
*/
public interface IFluidBlock
{
@@ -19,33 +20,33 @@ public interface IFluidBlock
/**
* Attempt to drain the block. This method should be called by devices such as pumps.
*
*
* NOTE: The block is intended to handle its own state changes.
*
*
* @param doDrain
* If false, the drain will only be simulated.
* @return
*/
FluidStack drain(World world, int x, int y, int z, boolean doDrain);
FluidStack drain(World world, BlockPos pos, boolean doDrain);
/**
* Check to see if a block can be drained. This method should be called by devices such as
* pumps.
*
*
* @param doDrain
* If false, the drain will only be simulated.
* @return
*/
boolean canDrain(World world, int x, int y, int z);
boolean canDrain(World world, BlockPos pos);
/**
* Returns the amount of a single block is filled. Value between 0 and 1.
* 1 meaning the entire 1x1x1 cube is full, 0 meaning completely empty.
*
* If the return value is negative. It will be treated as filling the block
*
* If the return value is negative. It will be treated as filling the block
* from the top down instead of bottom up.
*
*
* @return
*/
float getFilledPercentage(World world, int x, int y, int z);
}
float getFilledPercentage(World world, BlockPos pos);
}
@@ -1,21 +1,21 @@
package net.minecraftforge.fluids;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraft.util.EnumFacing;
/**
* Implement this interface on TileEntities which should handle fluids, generally storing them in
* one or more internal {@link IFluidTank} objects.
*
*
* A reference implementation is provided {@link TileFluidHandler}.
*
*
* @author King Lemming
*
*
*/
public interface IFluidHandler
{
/**
* Fills fluid into internal tanks, distribution is left entirely to the IFluidHandler.
*
*
* @param from
* Orientation the Fluid is pumped in from.
* @param resource
@@ -24,11 +24,11 @@ public interface IFluidHandler
* If false, fill will only be simulated.
* @return Amount of resource that was (or would have been, if simulated) filled.
*/
int fill(ForgeDirection from, FluidStack resource, boolean doFill);
int fill(EnumFacing from, FluidStack resource, boolean doFill);
/**
* Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
*
*
* @param from
* Orientation the Fluid is drained to.
* @param resource
@@ -38,13 +38,13 @@ public interface IFluidHandler
* @return FluidStack representing the Fluid and amount that was (or would have been, if
* simulated) drained.
*/
FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain);
FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain);
/**
* Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
*
*
* This method is not Fluid-sensitive.
*
*
* @param from
* Orientation the fluid is drained to.
* @param maxDrain
@@ -54,29 +54,29 @@ public interface IFluidHandler
* @return FluidStack representing the Fluid and amount that was (or would have been, if
* simulated) drained.
*/
FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain);
FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain);
/**
* Returns true if the given fluid can be inserted into the given direction.
*
*
* More formally, this should return true if fluid is able to enter from the given direction.
*/
boolean canFill(ForgeDirection from, Fluid fluid);
boolean canFill(EnumFacing from, Fluid fluid);
/**
* Returns true if the given fluid can be extracted from the given direction.
*
*
* More formally, this should return true if fluid is able to leave from the given direction.
*/
boolean canDrain(ForgeDirection from, Fluid fluid);
boolean canDrain(EnumFacing from, Fluid fluid);
/**
* Returns an array of objects which represent the internal tanks. These objects cannot be used
* to manipulate the internal tanks. See {@link FluidTankInfo}.
*
*
* @param from
* Orientation determining which tanks should be queried.
* @return Info for the relevant internal tanks.
*/
FluidTankInfo[] getTankInfo(ForgeDirection from);
FluidTankInfo[] getTankInfo(EnumFacing from);
}
@@ -6,9 +6,9 @@ import net.minecraft.nbt.NBTTagCompound;
/**
* Reference implementation of {@link IFluidContainerItem}. Use/extend this or implement your own.
*
*
* @author King Lemming
*
*
*/
public class ItemFluidContainer extends Item implements IFluidContainerItem
{
@@ -35,11 +35,11 @@ public class ItemFluidContainer extends Item implements IFluidContainerItem
@Override
public FluidStack getFluid(ItemStack container)
{
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid"))
if (!container.hasTagCompound() || !container.getTagCompound().hasKey("Fluid"))
{
return null;
}
return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));
return FluidStack.loadFluidStackFromNBT(container.getTagCompound().getCompoundTag("Fluid"));
}
@Override
@@ -58,12 +58,12 @@ public class ItemFluidContainer extends Item implements IFluidContainerItem
if (!doFill)
{
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid"))
if (!container.hasTagCompound() || !container.getTagCompound().hasKey("Fluid"))
{
return Math.min(capacity, resource.amount);
}
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.getTagCompound().getCompoundTag("Fluid"));
if (stack == null)
{
@@ -78,27 +78,27 @@ public class ItemFluidContainer extends Item implements IFluidContainerItem
return Math.min(capacity - stack.amount, resource.amount);
}
if (container.stackTagCompound == null)
if (!container.hasTagCompound())
{
container.stackTagCompound = new NBTTagCompound();
container.setTagCompound(new NBTTagCompound());
}
if (!container.stackTagCompound.hasKey("Fluid"))
if (!container.getTagCompound().hasKey("Fluid"))
{
NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());
if (capacity < resource.amount)
{
fluidTag.setInteger("Amount", capacity);
container.stackTagCompound.setTag("Fluid", fluidTag);
container.getTagCompound().setTag("Fluid", fluidTag);
return capacity;
}
container.stackTagCompound.setTag("Fluid", fluidTag);
container.getTagCompound().setTag("Fluid", fluidTag);
return resource.amount;
}
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid");
NBTTagCompound fluidTag = container.getTagCompound().getCompoundTag("Fluid");
FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);
if (!stack.isFluidEqual(resource))
@@ -117,19 +117,19 @@ public class ItemFluidContainer extends Item implements IFluidContainerItem
stack.amount = capacity;
}
container.stackTagCompound.setTag("Fluid", stack.writeToNBT(fluidTag));
container.getTagCompound().setTag("Fluid", stack.writeToNBT(fluidTag));
return filled;
}
@Override
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain)
{
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid"))
if (!container.hasTagCompound() || !container.getTagCompound().hasKey("Fluid"))
{
return null;
}
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.getTagCompound().getCompoundTag("Fluid"));
if (stack == null)
{
return null;
@@ -141,18 +141,18 @@ public class ItemFluidContainer extends Item implements IFluidContainerItem
{
if (currentAmount == stack.amount)
{
container.stackTagCompound.removeTag("Fluid");
container.getTagCompound().removeTag("Fluid");
if (container.stackTagCompound.hasNoTags())
if (container.getTagCompound().hasNoTags())
{
container.stackTagCompound = null;
container.setTagCompound(null);
}
return stack;
}
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid");
NBTTagCompound fluidTag = container.getTagCompound().getCompoundTag("Fluid");
fluidTag.setInteger("Amount", currentAmount - stack.amount);
container.stackTagCompound.setTag("Fluid", fluidTag);
container.getTagCompound().setTag("Fluid", fluidTag);
}
return stack;
}
@@ -1,5 +1,7 @@
package net.minecraftforge.fluids;
//TODO: Get some test liquids and test this out -.-
/*
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
@@ -8,14 +10,14 @@ import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import net.minecraftforge.fml.client.registry.ISimpleBlockRenderingHandler;
/**
* Default renderer for Forge fluid blocks.
*
*
* @author King Lemming
*
*/
*
* /
public class RenderBlockFluid implements ISimpleBlockRenderingHandler
{
public static RenderBlockFluid instance = new RenderBlockFluid();
@@ -30,7 +32,7 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler
{
float total = 0;
int count = 0;
float end = 0;
for (int i = 0; i < flow.length; i++)
@@ -46,10 +48,10 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler
count++;
}
}
if (end == 0)
end = total / count;
return end;
}
@@ -71,7 +73,7 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler
return !world.getBlock(x, y, z).getMaterial().isSolid() && world.getBlock(x, y - block.densityDir, z) == block ? 1 : block.getQuantaPercentage(world, x, y, z) * 0.875F;
}
/* ISimpleBlockRenderingHandler */
/* ISimpleBlockRenderingHandler * /
@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer){}
@@ -98,9 +100,9 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler
boolean[] renderSides = new boolean[]
{
block.shouldSideBeRendered(world, x, y, z - 1, 2),
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, 4),
block.shouldSideBeRendered(world, x + 1, y, z, 5)
};
@@ -334,4 +336,5 @@ public class RenderBlockFluid implements ISimpleBlockRenderingHandler
if (icon != null) return icon;
return ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno");
}
}
}
*/
@@ -3,13 +3,13 @@ package net.minecraftforge.fluids;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraft.util.EnumFacing;
/**
* Reference Tile Entity implementation of {@link IFluidHandler}. Use/extend this or write your own.
*
*
* @author King Lemming
*
*
*/
public class TileFluidHandler extends TileEntity implements IFluidHandler
{
@@ -31,13 +31,13 @@ public class TileFluidHandler extends TileEntity implements IFluidHandler
/* IFluidHandler */
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
public int fill(EnumFacing from, FluidStack resource, boolean doFill)
{
return tank.fill(resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain)
{
if (resource == null || !resource.isFluidEqual(tank.getFluid()))
{
@@ -47,25 +47,25 @@ public class TileFluidHandler extends TileEntity implements IFluidHandler
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain)
{
return tank.drain(maxDrain, doDrain);
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
public boolean canFill(EnumFacing from, Fluid fluid)
{
return true;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
public boolean canDrain(EnumFacing from, Fluid fluid)
{
return true;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
public FluidTankInfo[] getTankInfo(EnumFacing from)
{
return new FluidTankInfo[] { tank.getInfo() };
}