3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/patches/server/0520-Fix-interact-event-not-being-called-sometimes.patch
Nassim Jahnke 72e87abc2d
Strip raytracing for EntityLiving#hasLineOfSight
Co-authored-by: Paul Sauve <paul@technove.co>
2023-09-10 12:28:03 +10:00

49 Zeilen
4.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: TheMolkaPL <themolkapl@gmail.com>
Date: Sun, 21 Jun 2020 17:21:46 +0200
Subject: [PATCH] Fix interact event not being called sometimes
* Call PlayerInteractEvent when left-clicking on a block in adventure
mode.
* Call PlayerInteractEvent when left-clicking an Entity that is out of
range in adventure/survival (entity reach is 3.0).
Co-authored-by: Moulberry <james.jenour@protonmail.com>
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 9f9db1234a8b14fbb53a1293f0ffe2b51d652c5e..d0fee1a4d728213a6b0c9bf9f26101d1a5bbec9f 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1839,7 +1839,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
MutableComponent ichatmutablecomponent = Component.translatable("build.tooHigh", i - 1).withStyle(ChatFormatting.RED);
this.player.sendSystemMessage(ichatmutablecomponent, true);
- } else if (enuminteractionresult.shouldSwing()) {
+ } else if (enuminteractionresult.shouldSwing() && !this.player.gameMode.interactResult) { // Paper
this.player.swing(enumhand, true);
}
}
@@ -2468,13 +2468,20 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
double d3 = player.gameMode.getGameModeForPlayer() == GameType.CREATIVE ? 5.0D : 4.5D;
// 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
// SPIGOT-7429: Make sure to call PlayerInteractEvent for spectators and non-pickable entities
- org.bukkit.util.RayTraceResult result = this.player.level().getWorld().rayTrace(origin, origin.getDirection(), d3, org.bukkit.FluidCollisionMode.NEVER, false, 0.1, entity -> {
+ org.bukkit.util.RayTraceResult result = this.player.level().getWorld().rayTrace(origin, origin.getDirection(), d3, org.bukkit.FluidCollisionMode.NEVER, false, 0.0, entity -> { // Paper - change raySize from 0.1 to 0.0
Entity handle = ((CraftEntity) entity).getHandle();
return entity != this.player.getBukkitEntity() && this.player.getBukkitEntity().canSee(entity) && !handle.isSpectator() && handle.isPickable() && !handle.isPassengerOfSameVehicle(player);
});
if (result == null) {
CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
- }
+ } else { // Paper start - Fix interact event not being called sometimes
+ GameType gameType = this.player.gameMode.getGameModeForPlayer();
+ if (gameType == GameType.ADVENTURE && result.getHitBlock() != null) {
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, io.papermc.paper.util.MCUtil.toBlockPosition(result.getHitPosition()), org.bukkit.craftbukkit.block.CraftBlock.blockFaceToNotch(result.getHitBlockFace()), this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
+ } else if (gameType != GameType.CREATIVE && result.getHitEntity() != null && origin.toVector().distanceSquared(result.getHitPosition()) > 3.0D * 3.0D) {
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
+ }
+ } // Paper end
// Arm swing animation
PlayerAnimationEvent event = new PlayerAnimationEvent(this.getCraftPlayer(), (packet.getHand() == InteractionHand.MAIN_HAND) ? PlayerAnimationType.ARM_SWING : PlayerAnimationType.OFF_ARM_SWING);