2023-09-11 04:03:35 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Nassim Jahnke <nassim@njahnke.dev>
|
|
|
|
Date: Mon, 11 Sep 2023 12:01:57 +1000
|
|
|
|
Subject: [PATCH] Add slot sanity checks in container clicks
|
|
|
|
|
|
|
|
|
2023-11-04 16:07:48 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2023-11-11 21:25:45 +01:00
|
|
|
index 236ab643cdd65b3572860aedf1f5ac18ff96139a..65bb221993147a558995b36fb835f7b82e0eb4bd 100644
|
2023-11-04 16:07:48 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2023-11-11 21:25:45 +01:00
|
|
|
@@ -2981,6 +2981,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
2023-11-04 16:07:48 +01:00
|
|
|
break;
|
|
|
|
case SWAP:
|
|
|
|
if ((packet.getButtonNum() >= 0 && packet.getButtonNum() < 9) || packet.getButtonNum() == 40) {
|
|
|
|
+ // Paper start
|
|
|
|
+ if (packet.getSlotNum() < 0) {
|
|
|
|
+ action = InventoryAction.NOTHING;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
click = (packet.getButtonNum() == 40) ? ClickType.SWAP_OFFHAND : ClickType.NUMBER_KEY;
|
|
|
|
Slot clickedSlot = this.player.containerMenu.getSlot(packet.getSlotNum());
|
|
|
|
if (clickedSlot.mayPickup(this.player)) {
|
2023-09-11 04:03:35 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
2023-11-25 22:48:32 +01:00
|
|
|
index 3ef712299fe248602b0b117c0a8e285cdf4e05c2..aea228ea9fee51c25a03ce1c54bf9dff0741e053 100644
|
2023-09-11 04:03:35 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
|
|
@@ -423,6 +423,7 @@ public abstract class AbstractContainerMenu {
|
|
|
|
this.resetQuickCraft();
|
|
|
|
}
|
|
|
|
} else if (this.quickcraftStatus == 1) {
|
|
|
|
+ if (slotIndex < 0) return; // Paper
|
|
|
|
slot = (Slot) this.slots.get(slotIndex);
|
|
|
|
itemstack = this.getCarried();
|
|
|
|
if (AbstractContainerMenu.canItemQuickReplace(slot, itemstack, true) && slot.mayPlace(itemstack) && (this.quickcraftType == 2 || itemstack.getCount() > this.quickcraftSlots.size()) && this.canDragTo(slot)) {
|
2023-11-25 22:48:32 +01:00
|
|
|
@@ -597,7 +598,8 @@ public abstract class AbstractContainerMenu {
|
|
|
|
Slot slot2;
|
2023-09-11 04:03:35 +02:00
|
|
|
int j2;
|
|
|
|
|
2023-11-25 22:48:32 +01:00
|
|
|
- if (actionType == ClickType.SWAP) {
|
|
|
|
+ if (actionType == ClickType.SWAP && (button == 40 || button >= 0 && button < 9)) { // Paper
|
2023-11-03 05:49:55 +01:00
|
|
|
+ if (slotIndex < 0 || button < 0) return; // Paper
|
2023-09-11 04:03:35 +02:00
|
|
|
slot2 = (Slot) this.slots.get(slotIndex);
|
|
|
|
itemstack1 = playerinventory.getItem(button);
|
|
|
|
itemstack = slot2.getItem();
|