BlockLiquid: Difference between revisions
Content added Content deleted
mNo edit summary |
mNo edit summary |
||
Line 6: | Line 6: | ||
{ |
{ |
||
public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 15); |
public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 15); |
||
/* 0 = still, 1-7 = regular liquid level, |
|||
>=8 is downward? */ |
|||
⚫ | |||
protected BlockLiquid(Material materialIn) |
protected BlockLiquid(Material materialIn) |
||
Line 14: | Line 17: | ||
} |
} |
||
⚫ | |||
⚫ | |||
{ |
{ |
||
return false; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
public boolean isFlowingDown(IBlockAccess worldIn, BlockPos pos, EnumFacing side) |
|||
{ |
{ |
||
Material material = worldIn.getBlockState(pos).getBlock().getMaterial(); |
|||
⚫ | |||
if (material == this.blockMaterial) |
|||
return false; |
|||
else if (side == EnumFacing.UP) |
|||
return true; |
|||
else if (material == Material.ice) |
|||
return false; |
|||
else |
|||
return super.isFlowingDown(worldIn, pos, side); |
|||
} |
} |
||
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) |
|||
{ |
{ |
||
return null; |
|||
⚫ | |||
} |
} |
||
⚫ | |||
⚫ | |||
{ |
{ |
||
if (i >= 8) |
|||
⚫ | |||
⚫ | |||
} |
} |
||
protected int getLevel(IBlockAccess worldIn, BlockPos pos) |
|||
{ |
{ |
||
return worldIn.getBlockState(pos).getBlock().getMaterial() == this.blockMaterial ? ((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() : -1; |
|||
return material == this.blockMaterial ? false : (side == EnumFacing.UP ? true : (material == Material.ice ? false : super.isBlockSolid(worldIn, pos, side))); |
|||
} |
} |
||
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) |
|||
protected int getEffectiveFlowDecay(IBlockAccess worldIn, BlockPos pos) |
|||
{ |
{ |
||
int lvl = this.getLevel(worldIn, pos); |
|||
⚫ | |||
} |
} |
||
protected Vec3 getFlowVector(IBlockAccess worldIn, BlockPos pos) |
protected Vec3 getFlowVector(IBlockAccess worldIn, BlockPos pos) |
||
{ |
{ |
||
Line 57: | Line 71: | ||
int flowDecay = this.getEffectiveFlowDecay(worldIn, pos); |
int flowDecay = this.getEffectiveFlowDecay(worldIn, pos); |
||
//add sideward motion |
|||
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) |
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) //N,E,S,W |
||
{ |
{ |
||
BlockPos blockpos = pos.offset(enumfacing); |
BlockPos blockpos = pos.offset(enumfacing); |
||
int adjFlowDecay = this.getEffectiveFlowDecay(worldIn, blockpos); |
int adjFlowDecay = this.getEffectiveFlowDecay(worldIn, blockpos); |
||
int deltaX = blockpos.getX() - pos.getX(); |
|||
int deltaZ = blockpos.getZ() - pos.getZ(); |
|||
//one of these is equal to 0 |
|||
if (adjFlowDecay < 0) |
|||
{ |
|||
if (!worldIn.getBlockState(blockpos).getBlock().getMaterial().blocksMovement()) |
|||
{ |
|||
adjFlowDecay = this.getEffectiveFlowDecay(worldIn, blockpos.down()); |
|||
if (adjFlowDecay >= 0) |
|||
{ |
|||
int force = adjFlowDecay - (flowDecay - 8); |
|||
flow = flow.addVector(deltaX*force, 0, deltaZ*force); |
|||
} |
|||
} |
|||
} |
|||
else if (adjFlowDecay >= 0) |
|||
{ |
|||
int force = adjFlowDecay - flowDecay; |
|||
flow = flow.addVector(deltaX*force, 0, deltaZ*force); |
|||
} |
|||
} |
} |
||
// |
//add downward motion |
||
if (((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() >= 8) |
if (((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() >= 8) |
||
{ |
{ |
||
for (EnumFacing enumfacing_alt : EnumFacing.Plane.HORIZONTAL) |
for (EnumFacing enumfacing_alt : EnumFacing.Plane.HORIZONTAL) //N,E,S,W |
||
{ |
{ |
||
BlockPos blockpos_alt = pos.offset(enumfacing_alt); |
BlockPos blockpos_alt = pos.offset(enumfacing_alt); |
||
if (this. |
if (this.isFlowingDown(worldIn, blockpos_alt, enumfacing_alt) || this.isFlowingDown(worldIn, blockpos_alt.up(), enumfacing_alt)) |
||
{ |
{ |
||
flow = flow.normalize().addVector(0.0D, -6.0D, 0.0D); |
flow = flow.normalize().addVector(0.0D, -6.0D, 0.0D); |
Revision as of 18:11, 3 April 2020
package net.minecraft.block;
public abstract class BlockLiquid extends Block
{
public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 15);
/* 0 = still, 1-7 = regular liquid level,
>=8 is downward? */
protected BlockLiquid(Material materialIn)
{
super(materialIn);
this.setDefaultState(this.blockState.getBaseState().withProperty(LEVEL, Integer.valueOf(0)));
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
public boolean isFullCube()
{
return false;
}
public boolean isFlowingDown(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
{
Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
if (material == this.blockMaterial)
return false;
else if (side == EnumFacing.UP)
return true;
else if (material == Material.ice)
return false;
else
return super.isFlowingDown(worldIn, pos, side);
}
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
{
return null;
}
public static float getLiquidHeightPercent(int i)
{
if (i >= 8)
i = 0;
return (i + 1.0) / 9.0F;
}
protected int getLevel(IBlockAccess worldIn, BlockPos pos)
{
return worldIn.getBlockState(pos).getBlock().getMaterial() == this.blockMaterial ? ((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() : -1;
}
protected int getEffectiveFlowDecay(IBlockAccess worldIn, BlockPos pos)
{
int lvl = this.getLevel(worldIn, pos);
return lvl >= 8 ? 0 : lvl;
}
protected Vec3 getFlowVector(IBlockAccess worldIn, BlockPos pos)
{
Vec3 flow = new Vec3(0.0D, 0.0D, 0.0D);
int flowDecay = this.getEffectiveFlowDecay(worldIn, pos);
//add sideward motion
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) //N,E,S,W
{
BlockPos blockpos = pos.offset(enumfacing);
int adjFlowDecay = this.getEffectiveFlowDecay(worldIn, blockpos);
int deltaX = blockpos.getX() - pos.getX();
int deltaZ = blockpos.getZ() - pos.getZ();
//one of these is equal to 0
if (adjFlowDecay < 0)
{
if (!worldIn.getBlockState(blockpos).getBlock().getMaterial().blocksMovement())
{
adjFlowDecay = this.getEffectiveFlowDecay(worldIn, blockpos.down());
if (adjFlowDecay >= 0)
{
int force = adjFlowDecay - (flowDecay - 8);
flow = flow.addVector(deltaX*force, 0, deltaZ*force);
}
}
}
else if (adjFlowDecay >= 0)
{
int force = adjFlowDecay - flowDecay;
flow = flow.addVector(deltaX*force, 0, deltaZ*force);
}
}
//add downward motion
if (((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() >= 8)
{
for (EnumFacing enumfacing_alt : EnumFacing.Plane.HORIZONTAL) //N,E,S,W
{
BlockPos blockpos_alt = pos.offset(enumfacing_alt);
if (this.isFlowingDown(worldIn, blockpos_alt, enumfacing_alt) || this.isFlowingDown(worldIn, blockpos_alt.up(), enumfacing_alt))
{
flow = flow.normalize().addVector(0.0D, -6.0D, 0.0D);
break;
}
}
}
return flow.normalize();
}
public Vec3 modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3 motion)
{
return motion.add(this.getFlowVector(worldIn, pos));
}
}