Skip to content

Commit dbc367b

Browse files
authored
Keep non-container slots synced when in container view (#12881)
1 parent a576361 commit dbc367b

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

build-data/paper.at

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ public net.minecraft.world.inventory.AbstractContainerMenu quickcraftSlots
510510
public net.minecraft.world.inventory.AbstractContainerMenu quickcraftStatus
511511
public net.minecraft.world.inventory.AbstractContainerMenu quickcraftType
512512
public net.minecraft.world.inventory.AbstractContainerMenu resetQuickCraft()V
513+
public net.minecraft.world.inventory.AbstractContainerMenu synchronizeSlotToRemote(ILnet/minecraft/world/item/ItemStack;Ljava/util/function/Supplier;)V
514+
public net.minecraft.world.inventory.AbstractContainerMenu triggerSlotListeners(ILnet/minecraft/world/item/ItemStack;Ljava/util/function/Supplier;)V
513515
public net.minecraft.world.inventory.AbstractCraftingMenu craftSlots
514516
public net.minecraft.world.inventory.AbstractCraftingMenu resultSlots
515517
public net.minecraft.world.inventory.AnvilMenu cost

paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
this.tickClientLoadTimeout();
217217
this.gameMode.tick();
218218
this.wardenSpawnTracker.tick();
219-
@@ -614,9 +_,14 @@
219+
@@ -614,9 +_,18 @@
220220
this.invulnerableTime--;
221221
}
222222

@@ -226,6 +226,10 @@
226226
+ // Paper start - Configurable container update tick rate
227227
+ if (--this.containerUpdateDelay <= 0) {
228228
+ this.containerMenu.broadcastChanges();
229+
+ // Broadcast equipment and crafting slots when the player is in a container, fixes MC-297508
230+
+ if (this.containerMenu != this.inventoryMenu) {
231+
+ this.inventoryMenu.broadcastNonContainerSlotChanges();
232+
+ }
229233
+ this.containerUpdateDelay = this.level().paperConfig().tickRates.containerUpdate;
230234
+ }
231235
+ // Paper end - Configurable container update tick rate

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,10 +2281,11 @@
22812281

22822282
for (Entry<HashedStack> entry : Int2ObjectMaps.fastIterable(packet.changedSlots())) {
22832283
this.player.containerMenu.setRemoteSlotUnsafe(entry.getIntKey(), entry.getValue());
2284-
@@ -1824,6 +_,7 @@
2284+
@@ -1824,6 +_,8 @@
22852285
} else {
22862286
this.player.containerMenu.broadcastChanges();
22872287
}
2288+
+ if (packet.buttonNum() == Inventory.SLOT_OFFHAND && this.player.containerMenu != this.player.inventoryMenu) this.player.containerSynchronizer.sendOffHandSlotChange(); // Paper - update offhand data when the player is clicking in an inventory not their own as the sychronizer does not include offhand slots
22882289
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdates(); // Paper - Force update attributes.
22892290
}
22902291
}

paper-server/patches/sources/net/minecraft/world/inventory/InventoryMenu.java.patch

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
this.active = active;
1616
this.owner = owner;
1717
this.addResultSlot(owner, 154, 28);
18-
@@ -188,4 +_,38 @@
18+
@@ -188,4 +_,54 @@
1919
protected Player owner() {
2020
return this.owner;
2121
}
@@ -53,4 +53,20 @@
5353
+ }
5454
+
5555
+ // CraftBukkit end
56+
+
57+
+ // Paper start - utility methods for synchronizing slots usually not synchronized by the container menus
58+
+ public void broadcastNonContainerSlotChanges() {
59+
+ for (int i = RESULT_SLOT; i < ARMOR_SLOT_END; i++) {
60+
+ this.broadcastSlotChange(i);
61+
+ }
62+
+ this.broadcastSlotChange(SHIELD_SLOT);
63+
+ }
64+
+
65+
+ private void broadcastSlotChange(int slot) {
66+
+ ItemStack item = this.slots.get(slot).getItem();
67+
+ java.util.function.Supplier<net.minecraft.world.item.ItemStack> supplier = com.google.common.base.Suppliers.memoize(item::copy);
68+
+ this.triggerSlotListeners(slot, item, supplier);
69+
+ this.synchronizeSlotToRemote(slot, item, supplier);
70+
+ }
71+
+ // Paper end - utility methods for synchronizing slots usually not synchronized by the container menus
5672
}

0 commit comments

Comments
 (0)