Search in sources :

Example 1 with FluidFillable

use of net.minecraft.block.FluidFillable in project Paradise-Lost by devs-immortal.

the class SkyrootBucket method placeLiquid.

public boolean placeLiquid(PlayerEntity playerIn, World worldIn, BlockPos posIn, BlockHitResult hitResult) {
    if (!(this.containedBlock instanceof FlowableFluid)) {
        return false;
    } else {
        BlockState stateIn = worldIn.getBlockState(posIn);
        Material material = stateIn.getMaterial();
        boolean flag = !material.isSolid();
        boolean flag1 = material.isReplaceable();
        if (worldIn.isAir(posIn) || flag || flag1 || stateIn.getBlock() instanceof FluidFillable && ((FluidFillable) stateIn.getBlock()).canFillWithFluid(worldIn, posIn, stateIn, this.containedBlock)) {
            if (worldIn.getRegistryKey().equals(World.NETHER)) {
                int i = posIn.getX();
                int j = posIn.getY();
                int k = posIn.getZ();
                worldIn.playSound(playerIn, posIn, SoundEvents.BLOCK_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);
                }
            } else if (stateIn.getBlock() instanceof FluidFillable) {
                if (((FluidFillable) stateIn.getBlock()).tryFillWithFluid(worldIn, posIn, stateIn, ((FlowableFluid) this.containedBlock).getStill(false))) {
                    this.playEmptySound(playerIn, worldIn, posIn);
                }
            } else {
                if (!worldIn.isClient && (flag || flag1) && !material.isLiquid()) {
                    worldIn.breakBlock(posIn, true);
                }
                this.playEmptySound(playerIn, worldIn, posIn);
                worldIn.setBlockState(posIn, this.containedBlock.getDefaultState().getBlockState(), 11);
            }
            return true;
        } else {
            return hitResult != null && this.placeLiquid(playerIn, worldIn, hitResult.getBlockPos().offset(hitResult.getSide()), null);
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) FluidFillable(net.minecraft.block.FluidFillable) FlowableFluid(net.minecraft.fluid.FlowableFluid) Material(net.minecraft.block.Material)

Example 2 with FluidFillable

use of net.minecraft.block.FluidFillable in project Paradise-Lost by devs-immortal.

the class SkyrootBucket method use.

@Override
public TypedActionResult<ItemStack> use(World worldIn, PlayerEntity playerIn, Hand handIn) {
    ItemStack currentStack = playerIn.getStackInHand(handIn);
    BlockHitResult hitResult = raycast(worldIn, playerIn, this.containedBlock == Fluids.EMPTY ? RaycastContext.FluidHandling.SOURCE_ONLY : RaycastContext.FluidHandling.NONE);
    if (currentStack.getItem() != AetherItems.SKYROOT_WATER_BUCKET && currentStack.getItem() != AetherItems.SKYROOT_BUCKET) {
        playerIn.setCurrentHand(handIn);
        return new TypedActionResult<>(ActionResult.PASS, currentStack);
    }
    if (hitResult == null) {
        return new TypedActionResult<>(ActionResult.PASS, currentStack);
    } else if (hitResult.getType() == HitResult.Type.BLOCK) {
        BlockPos hitPos = hitResult.getBlockPos();
        if (worldIn.canPlayerModifyAt(playerIn, hitPos) && playerIn.canPlaceOn(hitPos, hitResult.getSide(), currentStack)) {
            if (this.containedBlock == Fluids.EMPTY) {
                BlockState hitState = worldIn.getBlockState(hitPos);
                if (hitState.getBlock() instanceof FluidDrainable) {
                    Fluid fluid = (hitState.getFluidState().getFluid());
                    if (fluid == Fluids.WATER) {
                        ((FluidDrainable) hitState.getBlock()).tryDrainFluid(worldIn, hitPos, hitState);
                        playerIn.incrementStat(Stats.USED.getOrCreateStat(this));
                        playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
                        ItemStack fillStack = this.fillBucket(currentStack, playerIn, AetherItems.SKYROOT_WATER_BUCKET);
                        return new TypedActionResult<>(ActionResult.SUCCESS, fillStack);
                    }
                }
                return new TypedActionResult<>(ActionResult.FAIL, currentStack);
            } else {
                BlockState hitBlockState = worldIn.getBlockState(hitPos);
                BlockPos adjustedPos = hitBlockState.getBlock() instanceof FluidFillable ? hitPos : hitResult.getBlockPos().offset(hitResult.getSide());
                this.placeLiquid(playerIn, worldIn, adjustedPos, hitResult);
                playerIn.incrementStat(Stats.USED.getOrCreateStat(this));
                return new TypedActionResult<>(ActionResult.SUCCESS, this.emptyBucket(currentStack, playerIn));
            }
        } else {
            return new TypedActionResult<>(ActionResult.FAIL, currentStack);
        }
    } else {
        return new TypedActionResult<>(ActionResult.PASS, currentStack);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) FluidFillable(net.minecraft.block.FluidFillable) FlowableFluid(net.minecraft.fluid.FlowableFluid) Fluid(net.minecraft.fluid.Fluid) BlockPos(net.minecraft.util.math.BlockPos) FluidDrainable(net.minecraft.block.FluidDrainable) ItemStack(net.minecraft.item.ItemStack) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Aggregations

BlockState (net.minecraft.block.BlockState)2 FluidFillable (net.minecraft.block.FluidFillable)2 FlowableFluid (net.minecraft.fluid.FlowableFluid)2 FluidDrainable (net.minecraft.block.FluidDrainable)1 Material (net.minecraft.block.Material)1 Fluid (net.minecraft.fluid.Fluid)1 ItemStack (net.minecraft.item.ItemStack)1 BlockHitResult (net.minecraft.util.hit.BlockHitResult)1 BlockPos (net.minecraft.util.math.BlockPos)1