Skip to content

Commit 68e097f

Browse files
committed
pick block event expansion
1 parent e2ef14b commit 68e097f

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--- a/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java
2+
+++ b/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java
3+
@@ -1,6 +_,8 @@
4+
package io.papermc.paper.event.player;
5+
6+
import com.google.common.base.Preconditions;
7+
+import org.bukkit.Location;
8+
+import org.bukkit.entity.Entity;
9+
import org.bukkit.entity.Player;
10+
import org.bukkit.event.Cancellable;
11+
import org.bukkit.event.HandlerList;
12+
@@ -22,13 +_,18 @@
13+
private int targetSlot;
14+
private int sourceSlot;
15+
16+
+ private Location location;
17+
+ private Entity entity;
18+
+
19+
private boolean cancelled;
20+
21+
@ApiStatus.Internal
22+
- public PlayerPickItemEvent(final Player player, final int targetSlot, final int sourceSlot) {
23+
+ public PlayerPickItemEvent(final Player player, final int targetSlot, final int sourceSlot, final Location location, final Entity entity) {
24+
super(player);
25+
this.targetSlot = targetSlot;
26+
this.sourceSlot = sourceSlot;
27+
+ this.location = location;
28+
+ this.entity = entity;
29+
}
30+
31+
/**
32+
@@ -72,6 +_,14 @@
33+
public void setSourceSlot(final @Range(from = -1, to = 35) int sourceSlot) {
34+
Preconditions.checkArgument(sourceSlot >= -1 && sourceSlot <= 35, "Source slot must be in range of the player's inventory slot, or -1");
35+
this.sourceSlot = sourceSlot;
36+
+ }
37+
+
38+
+ public Location getLocation() {
39+
+ return location;
40+
+ }
41+
+
42+
+ public Entity getEntity() {
43+
+ return entity;
44+
}
45+
46+
@Override

parchment-server/minecraft-patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,40 @@
1616
}
1717
// CraftBukkit end
1818
// Paper start - Don't suggest if tab-complete is disabled
19+
@@ -977,7 +_,8 @@
20+
addBlockDataToItem(blockState, serverLevel, blockPos, cloneItemStack);
21+
}
22+
23+
- this.tryPickItem(cloneItemStack);
24+
+ Location location = new Location(this.player.getBukkitEntity().getWorld(), blockPos.getX(), blockPos.getY(), blockPos.getZ());
25+
+ this.tryPickItem(cloneItemStack, location, null);
26+
}
27+
}
28+
}
29+
@@ -1001,12 +_,12 @@
30+
if (entity != null && this.player.canInteractWithEntity(entity, 3.0)) {
31+
ItemStack pickResult = entity.getPickResult();
32+
if (pickResult != null && !pickResult.isEmpty()) {
33+
- this.tryPickItem(pickResult);
34+
+ this.tryPickItem(pickResult, null, entity.getBukkitEntity());
35+
}
36+
}
37+
}
38+
39+
- private void tryPickItem(ItemStack stack) {
40+
+ private void tryPickItem(ItemStack stack, Location location, org.bukkit.entity.Entity entity) {
41+
if (stack.isItemEnabled(this.player.level().enabledFeatures())) {
42+
Inventory inventory = this.player.getInventory();
43+
int i = inventory.findSlotMatchingItem(stack);
44+
@@ -1014,7 +_,7 @@
45+
final int sourceSlot = i;
46+
final int targetSlot = Inventory.isHotbarSlot(sourceSlot) ? sourceSlot : inventory.getSuitableHotbarSlot();
47+
final org.bukkit.entity.Player bukkitPlayer = this.player.getBukkitEntity();
48+
- final io.papermc.paper.event.player.PlayerPickItemEvent event = new io.papermc.paper.event.player.PlayerPickItemEvent(bukkitPlayer, targetSlot, sourceSlot);
49+
+ final io.papermc.paper.event.player.PlayerPickItemEvent event = new io.papermc.paper.event.player.PlayerPickItemEvent(bukkitPlayer, targetSlot, sourceSlot, location, entity);
50+
if (!event.callEvent()) {
51+
return;
52+
}
1953
@@ -2497,6 +_,7 @@
2054

2155
// Spigot start - spam exclusions

0 commit comments

Comments
 (0)