Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Fix rogue armswing detection

Open Owen1212055 opened this issue 2 years ago • 2 comments

Fix https://github.com/PaperMC/Paper/issues/8540

The range for survival is actually 3 blocks. This also fixes the issue where if you look "nearby" an entity it will incorrectly assume you are attacking that entity.

TODO: Properly have check for blocks/entities separate

Owen1212055 avatar Nov 23 '22 18:11 Owen1212055

Reported upstream, most likely will see a fix there. If not will reopen.

Owen1212055 avatar Jan 10 '23 02:01 Owen1212055

Hello!

Unfortunately, this fix is incorrect. It will result in both LEFT_CLICK_AIR and LEFT_CLICK_BLOCK firing if there is a block greater than 3.0 units away.

The correct fix is to perform the raycast with length 4.5, then allow the PlayerInteractEvent to be fired as long as the entity is further than 3.0 blocks away. As far as I can tell, this is the same logic that the vanilla GameRenderer#pick uses.

A sample patch is provided below.

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Moulberry <[email protected]>
Date: Sun, 30 Apr 2023 23:06:24 +0800
Subject: [PATCH] Fix Paper/8540


diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 9c5754ac3b00d3f0cb80ec83a2beefadee6d0a14..7c113741fd06e400b4bfc0caf9a6a8221505f220 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2606,7 +2606,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
         // SPIGOT-5607: Only call interact event if no block or entity is being clicked. Use bukkit ray trace method, because it handles blocks and entities at the same time
         org.bukkit.util.RayTraceResult result = this.player.level.getWorld().rayTrace(origin, origin.getDirection(), d3, org.bukkit.FluidCollisionMode.NEVER, false, 0.1, entity -> entity != this.player.getBukkitEntity() && this.player.getBukkitEntity().canSee(entity));
 
-        if (result == null || this.player.gameMode.getGameModeForPlayer() == GameType.ADVENTURE) { // Paper - call PlayerInteractEvent when left-clicking on a block in adventure mode
+        if (result == null || this.player.gameMode.getGameModeForPlayer() == GameType.ADVENTURE || (player.gameMode.getGameModeForPlayer() != GameType.CREATIVE && result.getHitEntity() != null && origin.toVector().distanceSquared(result.getHitPosition()) > 3.0D*3.0D)) { // Paper - call PlayerInteractEvent when left-clicking on a block in adventure mode // Paper - call PlayerInteractEvent when entity distance is greater than 3.0
             CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
         }

Moulberry avatar Apr 30 '23 15:04 Moulberry

Superseded by https://github.com/PaperMC/Paper/pull/9211

Owen1212055 avatar Jul 14 '23 03:07 Owen1212055