BlockLiquid

From Minecraft Parkour Wiki
Revision as of 22:39, 2 April 2020 by MCPK (talk | contribs) (created page, but a lot of understanding is needed still)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Back to SourceCode

package net.minecraft.block;

public abstract class BlockLiquid extends Block
{
    public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 15);

    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 static float getLiquidHeightPercent(int meta)
    {
        if (meta >= 8)
        {
            meta = 0;
        }

        return (meta + 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;
    }

    public boolean isFullCube()
    {
        return false;
    }

    public boolean isBlockSolid(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
    {
        Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
        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)
    {
        return null;
    }

    protected Vec3 getFlowVector(IBlockAccess worldIn, BlockPos pos)
    {
        Vec3 flow = new Vec3(0.0D, 0.0D, 0.0D);
        int flowDecay = this.getEffectiveFlowDecay(worldIn, pos);

        for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
        {
            BlockPos blockpos = pos.offset(enumfacing);
            int adjFlowDecay = this.getEffectiveFlowDecay(worldIn, blockpos);
            int delta = adjFlowDecay - flowDecay;
            flow = flow.addVector( (blockpos.getX()-pos.getX())*delta, (blockpos.getY()-pos.getY())*delta, (blockpos.getZ()-pos.getZ())*delta);
        }

        //TODO: what does this do?
        if (((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() >= 8)
        {
            for (EnumFacing enumfacing_alt : EnumFacing.Plane.HORIZONTAL)
            {
                BlockPos blockpos_alt = pos.offset(enumfacing_alt);

                if (this.isBlockSolid(worldIn, blockpos_alt, enumfacing_alt) || this.isBlockSolid(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));
    }


    public static double getFlowDirection(IBlockAccess worldIn, BlockPos pos, Material materialIn)
    {
        Vec3 vec3 = getFlowingBlock(materialIn).getFlowVector(worldIn, pos);
        return vec3.xCoord == 0.0D && vec3.zCoord == 0.0D ? -1000.0D : MathHelper.angleFromVector(vec3.zCoord, vec3.xCoord) - (Math.PI / 2D);
    }
}