BlockLiquid: Difference between revisions

From Minecraft Parkour Wiki
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:
}
}


public boolean isFullCube()

public static float getLiquidHeightPercent(int meta)
{
{
if (meta >= 8)
return false;
{
meta = 0;
}

return (meta + 1.0) / 9.0F;
}
}


protected int getLevel(IBlockAccess worldIn, BlockPos pos)
public boolean isFlowingDown(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
{
{
return worldIn.getBlockState(pos).getBlock().getMaterial() == this.blockMaterial ? ((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() : -1;
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);
}
}


protected int getEffectiveFlowDecay(IBlockAccess worldIn, BlockPos pos)
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
{
{
int lvl = this.getLevel(worldIn, pos);
return null;
return lvl >= 8 ? 0 : lvl;
}
}


public boolean isFullCube()
public static float getLiquidHeightPercent(int i)
{
{
return false;
if (i >= 8)
i = 0;

return (i + 1.0) / 9.0F;
}
}


public boolean isBlockSolid(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
protected int getLevel(IBlockAccess worldIn, BlockPos pos)
{
{
Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
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)
{
{
return null;
int lvl = this.getLevel(worldIn, pos);
return lvl >= 8 ? 0 : lvl;
}
}

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 delta = adjFlowDecay - flowDecay;
double dX = (double) ((blockpos.getX()-pos.getX())*delta);
int deltaX = blockpos.getX() - pos.getX();
double dY = (double) ((blockpos.getY()-pos.getY())*delta);
int deltaZ = blockpos.getZ() - pos.getZ();
double dZ = (double) ((blockpos.getZ()-pos.getZ())*delta);
//one of these is equal to 0
flow = flow.addVector(dX, dY, dZ);
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);
}
}
}


//seems to add downward current?
//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.isBlockSolid(worldIn, blockpos_alt, enumfacing_alt) || this.isBlockSolid(worldIn, blockpos_alt.up(), 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);
flow = flow.normalize().addVector(0.0D, -6.0D, 0.0D);

Revision as of 18:11, 3 April 2020

Back to SourceCode

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));
    }
}