2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2021-09-20 11:30:04 +02:00
|
|
|
From: Madeline Miller <mnmiller1@me.com>
|
2021-06-11 14:02:28 +02:00
|
|
|
Date: Mon, 4 Jan 2021 16:40:27 +1000
|
|
|
|
Subject: [PATCH] Implement API to expose exact interaction point
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
2021-09-03 19:57:21 +02:00
|
|
|
index 0b274a5b9e0bf68769637f10e43dbff6d909512b..da2ae74b6f5875200e22c42ed07431016a90845e 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
2021-07-17 14:46:46 +02:00
|
|
|
@@ -501,7 +501,7 @@ public class ServerPlayerGameMode {
|
2021-06-11 14:02:28 +02:00
|
|
|
cancelledBlock = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
- PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, blockposition, hitResult.getDirection(), stack, cancelledBlock, hand);
|
|
|
|
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, blockposition, hitResult.getDirection(), stack, cancelledBlock, hand, hitResult.getLocation()); // Paper
|
2021-06-14 21:17:47 +02:00
|
|
|
this.firedInteract = true;
|
|
|
|
this.interactResult = event.useItemInHand() == Event.Result.DENY;
|
|
|
|
this.interactPosition = blockposition.immutable();
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2021-10-05 05:14:11 +02:00
|
|
|
index 31445c2e888d3020c1cba01f208fd60e424fb173..70452799bb3436fdb11462f77097ee52d1139f0d 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2021-09-01 14:03:36 +02:00
|
|
|
@@ -56,7 +56,9 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
2021-06-11 14:02:28 +02:00
|
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
|
|
import net.minecraft.world.phys.EntityHitResult;
|
|
|
|
import net.minecraft.world.phys.HitResult;
|
|
|
|
+import net.minecraft.world.phys.Vec3;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
+import org.bukkit.Location; // Paper
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.NamespacedKey;
|
|
|
|
import org.bukkit.Server;
|
2021-10-02 19:21:49 +02:00
|
|
|
@@ -482,7 +484,13 @@ public class CraftEventFactory {
|
2021-06-14 21:17:47 +02:00
|
|
|
return CraftEventFactory.callPlayerInteractEvent(who, action, position, direction, itemstack, false, hand);
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - Add interactionPoint
|
|
|
|
public static PlayerInteractEvent callPlayerInteractEvent(net.minecraft.world.entity.player.Player who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, InteractionHand hand) {
|
|
|
|
+ return callPlayerInteractEvent(who, action, position, direction, itemstack, cancelledBlock, hand, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static PlayerInteractEvent callPlayerInteractEvent(net.minecraft.world.entity.player.Player who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, InteractionHand hand, Vec3 hitVec) {
|
|
|
|
+ // Paper end
|
|
|
|
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
|
|
|
|
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
|
|
|
|
|
2021-10-02 19:21:49 +02:00
|
|
|
@@ -508,7 +516,10 @@ public class CraftEventFactory {
|
2021-06-11 14:02:28 +02:00
|
|
|
itemInHand = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
- PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == InteractionHand.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 == InteractionHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND), interactionPoint);
|
|
|
|
+ // Paper end
|
|
|
|
if (cancelledBlock) {
|
|
|
|
event.setUseInteractedBlock(Event.Result.DENY);
|
|
|
|
}
|