2021-01-08 05:26:51 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Matthew Miller <mnmiller1@me.com>
|
|
|
|
Date: Mon, 4 Jan 2021 16:40:27 +1000
|
|
|
|
Subject: [PATCH] Implement API to expose exact interaction point
|
|
|
|
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/PlayerInteractManager.java b/src/main/java/net/minecraft/server/level/PlayerInteractManager.java
|
2021-04-27 15:51:42 +00:00
|
|
|
index 31012963815a5c7355753b8cd2749976282ef0d2..87722285690d9d3370610e2a2eb809e0d1f497c9 100644
|
2021-03-16 07:19:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/PlayerInteractManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/PlayerInteractManager.java
|
2021-04-27 15:51:42 +00:00
|
|
|
@@ -496,7 +496,7 @@ public class PlayerInteractManager {
|
2021-01-08 05:26:51 +00:00
|
|
|
cancelledBlock = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
- PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, blockposition, movingobjectpositionblock.getDirection(), itemstack, cancelledBlock, enumhand);
|
|
|
|
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, blockposition, movingobjectpositionblock.getDirection(), itemstack, cancelledBlock, enumhand, movingobjectpositionblock.getPos()); // Paper
|
|
|
|
firedInteract = true;
|
|
|
|
interactResult = event.useItemInHand() == Event.Result.DENY;
|
|
|
|
interactPosition = blockposition.immutableCopy();
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2021-04-24 22:47:20 +00:00
|
|
|
index b7287868c26bc023c423b8ecbdf28ea99b3d1716..08b3adcd1ab8c8872a40b2faecc95471c3236292 100644
|
2021-01-08 05:26:51 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2021-04-24 22:47:20 +00:00
|
|
|
@@ -69,7 +69,9 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParameters;
|
2021-03-16 13:04:28 +00:00
|
|
|
import net.minecraft.world.phys.MovingObjectPosition;
|
2021-03-16 07:19:45 +00:00
|
|
|
import net.minecraft.world.phys.MovingObjectPositionBlock;
|
|
|
|
import net.minecraft.world.phys.MovingObjectPositionEntity;
|
2021-03-16 13:04:28 +00:00
|
|
|
+import net.minecraft.world.phys.Vec3D;
|
2021-01-08 05:26:51 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2021-03-16 07:19:45 +00:00
|
|
|
+import org.bukkit.Location; // Paper
|
2021-01-08 05:26:51 +00:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.NamespacedKey;
|
|
|
|
import org.bukkit.Server;
|
2021-04-24 22:47:20 +00:00
|
|
|
@@ -483,7 +485,13 @@ public class CraftEventFactory {
|
2021-01-08 05:26:51 +00:00
|
|
|
return callPlayerInteractEvent(who, action, position, direction, itemstack, false, hand);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - Add interactionPoint
|
|
|
|
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) {
|
|
|
|
+ return callPlayerInteractEvent(who, action, position, direction, itemstack, cancelledBlock, hand, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand, Vec3D hitVec) {
|
|
|
|
+ // Paper end
|
|
|
|
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
|
|
|
|
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
|
|
|
|
|
2021-04-24 22:47:20 +00:00
|
|
|
@@ -509,7 +517,10 @@ public class CraftEventFactory {
|
2021-01-08 05:26:51 +00:00
|
|
|
itemInHand = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
- PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
|
|
|
|
+ // Paper start
|
|
|
|
+ Location interactionPoint = hitVec == null ? null : new Location(craftWorld, hitVec.x, hitVec.y, hitVec.z);
|
|
|
|
+ PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND), interactionPoint);
|
|
|
|
+ // Paper end
|
|
|
|
if (cancelledBlock) {
|
|
|
|
event.setUseInteractedBlock(Event.Result.DENY);
|
|
|
|
}
|