BlockLiquid

    From Minecraft Parkour Wiki

    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;
        }
    
        
        /* Only called from getFlowVector with N,E,S,W
        public boolean isBlockSolid(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
        {
            Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
            
            if (material == this.blockMaterial || material == Material.ice)
                return false;
                
            else
                return super.isBlockSolid(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);
    
                    //adjacent solid blocks make it harder to move up the stream.
                    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));
        }
    }