2023-07-16 17:58:25 +02:00
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
2024-12-03 22:06:05 +01:00
index 04de96af5415c3115703f5ab42e9fa3aa2ccee60..76b6c3fca13590f057dc4767d27fef4192974147 100644
2023-07-16 17:58:25 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-12-03 19:54:10 +01:00
@@ -1842,7 +1842,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
} else if (enuminteractionresult instanceof InteractionResult.Success) {
InteractionResult.Success enuminteractionresult_d = (InteractionResult.Success) enuminteractionresult;
2023-07-16 17:58:25 +02:00
2024-12-03 19:54:10 +01:00
- if (enuminteractionresult_d.swingSource() == InteractionResult.SwingSource.SERVER) {
2024-12-03 20:34:55 +01:00
+ if (enuminteractionresult_d.swingSource() == InteractionResult.SwingSource.SERVER && !this.player.gameMode.interactResult) { // Paper - Call interact event
2024-12-03 19:54:10 +01:00
this.player.swing(enumhand, true);
}
2024-10-23 17:58:11 +02:00
}
2024-12-03 19:54:10 +01:00
@@ -2466,13 +2466,20 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2024-06-16 17:21:14 +02:00
double d3 = Math.max(this.player.blockInteractionRange(), this.player.entityInteractionRange());
2023-07-16 17:58:25 +02:00
// 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
2023-08-06 02:21:59 +02:00
// 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 -> {
2024-01-19 22:13:42 +01:00
+ org.bukkit.util.RayTraceResult result = this.player.level().getWorld().rayTrace(origin, origin.getDirection(), d3, org.bukkit.FluidCollisionMode.NEVER, false, 0.0, entity -> { // Paper - Call interact event; change raySize from 0.1 to 0.0
2023-08-06 02:21:59 +02:00
Entity handle = ((CraftEntity) entity).getHandle();
2023-10-27 01:34:58 +02:00
return entity != this.player.getBukkitEntity() && this.player.getBukkitEntity().canSee(entity) && !handle.isSpectator() && handle.isPickable() && !handle.isPassengerOfSameVehicle(this.player);
2023-08-06 02:21:59 +02:00
});
2023-07-16 17:58:25 +02:00
if (result == null) {
CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
- }
2024-01-19 22:13:42 +01:00
+ } else { // Paper start - Call interact event
2023-07-16 17:58:25 +02:00
+ GameType gameType = this.player.gameMode.getGameModeForPlayer();
+ if (gameType == GameType.ADVENTURE && result.getHitBlock() != null) {
2023-12-10 11:02:24 +01:00
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, ((org.bukkit.craftbukkit.block.CraftBlock) result.getHitBlock()).getPosition(), org.bukkit.craftbukkit.block.CraftBlock.blockFaceToNotch(result.getHitBlockFace()), this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
2024-06-16 17:21:14 +02:00
+ } else if (gameType != GameType.CREATIVE && result.getHitEntity() != null && origin.toVector().distanceSquared(result.getHitPosition()) > this.player.entityInteractionRange() * this.player.entityInteractionRange()) {
2023-07-16 17:58:25 +02:00
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
+ }
2024-01-19 22:13:42 +01:00
+ } // Paper end - Call interact event
2023-07-16 17:58:25 +02:00
// Arm swing animation
PlayerAnimationEvent event = new PlayerAnimationEvent(this.getCraftPlayer(), (packet.getHand() == InteractionHand.MAIN_HAND) ? PlayerAnimationType.ARM_SWING : PlayerAnimationType.OFF_ARM_SWING);