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);
}
}
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);
}
Aggregations