BlockLiquid: Difference between revisions

From Minecraft Parkour Wiki
Content added Content deleted
(created page, but a lot of understanding is needed still)
 
mNo edit summary
Line 62: Line 62:
int adjFlowDecay = this.getEffectiveFlowDecay(worldIn, blockpos);
int adjFlowDecay = this.getEffectiveFlowDecay(worldIn, blockpos);
int delta = adjFlowDecay - flowDecay;
int delta = adjFlowDecay - flowDecay;
flow = flow.addVector( (blockpos.getX()-pos.getX())*delta, (blockpos.getY()-pos.getY())*delta, (blockpos.getZ()-pos.getZ())*delta);
double dX = (double) ((blockpos.getX()-pos.getX())*delta);
double dY = (double) ((blockpos.getY()-pos.getY())*delta);
double dZ = (double) ((blockpos.getZ()-pos.getZ())*delta);
flow = flow.addVector(dX, dY, dZ);
}
}


//TODO: what does this do?
//seems to add downward current?
if (((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() >= 8)
if (((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() >= 8)
{
{
Line 79: Line 82:
}
}
}
}

return flow.normalize();
return flow.normalize();
}
}
Line 87: Line 90:
{
{
return motion.add(this.getFlowVector(worldIn, pos));
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);
}
}
}
}

Revision as of 22:45, 2 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);

    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;
            double dX = (double) ((blockpos.getX()-pos.getX())*delta);
            double dY = (double) ((blockpos.getY()-pos.getY())*delta);
            double dZ = (double) ((blockpos.getZ()-pos.getZ())*delta);
            flow = flow.addVector(dX, dY, dZ);
        }

        //seems to add downward current?
        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));
    }
}