Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SubscribeEvent
- public static void checkForWater(PlayerInteractEvent.RightClickItem event) {
- if(event.getEntity() == null){
- return;
- }
- Player player = event.getEntity();
- HitResult hitresult = getPlayerPOVHitResult(event.getLevel(), event.getEntity(), ClipContext.Fluid.SOURCE_ONLY);
- if(hitresult.getType() == HitResult.Type.MISS){
- return;
- }
- if(hitresult.getType() == HitResult.Type.BLOCK) {
- BlockPos blockpos = ((BlockHitResult)hitresult).getBlockPos();
- if (!event.getLevel().getFluidState(blockpos).is(WATER)) {
- return;
- }
- ItemStack itemInHand = player.getItemInHand(event.getHand());
- if (itemInHand.is(Items.GLASS_BOTTLE)) {
- event.setCanceled(true);
- player.level.gameEvent(player, GameEvent.FLUID_PICKUP, blockpos);
- if (!player.isCreative()) {
- itemInHand.shrink(1);
- }
- return;
- }
- }
- }
- //Vanilla copy
- protected static BlockHitResult getPlayerPOVHitResult(Level pLevel, Player pPlayer, ClipContext.Fluid pFluidMode) {
- float f = pPlayer.getXRot();
- float f1 = pPlayer.getYRot();
- Vec3 vec3 = pPlayer.getEyePosition();
- float f2 = Mth.cos(-f1 * ((float)Math.PI / 180F) - (float)Math.PI);
- float f3 = Mth.sin(-f1 * ((float)Math.PI / 180F) - (float)Math.PI);
- float f4 = -Mth.cos(-f * ((float)Math.PI / 180F));
- float f5 = Mth.sin(-f * ((float)Math.PI / 180F));
- float f6 = f3 * f4;
- float f7 = f2 * f4;
- double d0 = pPlayer.getReachDistance();
- Vec3 vec31 = vec3.add((double)f6 * d0, (double)f5 * d0, (double)f7 * d0);
- return pLevel.clip(new ClipContext(vec3, vec31, ClipContext.Block.OUTLINE, pFluidMode, pPlayer));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement