aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/1057-Correct-update-cursor.patch
blob: 1ae9d46f9cb2137899e6c59b40be285d47456795 (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Bjarne Koll <git@lynxplay.dev>
Date: Fri, 1 Nov 2024 14:58:57 +0100
Subject: [PATCH] Correct update cursor

Spigot uses a no longer valid ClientboundContainerSetSlotPacket with the
slot -1, which would update the carried stack in versions <=1.21.1 but
now leads to an IOOB.
1.21.2 instead introduced the ClientboundSetCursorItemPacket, which this
patch uses instead.

diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index a3d8d5d735272ae2a67536e4d5bbcdb5d2e4bf8b..cdee55bece5e64a88051ecc0c43f446b50076ed3 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -3353,7 +3353,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
                                     case PLACE_SOME:
                                     case PLACE_ONE:
                                     case SWAP_WITH_CURSOR:
-                                        this.player.connection.send(new ClientboundContainerSetSlotPacket(-1, -1, this.player.inventoryMenu.incrementStateId(), this.player.containerMenu.getCarried()));
+                                        this.player.connection.send(new net.minecraft.network.protocol.game.ClientboundSetCursorItemPacket(this.player.containerMenu.getCarried().copy())); // Paper - correctly set cursor
                                         this.player.connection.send(new ClientboundContainerSetSlotPacket(this.player.containerMenu.containerId, this.player.inventoryMenu.incrementStateId(), packet.getSlotNum(), this.player.containerMenu.getSlot(packet.getSlotNum()).getItem()));
                                         break;
                                     // Modified clicked only
@@ -3365,7 +3365,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
                                     case DROP_ALL_CURSOR:
                                     case DROP_ONE_CURSOR:
                                     case CLONE_STACK:
-                                        this.player.connection.send(new ClientboundContainerSetSlotPacket(-1, -1, this.player.inventoryMenu.incrementStateId(), this.player.containerMenu.getCarried()));
+                                        this.player.connection.send(new net.minecraft.network.protocol.game.ClientboundSetCursorItemPacket(this.player.containerMenu.getCarried().copy())); // Paper - correctly set cursor
                                         break;
                                     // Nothing
                                     case NOTHING:
@@ -3543,7 +3543,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
                     // Reset the slot
                     if (packet.slotNum() >= 0) {
                         this.player.connection.send(new ClientboundContainerSetSlotPacket(this.player.inventoryMenu.containerId, this.player.inventoryMenu.incrementStateId(), packet.slotNum(), this.player.inventoryMenu.getSlot(packet.slotNum()).getItem()));
-                        this.player.connection.send(new ClientboundContainerSetSlotPacket(-1, this.player.inventoryMenu.incrementStateId(), -1, ItemStack.EMPTY));
+                        this.player.connection.send(new net.minecraft.network.protocol.game.ClientboundSetCursorItemPacket(ItemStack.EMPTY.copy())); // Paper - correctly set cursor
                     }
                     return;
                 }