From 68e097f2b2ee75f96460e0ab2202bc96127d08a3 Mon Sep 17 00:00:00 2001 From: Blast-MC Date: Thu, 6 Mar 2025 12:27:39 -0500 Subject: [PATCH] pick block event expansion --- .../player/PlayerPickItemEvent.java.patch | 46 +++++++++++++++++++ .../ServerGamePacketListenerImpl.java.patch | 34 ++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 parchment-api/paper-patches/files/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java.patch diff --git a/parchment-api/paper-patches/files/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java.patch b/parchment-api/paper-patches/files/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java.patch new file mode 100644 index 0000000..cc36bf1 --- /dev/null +++ b/parchment-api/paper-patches/files/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java.patch @@ -0,0 +1,46 @@ +--- a/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java ++++ b/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java +@@ -1,6 +_,8 @@ + package io.papermc.paper.event.player; + + import com.google.common.base.Preconditions; ++import org.bukkit.Location; ++import org.bukkit.entity.Entity; + import org.bukkit.entity.Player; + import org.bukkit.event.Cancellable; + import org.bukkit.event.HandlerList; +@@ -22,13 +_,18 @@ + private int targetSlot; + private int sourceSlot; + ++ private Location location; ++ private Entity entity; ++ + private boolean cancelled; + + @ApiStatus.Internal +- public PlayerPickItemEvent(final Player player, final int targetSlot, final int sourceSlot) { ++ public PlayerPickItemEvent(final Player player, final int targetSlot, final int sourceSlot, final Location location, final Entity entity) { + super(player); + this.targetSlot = targetSlot; + this.sourceSlot = sourceSlot; ++ this.location = location; ++ this.entity = entity; + } + + /** +@@ -72,6 +_,14 @@ + public void setSourceSlot(final @Range(from = -1, to = 35) int sourceSlot) { + Preconditions.checkArgument(sourceSlot >= -1 && sourceSlot <= 35, "Source slot must be in range of the player's inventory slot, or -1"); + this.sourceSlot = sourceSlot; ++ } ++ ++ public Location getLocation() { ++ return location; ++ } ++ ++ public Entity getEntity() { ++ return entity; + } + + @Override diff --git a/parchment-server/minecraft-patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch b/parchment-server/minecraft-patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch index 53509e4..c99efb7 100644 --- a/parchment-server/minecraft-patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch +++ b/parchment-server/minecraft-patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch @@ -16,6 +16,40 @@ } // CraftBukkit end // Paper start - Don't suggest if tab-complete is disabled +@@ -977,7 +_,8 @@ + addBlockDataToItem(blockState, serverLevel, blockPos, cloneItemStack); + } + +- this.tryPickItem(cloneItemStack); ++ Location location = new Location(this.player.getBukkitEntity().getWorld(), blockPos.getX(), blockPos.getY(), blockPos.getZ()); ++ this.tryPickItem(cloneItemStack, location, null); + } + } + } +@@ -1001,12 +_,12 @@ + if (entity != null && this.player.canInteractWithEntity(entity, 3.0)) { + ItemStack pickResult = entity.getPickResult(); + if (pickResult != null && !pickResult.isEmpty()) { +- this.tryPickItem(pickResult); ++ this.tryPickItem(pickResult, null, entity.getBukkitEntity()); + } + } + } + +- private void tryPickItem(ItemStack stack) { ++ private void tryPickItem(ItemStack stack, Location location, org.bukkit.entity.Entity entity) { + if (stack.isItemEnabled(this.player.level().enabledFeatures())) { + Inventory inventory = this.player.getInventory(); + int i = inventory.findSlotMatchingItem(stack); +@@ -1014,7 +_,7 @@ + final int sourceSlot = i; + final int targetSlot = Inventory.isHotbarSlot(sourceSlot) ? sourceSlot : inventory.getSuitableHotbarSlot(); + final org.bukkit.entity.Player bukkitPlayer = this.player.getBukkitEntity(); +- final io.papermc.paper.event.player.PlayerPickItemEvent event = new io.papermc.paper.event.player.PlayerPickItemEvent(bukkitPlayer, targetSlot, sourceSlot); ++ final io.papermc.paper.event.player.PlayerPickItemEvent event = new io.papermc.paper.event.player.PlayerPickItemEvent(bukkitPlayer, targetSlot, sourceSlot, location, entity); + if (!event.callEvent()) { + return; + } @@ -2497,6 +_,7 @@ // Spigot start - spam exclusions