Skip to content

Commit 4df26a8

Browse files
committed
add data request to event (ctrl+pickblock)
1 parent 92b60b4 commit 4df26a8

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

parchment-api/paper-patches/files/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java.patch

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,30 @@
99
import org.bukkit.entity.Player;
1010
import org.bukkit.event.Cancellable;
1111
import org.bukkit.event.HandlerList;
12-
@@ -22,13 +_,18 @@
12+
@@ -21,14 +_,21 @@
13+
1314
private int targetSlot;
1415
private int sourceSlot;
15-
16-
+ private Location location;
17-
+ private Entity entity;
16+
+ private final Location location;
17+
+ private final Entity entity;
18+
+ private boolean isRequestingData;
1819
+
20+
1921
private boolean cancelled;
2022

2123
@ApiStatus.Internal
2224
- 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) {
25+
+ public PlayerPickItemEvent(final Player player, final int targetSlot, final int sourceSlot, final Location location, final Entity entity, boolean isRequestingData) {
2426
super(player);
2527
this.targetSlot = targetSlot;
2628
this.sourceSlot = sourceSlot;
2729
+ this.location = location;
2830
+ this.entity = entity;
31+
+ this.isRequestingData = isRequestingData;
2932
}
3033

3134
/**
32-
@@ -72,6 +_,14 @@
35+
@@ -72,6 +_,18 @@
3336
public void setSourceSlot(final @Range(from = -1, to = 35) int sourceSlot) {
3437
Preconditions.checkArgument(sourceSlot >= -1 && sourceSlot <= 35, "Source slot must be in range of the player's inventory slot, or -1");
3538
this.sourceSlot = sourceSlot;
@@ -41,6 +44,10 @@
4144
+
4245
+ public @org.jetbrains.annotations.Nullable Entity getEntity() {
4346
+ return entity;
47+
+ }
48+
+
49+
+ public boolean isRequestingData() {
50+
+ return isRequestingData;
4451
}
4552

4653
@Override

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
- this.tryPickItem(cloneItemStack);
2424
+ Location location = new Location(this.player.getBukkitEntity().getWorld(), blockPos.getX(), blockPos.getY(), blockPos.getZ());
25-
+ this.tryPickItem(cloneItemStack, location, null);
25+
+ this.tryPickItem(cloneItemStack, location, null, flag);
2626
}
2727
}
2828
}
@@ -31,13 +31,13 @@
3131
ItemStack pickResult = entity.getPickResult();
3232
if (pickResult != null && !pickResult.isEmpty()) {
3333
- this.tryPickItem(pickResult);
34-
+ this.tryPickItem(pickResult, null, entity.getBukkitEntity());
34+
+ this.tryPickItem(pickResult, null, entity.getBukkitEntity(), this.player.hasInfiniteMaterials() && packet.includeData());
3535
}
3636
}
3737
}
3838

3939
- private void tryPickItem(ItemStack stack) {
40-
+ private void tryPickItem(ItemStack stack, Location location, org.bukkit.entity.Entity entity) {
40+
+ private void tryPickItem(ItemStack stack, Location location, org.bukkit.entity.Entity entity, boolean isRequestingData) {
4141
if (stack.isItemEnabled(this.player.level().enabledFeatures())) {
4242
Inventory inventory = this.player.getInventory();
4343
int i = inventory.findSlotMatchingItem(stack);
@@ -46,7 +46,7 @@
4646
final int targetSlot = Inventory.isHotbarSlot(sourceSlot) ? sourceSlot : inventory.getSuitableHotbarSlot();
4747
final org.bukkit.entity.Player bukkitPlayer = this.player.getBukkitEntity();
4848
- 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);
49+
+ final io.papermc.paper.event.player.PlayerPickItemEvent event = new io.papermc.paper.event.player.PlayerPickItemEvent(bukkitPlayer, targetSlot, sourceSlot, location, entity, isRequestingData);
5050
if (!event.callEvent()) {
5151
return;
5252
}

0 commit comments

Comments
 (0)