@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
RayTraceResult rtr = rayTrace(world, player, true);
ItemStack stack = player.getHeldItem(hand);
if(rtr == null)
return ActionResult.newResult(EnumActionResult.PASS, stack);
else {
if(rtr.typeOfHit == net.minecraft.util.math.RayTraceResult.Type.BLOCK) {
BlockPos pos = rtr.getBlockPos();
if(!world.isBlockModifiable(player, pos))
return ActionResult.newResult(EnumActionResult.PASS, stack);
if(!player.canPlayerEdit(pos, rtr.sideHit, stack))
return ActionResult.newResult(EnumActionResult.PASS, stack);
IBlockState state = world.getBlockState(pos);
Fluid fluid = FluidRegistry.lookupFluidForBlock(state.getBlock());
boolean isFull = state.getBlock() instanceof BlockLiquid && state.getValue(BlockLiquid.LEVEL) == 0
|| state.getBlock() instanceof IFluidBlock && Math.abs(((IFluidBlock) state.getBlock()).getFilledPercentage(world, pos)) >= 1;
if(fluid != null && isFull) {
player.playSound(fluid.getFillSound(world, pos), 1.0f, 1.0f);
world.setBlockToAir(pos);
for(int x = 0; x < 5; x++)
world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), 0, 0, 0);
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
}
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
}