Advertisement
Scouter456

Untitled

Nov 13th, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. @SubscribeEvent
  2.     public static void checkForWater(PlayerInteractEvent.RightClickItem event) {
  3.         if(event.getEntity() == null){
  4.             return;
  5.         }
  6.         Player player = event.getEntity();
  7.         HitResult hitresult = getPlayerPOVHitResult(event.getLevel(), event.getEntity(), ClipContext.Fluid.SOURCE_ONLY);
  8.         if(hitresult.getType() == HitResult.Type.MISS){
  9.             return;
  10.         }
  11.         if(hitresult.getType() == HitResult.Type.BLOCK) {
  12.             BlockPos blockpos = ((BlockHitResult)hitresult).getBlockPos();
  13.             if (!event.getLevel().getFluidState(blockpos).is(WATER)) {
  14.                 return;
  15.             }
  16.             ItemStack itemInHand = player.getItemInHand(event.getHand());
  17.             if (itemInHand.is(Items.GLASS_BOTTLE)) {
  18.                 event.setCanceled(true);
  19.                
  20.        
  21.                 player.level.gameEvent(player, GameEvent.FLUID_PICKUP, blockpos);
  22.                 if (!player.isCreative()) {
  23.                     itemInHand.shrink(1);
  24.                 }
  25.                 return;
  26.             }
  27.  
  28.  
  29.         }
  30.     }
  31.  
  32.     //Vanilla copy
  33.     protected static BlockHitResult getPlayerPOVHitResult(Level pLevel, Player pPlayer, ClipContext.Fluid pFluidMode) {
  34.         float f = pPlayer.getXRot();
  35.         float f1 = pPlayer.getYRot();
  36.         Vec3 vec3 = pPlayer.getEyePosition();
  37.         float f2 = Mth.cos(-f1 * ((float)Math.PI / 180F) - (float)Math.PI);
  38.         float f3 = Mth.sin(-f1 * ((float)Math.PI / 180F) - (float)Math.PI);
  39.         float f4 = -Mth.cos(-f * ((float)Math.PI / 180F));
  40.         float f5 = Mth.sin(-f * ((float)Math.PI / 180F));
  41.         float f6 = f3 * f4;
  42.         float f7 = f2 * f4;
  43.         double d0 = pPlayer.getReachDistance();
  44.         Vec3 vec31 = vec3.add((double)f6 * d0, (double)f5 * d0, (double)f7 * d0);
  45.         return pLevel.clip(new ClipContext(vec3, vec31, ClipContext.Block.OUTLINE, pFluidMode, pPlayer));
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement