Search in sources :

Example 1 with FluidDrainable

use of net.minecraft.block.FluidDrainable 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)

Example 2 with FluidDrainable

use of net.minecraft.block.FluidDrainable in project bewitchment by MoriyaShiine.

the class DrainWaterRitualFunction method start.

@Override
public void start(ServerWorld world, BlockPos glyphPos, BlockPos effectivePos, Inventory inventory, boolean catFamiliar) {
    for (BlockPos foundPos : BWUtil.getBlockPoses(effectivePos, catFamiliar ? 24 : 8, currentPos -> world.getFluidState(currentPos).getFluid().isIn(FluidTags.WATER) && world.getBlockState(currentPos).getBlock() instanceof FluidDrainable && world.getWorldBorder().contains(currentPos))) {
        BlockState state = world.getBlockState(foundPos);
        ((FluidDrainable) state.getBlock()).tryDrainFluid(world, foundPos, state);
    }
    super.start(world, glyphPos, effectivePos, inventory, catFamiliar);
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) FluidDrainable(net.minecraft.block.FluidDrainable)

Aggregations

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