Java Code Examples for net.minecraft.block.material.Material.isSolid()

The following are Jave code examples for showing how to use isSolid() of the net.minecraft.block.material.Material class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Backmemed   File: BlockCactus.java   Source Code and License Vote up 5 votes
public boolean canBlockStay(World worldIn, BlockPos pos)
{
    for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
    {
        Material material = worldIn.getBlockState(pos.offset(enumfacing)).getMaterial();

        if (material.isSolid() || material == Material.LAVA)
        {
            return false;
        }
    }

    Block block = worldIn.getBlockState(pos.down()).getBlock();
    return block == Blocks.CACTUS || block == Blocks.SAND && !worldIn.getBlockState(pos.up()).getMaterial().isLiquid();
}
 
Example 2
Project: CustomWorldGen   File: BlockCactus.java   Source Code and License Vote up 5 votes
public boolean canBlockStay(World worldIn, BlockPos pos)
{
    for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
    {
        Material material = worldIn.getBlockState(pos.offset(enumfacing)).getMaterial();

        if (material.isSolid() || material == Material.LAVA)
        {
            return false;
        }
    }

    IBlockState state = worldIn.getBlockState(pos.down());
    return state.getBlock().canSustainPlant(state, worldIn, pos.down(), EnumFacing.UP, this) && !worldIn.getBlockState(pos.up()).getMaterial().isLiquid();
}
 
Example 3
Project: DecompiledMinecraft   File: ItemBucket.java   Source Code and License Vote up 4 votes
public boolean tryPlaceContainedLiquid(World worldIn, BlockPos pos)
{
    if (this.isFull == Blocks.air)
    {
        return false;
    }
    else
    {
        Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
        boolean flag = !material.isSolid();

        if (!worldIn.isAirBlock(pos) && !flag)
        {
            return false;
        }
        else
        {
            if (worldIn.provider.doesWaterVaporize() && this.isFull == Blocks.flowing_water)
            {
                int i = pos.getX();
                int j = pos.getY();
                int k = pos.getZ();
                worldIn.playSoundEffect((double)((float)i + 0.5F), (double)((float)j + 0.5F), (double)((float)k + 0.5F), "random.fizz", 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);

                for (int l = 0; l < 8; ++l)
                {
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)i + Math.random(), (double)j + Math.random(), (double)k + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
                }
            }
            else
            {
                if (!worldIn.isRemote && flag && !material.isLiquid())
                {
                    worldIn.destroyBlock(pos, true);
                }

                worldIn.setBlockState(pos, this.isFull.getDefaultState(), 3);
            }

            return true;
        }
    }
}
 
Example 4
Project: DecompiledMinecraft   File: ItemBucket.java   Source Code and License Vote up 4 votes
public boolean tryPlaceContainedLiquid(World worldIn, BlockPos pos)
{
    if (this.isFull == Blocks.air)
    {
        return false;
    }
    else
    {
        Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
        boolean flag = !material.isSolid();

        if (!worldIn.isAirBlock(pos) && !flag)
        {
            return false;
        }
        else
        {
            if (worldIn.provider.doesWaterVaporize() && this.isFull == Blocks.flowing_water)
            {
                int i = pos.getX();
                int j = pos.getY();
                int k = pos.getZ();
                worldIn.playSoundEffect((double)((float)i + 0.5F), (double)((float)j + 0.5F), (double)((float)k + 0.5F), "random.fizz", 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);

                for (int l = 0; l < 8; ++l)
                {
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)i + Math.random(), (double)j + Math.random(), (double)k + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
                }
            }
            else
            {
                if (!worldIn.isRemote && flag && !material.isLiquid())
                {
                    worldIn.destroyBlock(pos, true);
                }

                worldIn.setBlockState(pos, this.isFull.getDefaultState(), 3);
            }

            return true;
        }
    }
}
 
Example 5
Project: DecompiledMinecraft   File: EntityRainFX.java   Source Code and License Vote up 4 votes
/**
 * Called to update the entity's position/logic.
 */
public void onUpdate()
{
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.motionY -= (double)this.particleGravity;
    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    this.motionX *= 0.9800000190734863D;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= 0.9800000190734863D;

    if (this.particleMaxAge-- <= 0)
    {
        this.setDead();
    }

    if (this.onGround)
    {
        if (Math.random() < 0.5D)
        {
            this.setDead();
        }

        this.motionX *= 0.699999988079071D;
        this.motionZ *= 0.699999988079071D;
    }

    BlockPos blockpos = new BlockPos(this);
    IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
    Block block = iblockstate.getBlock();
    block.setBlockBoundsBasedOnState(this.worldObj, blockpos);
    Material material = iblockstate.getBlock().getMaterial();

    if (material.isLiquid() || material.isSolid())
    {
        double d0 = 0.0D;

        if (iblockstate.getBlock() instanceof BlockLiquid)
        {
            d0 = (double)(1.0F - BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()));
        }
        else
        {
            d0 = block.getBlockBoundsMaxY();
        }

        double d1 = (double)MathHelper.floor_double(this.posY) + d0;

        if (this.posY < d1)
        {
            this.setDead();
        }
    }
}
 
Example 6
Project: DecompiledMinecraft   File: BlockFluidRenderer.java   Source Code and License Vote up 4 votes
private float getFluidHeight(IBlockAccess blockAccess, BlockPos blockPosIn, Material blockMaterial)
{
    int i = 0;
    float f = 0.0F;

    for (int j = 0; j < 4; ++j)
    {
        BlockPos blockpos = blockPosIn.add(-(j & 1), 0, -(j >> 1 & 1));

        if (blockAccess.getBlockState(blockpos.up()).getBlock().getMaterial() == blockMaterial)
        {
            return 1.0F;
        }

        IBlockState iblockstate = blockAccess.getBlockState(blockpos);
        Material material = iblockstate.getBlock().getMaterial();

        if (material != blockMaterial)
        {
            if (!material.isSolid())
            {
                ++f;
                ++i;
            }
        }
        else
        {
            int k = ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue();

            if (k >= 8 || k == 0)
            {
                f += BlockLiquid.getLiquidHeightPercent(k) * 10.0F;
                i += 10;
            }

            f += BlockLiquid.getLiquidHeightPercent(k);
            ++i;
        }
    }

    return 1.0F - f / (float)i;
}
 
Example 7
Project: BaseClient   File: ItemBucket.java   Source Code and License Vote up 4 votes
public boolean tryPlaceContainedLiquid(World worldIn, BlockPos pos)
{
    if (this.isFull == Blocks.air)
    {
        return false;
    }
    else
    {
        Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
        boolean flag = !material.isSolid();

        if (!worldIn.isAirBlock(pos) && !flag)
        {
            return false;
        }
        else
        {
            if (worldIn.provider.doesWaterVaporize() && this.isFull == Blocks.flowing_water)
            {
                int i = pos.getX();
                int j = pos.getY();
                int k = pos.getZ();
                worldIn.playSoundEffect((double)((float)i + 0.5F), (double)((float)j + 0.5F), (double)((float)k + 0.5F), "random.fizz", 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);

                for (int l = 0; l < 8; ++l)
                {
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)i + Math.random(), (double)j + Math.random(), (double)k + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
                }
            }
            else
            {
                if (!worldIn.isRemote && flag && !material.isLiquid())
                {
                    worldIn.destroyBlock(pos, true);
                }

                worldIn.setBlockState(pos, this.isFull.getDefaultState(), 3);
            }

            return true;
        }
    }
}
 
Example 8
Project: BaseClient   File: EntityRainFX.java   Source Code and License Vote up 4 votes
/**
 * Called to update the entity's position/logic.
 */
public void onUpdate()
{
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.motionY -= (double)this.particleGravity;
    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    this.motionX *= 0.9800000190734863D;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= 0.9800000190734863D;

    if (this.particleMaxAge-- <= 0)
    {
        this.setDead();
    }

    if (this.onGround)
    {
        if (Math.random() < 0.5D)
        {
            this.setDead();
        }

        this.motionX *= 0.699999988079071D;
        this.motionZ *= 0.699999988079071D;
    }

    BlockPos blockpos = new BlockPos(this);
    IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
    Block block = iblockstate.getBlock();
    block.setBlockBoundsBasedOnState(this.worldObj, blockpos);
    Material material = iblockstate.getBlock().getMaterial();

    if (material.isLiquid() || material.isSolid())
    {
        double d0 = 0.0D;

        if (iblockstate.getBlock() instanceof BlockLiquid)
        {
            d0 = (double)(1.0F - BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()));
        }
        else
        {
            d0 = block.getBlockBoundsMaxY();
        }

        double d1 = (double)MathHelper.floor_double(this.posY) + d0;

        if (this.posY < d1)
        {
            this.setDead();
        }
    }
}
 
Example 9
Project: BaseClient   File: BlockFluidRenderer.java   Source Code and License Vote up 4 votes
private float getFluidHeight(IBlockAccess blockAccess, BlockPos blockPosIn, Material blockMaterial)
{
    int i = 0;
    float f = 0.0F;

    for (int j = 0; j < 4; ++j)
    {
        BlockPos blockpos = blockPosIn.add(-(j & 1), 0, -(j >> 1 & 1));

        if (blockAccess.getBlockState(blockpos.up()).getBlock().getMaterial() == blockMaterial)
        {
            return 1.0F;
        }

        IBlockState iblockstate = blockAccess.getBlockState(blockpos);
        Material material = iblockstate.getBlock().getMaterial();

        if (material != blockMaterial)
        {
            if (!material.isSolid())
            {
                ++f;
                ++i;
            }
        }
        else
        {
            int k = ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue();

            if (k >= 8 || k == 0)
            {
                f += BlockLiquid.getLiquidHeightPercent(k) * 10.0F;
                i += 10;
            }

            f += BlockLiquid.getLiquidHeightPercent(k);
            ++i;
        }
    }

    return 1.0F - f / (float)i;
}
 
Example 10
Project: BaseClient   File: ItemBucket.java   Source Code and License Vote up 4 votes
public boolean tryPlaceContainedLiquid(World worldIn, BlockPos pos)
{
    if (this.isFull == Blocks.air)
    {
        return false;
    }
    else
    {
        Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
        boolean flag = !material.isSolid();

        if (!worldIn.isAirBlock(pos) && !flag)
        {
            return false;
        }
        else
        {
            if (worldIn.provider.doesWaterVaporize() && this.isFull == Blocks.flowing_water)
            {
                int i = pos.getX();
                int j = pos.getY();
                int k = pos.getZ();
                worldIn.playSoundEffect((double)((float)i + 0.5F), (double)((float)j + 0.5F), (double)((float)k + 0.5F), "random.fizz", 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);

                for (int l = 0; l < 8; ++l)
                {
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)i + Math.random(), (double)j + Math.random(), (double)k + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
                }
            }
            else
            {
                if (!worldIn.isRemote && flag && !material.isLiquid())
                {
                    worldIn.destroyBlock(pos, true);
                }

                worldIn.setBlockState(pos, this.isFull.getDefaultState(), 3);
            }

            return true;
        }
    }
}
 
Example 11
Project: BaseClient   File: EntityRainFX.java   Source Code and License Vote up 4 votes
/**
 * Called to update the entity's position/logic.
 */
public void onUpdate()
{
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.motionY -= (double)this.particleGravity;
    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    this.motionX *= 0.9800000190734863D;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= 0.9800000190734863D;

    if (this.particleMaxAge-- <= 0)
    {
        this.setDead();
    }

    if (this.onGround)
    {
        if (Math.random() < 0.5D)
        {
            this.setDead();
        }

        this.motionX *= 0.699999988079071D;
        this.motionZ *= 0.699999988079071D;
    }

    BlockPos blockpos = new BlockPos(this);
    IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
    Block block = iblockstate.getBlock();
    block.setBlockBoundsBasedOnState(this.worldObj, blockpos);
    Material material = iblockstate.getBlock().getMaterial();

    if (material.isLiquid() || material.isSolid())
    {
        double d0 = 0.0D;

        if (iblockstate.getBlock() instanceof BlockLiquid)
        {
            d0 = (double)(1.0F - BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()));
        }
        else
        {
            d0 = block.getBlockBoundsMaxY();
        }

        double d1 = (double)MathHelper.floor_double(this.posY) + d0;

        if (this.posY < d1)
        {
            this.setDead();
        }
    }
}
 
Example 12
Project: CustomWorldGen   File: ParticleRain.java   Source Code and License Vote up 4 votes
public void onUpdate()
{
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.motionY -= (double)this.particleGravity;
    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    this.motionX *= 0.9800000190734863D;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= 0.9800000190734863D;

    if (this.particleMaxAge-- <= 0)
    {
        this.setExpired();
    }

    if (this.isCollided)
    {
        if (Math.random() < 0.5D)
        {
            this.setExpired();
        }

        this.motionX *= 0.699999988079071D;
        this.motionZ *= 0.699999988079071D;
    }

    BlockPos blockpos = new BlockPos(this.posX, this.posY, this.posZ);
    IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
    Material material = iblockstate.getMaterial();

    if (material.isLiquid() || material.isSolid())
    {
        double d0;

        if (iblockstate.getBlock() instanceof BlockLiquid)
        {
            d0 = (double)(1.0F - BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()));
        }
        else
        {
            d0 = iblockstate.getBoundingBox(this.worldObj, blockpos).maxY;
        }

        double d1 = (double)MathHelper.floor_double(this.posY) + d0;

        if (this.posY < d1)
        {
            this.setExpired();
        }
    }
}
 
Example 13
Project: Zombe-Modpack   File: ZWrapper.java   Source Code and License Vote up 4 votes
public static boolean getIsSolid(Material mat) {
    return mat.isSolid();
}
 
Example 14
Project: Backmemed   File: ItemBucket.java   Source Code and License Vote up 4 votes
public boolean tryPlaceContainedLiquid(@Nullable EntityPlayer player, World worldIn, BlockPos posIn)
{
    if (this.containedBlock == Blocks.AIR)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(posIn);
        Material material = iblockstate.getMaterial();
        boolean flag = !material.isSolid();
        boolean flag1 = iblockstate.getBlock().isReplaceable(worldIn, posIn);

        if (!worldIn.isAirBlock(posIn) && !flag && !flag1)
        {
            return false;
        }
        else
        {
            if (worldIn.provider.doesWaterVaporize() && this.containedBlock == Blocks.FLOWING_WATER)
            {
                int l = posIn.getX();
                int i = posIn.getY();
                int j = posIn.getZ();
                worldIn.playSound(player, posIn, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);

                for (int k = 0; k < 8; ++k)
                {
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)l + Math.random(), (double)i + Math.random(), (double)j + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
                }
            }
            else
            {
                if (!worldIn.isRemote && (flag || flag1) && !material.isLiquid())
                {
                    worldIn.destroyBlock(posIn, true);
                }

                SoundEvent soundevent = this.containedBlock == Blocks.FLOWING_LAVA ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY;
                worldIn.playSound(player, posIn, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
                worldIn.setBlockState(posIn, this.containedBlock.getDefaultState(), 11);
            }

            return true;
        }
    }
}
 
Example 15
Project: Backmemed   File: ParticleDrip.java   Source Code and License Vote up 4 votes
public void onUpdate()
{
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;

    if (this.materialType == Material.WATER)
    {
        this.particleRed = 0.2F;
        this.particleGreen = 0.3F;
        this.particleBlue = 1.0F;
    }
    else
    {
        this.particleRed = 1.0F;
        this.particleGreen = 16.0F / (float)(40 - this.bobTimer + 16);
        this.particleBlue = 4.0F / (float)(40 - this.bobTimer + 8);
    }

    this.motionY -= (double)this.particleGravity;

    if (this.bobTimer-- > 0)
    {
        this.motionX *= 0.02D;
        this.motionY *= 0.02D;
        this.motionZ *= 0.02D;
        this.setParticleTextureIndex(113);
    }
    else
    {
        this.setParticleTextureIndex(112);
    }

    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    this.motionX *= 0.9800000190734863D;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= 0.9800000190734863D;

    if (this.particleMaxAge-- <= 0)
    {
        this.setExpired();
    }

    if (this.isCollided)
    {
        if (this.materialType == Material.WATER)
        {
            this.setExpired();
            this.worldObj.spawnParticle(EnumParticleTypes.WATER_SPLASH, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
        }
        else
        {
            this.setParticleTextureIndex(114);
        }

        this.motionX *= 0.699999988079071D;
        this.motionZ *= 0.699999988079071D;
    }

    BlockPos blockpos = new BlockPos(this.posX, this.posY, this.posZ);
    IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
    Material material = iblockstate.getMaterial();

    if (material.isLiquid() || material.isSolid())
    {
        double d0 = 0.0D;

        if (iblockstate.getBlock() instanceof BlockLiquid)
        {
            d0 = (double)BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue());
        }

        double d1 = (double)(MathHelper.floor(this.posY) + 1) - d0;

        if (this.posY < d1)
        {
            this.setExpired();
        }
    }
}
 
Example 16
Project: Backmemed   File: ParticleRain.java   Source Code and License Vote up 4 votes
public void onUpdate()
{
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.motionY -= (double)this.particleGravity;
    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    this.motionX *= 0.9800000190734863D;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= 0.9800000190734863D;

    if (this.particleMaxAge-- <= 0)
    {
        this.setExpired();
    }

    if (this.isCollided)
    {
        if (Math.random() < 0.5D)
        {
            this.setExpired();
        }

        this.motionX *= 0.699999988079071D;
        this.motionZ *= 0.699999988079071D;
    }

    BlockPos blockpos = new BlockPos(this.posX, this.posY, this.posZ);
    IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
    Material material = iblockstate.getMaterial();

    if (material.isLiquid() || material.isSolid())
    {
        double d0;

        if (iblockstate.getBlock() instanceof BlockLiquid)
        {
            d0 = (double)(1.0F - BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()));
        }
        else
        {
            d0 = iblockstate.getBoundingBox(this.worldObj, blockpos).maxY;
        }

        double d1 = (double)MathHelper.floor(this.posY) + d0;

        if (this.posY < d1)
        {
            this.setExpired();
        }
    }
}
 
Example 17
Project: CustomWorldGen   File: BlockFluidRenderer.java   Source Code and License Vote up 4 votes
private float getFluidHeight(IBlockAccess blockAccess, BlockPos blockPosIn, Material blockMaterial)
{
    int i = 0;
    float f = 0.0F;

    for (int j = 0; j < 4; ++j)
    {
        BlockPos blockpos = blockPosIn.add(-(j & 1), 0, -(j >> 1 & 1));

        if (blockAccess.getBlockState(blockpos.up()).getMaterial() == blockMaterial)
        {
            return 1.0F;
        }

        IBlockState iblockstate = blockAccess.getBlockState(blockpos);
        Material material = iblockstate.getMaterial();

        if (material != blockMaterial)
        {
            if (!material.isSolid())
            {
                ++f;
                ++i;
            }
        }
        else
        {
            int k = ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue();

            if (k >= 8 || k == 0)
            {
                f += BlockLiquid.getLiquidHeightPercent(k) * 10.0F;
                i += 10;
            }

            f += BlockLiquid.getLiquidHeightPercent(k);
            ++i;
        }
    }

    return 1.0F - f / (float)i;
}
 
Example 18
Project: CustomWorldGen   File: FluidUtil.java   Source Code and License Vote up 4 votes
/**
 * Tries to place a fluid in the world in block form.
 * Makes a fluid emptying sound when successful.
 * Checks if water-like fluids should vaporize like in the nether.
 *
 * Modeled after {@link net.minecraft.item.ItemBucket#tryPlaceContainedLiquid(EntityPlayer, World, BlockPos)}
 *
 * @param player     Player who places the fluid. May be null for blocks like dispensers.
 * @param worldIn    World to place the fluid in
 * @param fluidStack The fluidStack to place.
 * @param pos        The position in the world to place the fluid block
 * @return true if successful
 */
public static boolean tryPlaceFluid(@Nullable EntityPlayer player, World worldIn, FluidStack fluidStack, BlockPos pos)
{
    if (worldIn == null || fluidStack == null || pos == null)
    {
        return false;
    }

    Fluid fluid = fluidStack.getFluid();
    if (fluid == null || !fluid.canBePlacedInWorld())
    {
        return false;
    }

    // check that we can place the fluid at the destination
    IBlockState destBlockState = worldIn.getBlockState(pos);
    Material destMaterial = destBlockState.getMaterial();
    boolean isDestNonSolid = !destMaterial.isSolid();
    boolean isDestReplaceable = destBlockState.getBlock().isReplaceable(worldIn, pos);
    if (!worldIn.isAirBlock(pos) && !isDestNonSolid && !isDestReplaceable)
    {
        return false; // Non-air, solid, unreplacable block. We can't put fluid here.
    }

    if (worldIn.provider.doesWaterVaporize() && fluid.doesVaporize(fluidStack))
    {
        fluid.vaporize(player, worldIn, pos, fluidStack);
    }
    else
    {
        if (!worldIn.isRemote && (isDestNonSolid || isDestReplaceable) && !destMaterial.isLiquid())
        {
            worldIn.destroyBlock(pos, true);
        }

        SoundEvent soundevent = fluid.getEmptySound(fluidStack);
        worldIn.playSound(player, pos, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);

        IBlockState fluidBlockState = fluid.getBlock().getDefaultState();
        worldIn.setBlockState(pos, fluidBlockState, 11);
    }
    return true;
}
 
Example 19
Project: CustomWorldGen   File: ItemBucket.java   Source Code and License Vote up 4 votes
public boolean tryPlaceContainedLiquid(@Nullable EntityPlayer player, World worldIn, BlockPos posIn)
{
    if (this.containedBlock == Blocks.AIR)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(posIn);
        Material material = iblockstate.getMaterial();
        boolean flag = !material.isSolid();
        boolean flag1 = iblockstate.getBlock().isReplaceable(worldIn, posIn);

        if (!worldIn.isAirBlock(posIn) && !flag && !flag1)
        {
            return false;
        }
        else
        {
            if (worldIn.provider.doesWaterVaporize() && this.containedBlock == Blocks.FLOWING_WATER)
            {
                int l = posIn.getX();
                int i = posIn.getY();
                int j = posIn.getZ();
                worldIn.playSound(player, posIn, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);

                for (int k = 0; k < 8; ++k)
                {
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)l + Math.random(), (double)i + Math.random(), (double)j + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
                }
            }
            else
            {
                if (!worldIn.isRemote && (flag || flag1) && !material.isLiquid())
                {
                    worldIn.destroyBlock(posIn, true);
                }

                SoundEvent soundevent = this.containedBlock == Blocks.FLOWING_LAVA ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY;
                worldIn.playSound(player, posIn, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
                worldIn.setBlockState(posIn, this.containedBlock.getDefaultState(), 11);
            }

            return true;
        }
    }
}
 
Example 20
Project: CustomWorldGen   File: ParticleDrip.java   Source Code and License Vote up 4 votes
public void onUpdate()
{
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;

    if (this.materialType == Material.WATER)
    {
        this.particleRed = 0.2F;
        this.particleGreen = 0.3F;
        this.particleBlue = 1.0F;
    }
    else
    {
        this.particleRed = 1.0F;
        this.particleGreen = 16.0F / (float)(40 - this.bobTimer + 16);
        this.particleBlue = 4.0F / (float)(40 - this.bobTimer + 8);
    }

    this.motionY -= (double)this.particleGravity;

    if (this.bobTimer-- > 0)
    {
        this.motionX *= 0.02D;
        this.motionY *= 0.02D;
        this.motionZ *= 0.02D;
        this.setParticleTextureIndex(113);
    }
    else
    {
        this.setParticleTextureIndex(112);
    }

    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    this.motionX *= 0.9800000190734863D;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= 0.9800000190734863D;

    if (this.particleMaxAge-- <= 0)
    {
        this.setExpired();
    }

    if (this.isCollided)
    {
        if (this.materialType == Material.WATER)
        {
            this.setExpired();
            this.worldObj.spawnParticle(EnumParticleTypes.WATER_SPLASH, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
        }
        else
        {
            this.setParticleTextureIndex(114);
        }

        this.motionX *= 0.699999988079071D;
        this.motionZ *= 0.699999988079071D;
    }

    BlockPos blockpos = new BlockPos(this.posX, this.posY, this.posZ);
    IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
    Material material = iblockstate.getMaterial();

    if (material.isLiquid() || material.isSolid())
    {
        double d0 = 0.0D;

        if (iblockstate.getBlock() instanceof BlockLiquid)
        {
            d0 = (double)BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue());
        }

        double d1 = (double)(MathHelper.floor_double(this.posY) + 1) - d0;

        if (this.posY < d1)
        {
            this.setExpired();
        }
    }
}