summaryrefslogtreecommitdiffhomepage
path: root/patches/unapplied/server/0898-Add-PlayerInventorySlotChangeEvent.patch
blob: d9b77327567bdf3e6401c7fafaff2717298776a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jakub Zacek <dawon@dawon.eu>
Date: Sun, 24 Apr 2022 22:56:59 +0200
Subject: [PATCH] Add PlayerInventorySlotChangeEvent


diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index c5dc769d13fbc2a88a731d42669d0906ee306e4b..6fdb22809195fc2ba95ee22a5523eeabc2f2c4da 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -330,6 +330,25 @@ public class ServerPlayer extends Player {
 
                 }
             }
+            // Paper start
+            @Override
+            public void slotChanged(AbstractContainerMenu handler, int slotId, ItemStack oldStack, ItemStack stack) {
+                Slot slot = handler.getSlot(slotId);
+                if (!(slot instanceof ResultSlot)) {
+                    if (slot.container == ServerPlayer.this.getInventory()) {
+                        if (io.papermc.paper.event.player.PlayerInventorySlotChangeEvent.getHandlerList().getRegisteredListeners().length == 0) {
+                            CriteriaTriggers.INVENTORY_CHANGED.trigger(ServerPlayer.this, ServerPlayer.this.getInventory(), stack);
+                            return;
+                        }
+                        io.papermc.paper.event.player.PlayerInventorySlotChangeEvent event = new io.papermc.paper.event.player.PlayerInventorySlotChangeEvent(ServerPlayer.this.getBukkitEntity(), slotId, CraftItemStack.asBukkitCopy(oldStack), CraftItemStack.asBukkitCopy(stack));
+                        event.callEvent();
+                        if (event.shouldTriggerAdvancements()) {
+                            CriteriaTriggers.INVENTORY_CHANGED.trigger(ServerPlayer.this, ServerPlayer.this.getInventory(), stack);
+                        }
+                    }
+                }
+            }
+            // Paper end
 
             @Override
             public void dataChanged(AbstractContainerMenu handler, int property, int value) {}
diff --git a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
index ec1da07fdfc86c2905766886f6f922320c73fb6a..0954e834ca4c777de61f5d45812008cc7c2ac733 100644
--- a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
@@ -302,7 +302,7 @@ public abstract class AbstractContainerMenu {
             while (iterator.hasNext()) {
                 ContainerListener icrafting = (ContainerListener) iterator.next();
 
-                icrafting.slotChanged(this, slot, itemstack2);
+                icrafting.slotChanged(this, slot, itemstack1, itemstack2); // Paper
             }
         }
 
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerListener.java b/src/main/java/net/minecraft/world/inventory/ContainerListener.java
index 0e19cc55646625bf32a354d3df2dc2d6bcff96f4..8ca9c14310b1e809662dd4ca6d35668992c2fc8d 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerListener.java
+++ b/src/main/java/net/minecraft/world/inventory/ContainerListener.java
@@ -5,5 +5,11 @@ import net.minecraft.world.item.ItemStack;
 public interface ContainerListener {
     void slotChanged(AbstractContainerMenu handler, int slotId, ItemStack stack);
 
+    // Paper start
+    default void slotChanged(AbstractContainerMenu handler, int slotId, ItemStack oldStack, ItemStack stack) {
+        slotChanged(handler, slotId, stack);
+    }
+    // Paper end
+
     void dataChanged(AbstractContainerMenu handler, int property, int value);
 }