2022-10-11 23:49:10 +02:00
|
|
|
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
|
2024-08-31 20:29:50 +02:00
|
|
|
index ad3896dd524acb573adffdfb38b13dd699539cef..3dbaa3c6b75a0f8bfdef42d210f2ac6f560cde3d 100644
|
2022-10-11 23:49:10 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2024-07-18 10:13:20 +02:00
|
|
|
@@ -352,6 +352,25 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
|
2022-10-11 23:49:10 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2024-01-18 15:56:25 +01:00
|
|
|
+ // Paper start - Add PlayerInventorySlotChangeEvent
|
2022-10-11 23:49:10 +02:00
|
|
|
+ @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()) {
|
2022-10-16 09:49:47 +02:00
|
|
|
+ if (io.papermc.paper.event.player.PlayerInventorySlotChangeEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
2022-10-11 23:49:10 +02:00
|
|
|
+ CriteriaTriggers.INVENTORY_CHANGED.trigger(ServerPlayer.this, ServerPlayer.this.getInventory(), stack);
|
|
|
|
+ return;
|
|
|
|
+ }
|
2022-10-16 09:49:47 +02:00
|
|
|
+ io.papermc.paper.event.player.PlayerInventorySlotChangeEvent event = new io.papermc.paper.event.player.PlayerInventorySlotChangeEvent(ServerPlayer.this.getBukkitEntity(), slotId, CraftItemStack.asBukkitCopy(oldStack), CraftItemStack.asBukkitCopy(stack));
|
2022-10-11 23:49:10 +02:00
|
|
|
+ event.callEvent();
|
2022-10-16 09:49:47 +02:00
|
|
|
+ if (event.shouldTriggerAdvancements()) {
|
2022-10-11 23:49:10 +02:00
|
|
|
+ CriteriaTriggers.INVENTORY_CHANGED.trigger(ServerPlayer.this, ServerPlayer.this.getInventory(), stack);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
2024-01-18 15:56:25 +01:00
|
|
|
+ // Paper end - Add PlayerInventorySlotChangeEvent
|
2022-10-11 23:49:10 +02:00
|
|
|
|
|
|
|
@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
|
2024-08-31 20:29:50 +02:00
|
|
|
index b8d8aad81f54f7f43c01da075e63ec9173750bec..f7b9849819c185cd89533aca1f6d34398ffc1077 100644
|
2022-10-11 23:49:10 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
2022-12-07 23:05:32 +01:00
|
|
|
@@ -302,7 +302,7 @@ public abstract class AbstractContainerMenu {
|
2022-10-11 23:49:10 +02:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
ContainerListener icrafting = (ContainerListener) iterator.next();
|
|
|
|
|
|
|
|
- icrafting.slotChanged(this, slot, itemstack2);
|
2024-01-18 15:56:25 +01:00
|
|
|
+ icrafting.slotChanged(this, slot, itemstack1, itemstack2); // Paper - Add PlayerInventorySlotChangeEvent
|
2022-10-11 23:49:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerListener.java b/src/main/java/net/minecraft/world/inventory/ContainerListener.java
|
2024-01-18 15:56:25 +01:00
|
|
|
index 0e19cc55646625bf32a354d3df2dc2d6bcff96f4..eba024c9aadef8902aacccea1584ffbee6c04e44 100644
|
2022-10-11 23:49:10 +02:00
|
|
|
--- 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);
|
|
|
|
|
2024-01-18 15:56:25 +01:00
|
|
|
+ // Paper start - Add PlayerInventorySlotChangeEvent
|
2022-10-11 23:49:10 +02:00
|
|
|
+ default void slotChanged(AbstractContainerMenu handler, int slotId, ItemStack oldStack, ItemStack stack) {
|
|
|
|
+ slotChanged(handler, slotId, stack);
|
|
|
|
+ }
|
2024-01-18 15:56:25 +01:00
|
|
|
+ // Paper end - Add PlayerInventorySlotChangeEvent
|
2022-10-11 23:49:10 +02:00
|
|
|
+
|
|
|
|
void dataChanged(AbstractContainerMenu handler, int property, int value);
|
|
|
|
}
|