Search in sources :

Example 6 with ILiquidContainer

use of net.minecraft.block.ILiquidContainer in project MCMOD-Industria by M-Marvin.

the class ItemFluidCannister method emptyBucket.

/**
 * Modified vanilla bucket behavior
 */
@SuppressWarnings("deprecation")
public boolean emptyBucket(@Nullable PlayerEntity player, World world, BlockPos pos, @Nullable BlockRayTraceResult raytraceResult, Fluid content) {
    BlockState blockstate = world.getBlockState(pos);
    Block block = blockstate.getBlock();
    Material material = blockstate.getMaterial();
    boolean flag = blockstate.canBeReplaced(content);
    boolean flag1 = blockstate.isAir() || flag || block instanceof ILiquidContainer && ((ILiquidContainer) block).canPlaceLiquid(world, pos, blockstate, content);
    if (!flag1) {
        return raytraceResult != null && this.emptyBucket(player, world, raytraceResult.getBlockPos().relative(raytraceResult.getDirection()), (BlockRayTraceResult) null, content);
    } else if (world.dimensionType().ultraWarm() && !canPlaceInNether(content)) {
        int i = pos.getX();
        int j = pos.getY();
        int k = pos.getZ();
        world.playSound(player, pos, SoundEvents.FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
        for (int l = 0; l < 8; ++l) {
            world.addParticle(ParticleTypes.LARGE_SMOKE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
        }
        return true;
    } else if (block instanceof ILiquidContainer && ((ILiquidContainer) block).canPlaceLiquid(world, pos, blockstate, content)) {
        ((ILiquidContainer) block).placeLiquid(world, pos, blockstate, ((FlowingFluid) content).getSource(false));
        return true;
    } else {
        if (!world.isClientSide && flag && !material.isLiquid()) {
            world.destroyBlock(pos, true);
        }
        if (!world.setBlock(pos, content.defaultFluidState().createLegacyBlock(), 11) && !blockstate.getFluidState().isSource()) {
            return false;
        } else {
            return true;
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) ILiquidContainer(net.minecraft.block.ILiquidContainer) Block(net.minecraft.block.Block) Material(net.minecraft.block.material.Material) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult)

Example 7 with ILiquidContainer

use of net.minecraft.block.ILiquidContainer in project MCMOD-Industria by M-Marvin.

the class ItemFluidBucket method emptyBucket.

@SuppressWarnings("deprecation")
public boolean emptyBucket(@Nullable PlayerEntity player, World worldIn, BlockPos posIn, @Nullable BlockRayTraceResult rayTrace) {
    if (!(getFluid() instanceof FlowingFluid)) {
        return false;
    } else {
        BlockState blockstate = worldIn.getBlockState(posIn);
        Block block = blockstate.getBlock();
        Material material = blockstate.getMaterial();
        boolean flag = blockstate.canBeReplaced(getFluid());
        boolean flag1 = blockstate.isAir() || flag || block instanceof ILiquidContainer && ((ILiquidContainer) block).canPlaceLiquid(worldIn, posIn, blockstate, getFluid());
        if (!flag1) {
            return rayTrace != null && this.emptyBucket(player, worldIn, rayTrace.getBlockPos().relative(rayTrace.getDirection()), (BlockRayTraceResult) null);
        } else if (!canPlaceInNether && worldIn.dimensionType().ultraWarm()) {
            int i = posIn.getX();
            int j = posIn.getY();
            int k = posIn.getZ();
            worldIn.playSound(player, posIn, SoundEvents.FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.random.nextFloat() - worldIn.random.nextFloat()) * 0.8F);
            for (int l = 0; l < 8; ++l) {
                worldIn.addParticle(ParticleTypes.LARGE_SMOKE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
            }
            return true;
        } else if (block instanceof ILiquidContainer && ((ILiquidContainer) block).canPlaceLiquid(worldIn, posIn, blockstate, getFluid())) {
            ((ILiquidContainer) block).placeLiquid(worldIn, posIn, blockstate, ((FlowingFluid) getFluid()).getSource(false));
            this.playEmptySound(player, worldIn, posIn);
            return true;
        } else {
            if (!worldIn.isClientSide && flag && !material.isLiquid()) {
                worldIn.destroyBlock(posIn, true);
            }
            if (!worldIn.setBlock(posIn, getFluid().defaultFluidState().createLegacyBlock(), 11) && !blockstate.getFluidState().isSource()) {
                return false;
            } else {
                this.playEmptySound(player, worldIn, posIn);
                return true;
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) ILiquidContainer(net.minecraft.block.ILiquidContainer) FlowingFluid(net.minecraft.fluid.FlowingFluid) Block(net.minecraft.block.Block) Material(net.minecraft.block.material.Material) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult)

Example 8 with ILiquidContainer

use of net.minecraft.block.ILiquidContainer in project MCMOD-Industria by M-Marvin.

the class ItemGasBucket method emptyBucket.

@SuppressWarnings("deprecation")
public boolean emptyBucket(@Nullable PlayerEntity player, World worldIn, BlockPos posIn, @Nullable BlockRayTraceResult p_180616_4_) {
    BlockState blockstate = worldIn.getBlockState(posIn);
    Block block = blockstate.getBlock();
    Material material = blockstate.getMaterial();
    boolean flag = blockstate.canBeReplaced(this.getFluid());
    boolean flag1 = blockstate.isAir() || flag || block instanceof ILiquidContainer && ((ILiquidContainer) block).canPlaceLiquid(worldIn, posIn, blockstate, this.getFluid());
    if (!flag1) {
        return p_180616_4_ != null && this.emptyBucket(player, worldIn, p_180616_4_.getBlockPos().relative(p_180616_4_.getDirection()), (BlockRayTraceResult) null);
    } else if (worldIn.dimensionType().ultraWarm() && this.getFluid().is(FluidTags.WATER)) {
        int i = posIn.getX();
        int j = posIn.getY();
        int k = posIn.getZ();
        worldIn.playSound(player, posIn, SoundEvents.FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.random.nextFloat() - worldIn.random.nextFloat()) * 0.8F);
        for (int l = 0; l < 8; ++l) {
            worldIn.addParticle(ParticleTypes.LARGE_SMOKE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
        }
        return true;
    } else if (block instanceof ILiquidContainer && ((ILiquidContainer) block).canPlaceLiquid(worldIn, posIn, blockstate, getFluid())) {
        ((ILiquidContainer) block).placeLiquid(worldIn, posIn, blockstate, ((FlowingFluid) this.getFluid()).getSource(false));
        this.playEmptySound(player, worldIn, posIn);
        return true;
    } else {
        if (!worldIn.isClientSide && flag && !material.isLiquid()) {
            worldIn.destroyBlock(posIn, true);
        }
        if (!worldIn.setBlock(posIn, this.getFluid().defaultFluidState().createLegacyBlock(), 11) && !blockstate.getFluidState().isSource()) {
            return false;
        } else {
            this.playEmptySound(player, worldIn, posIn);
            return true;
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) ILiquidContainer(net.minecraft.block.ILiquidContainer) Block(net.minecraft.block.Block) Material(net.minecraft.block.material.Material) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult)

Aggregations

BlockState (net.minecraft.block.BlockState)8 ILiquidContainer (net.minecraft.block.ILiquidContainer)8 Block (net.minecraft.block.Block)5 Fluid (net.minecraft.fluid.Fluid)5 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)5 FlowingFluid (net.minecraft.fluid.FlowingFluid)4 Material (net.minecraft.block.material.Material)3 CauldronBlock (net.minecraft.block.CauldronBlock)2 IBucketPickupHandler (net.minecraft.block.IBucketPickupHandler)2 ItemStack (net.minecraft.item.ItemStack)2 Direction (net.minecraft.util.Direction)2 SoundEvent (net.minecraft.util.SoundEvent)2 BlockPos (net.minecraft.util.math.BlockPos)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 FluidState (net.minecraft.fluid.FluidState)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1