mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-25 09:59:15 +00:00
fix inventory updates
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Taiyou06 <kaandindar21@gmail.com>
|
||||
Date: Thu, 20 Feb 2025 20:58:30 +0100
|
||||
Subject: [PATCH] Only broadcast carried item if changed
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/inventory/AbstractContainerMenu.java b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
index 6033f629ac457472ad10f8e346732a596aea52d9..ba37e6b52ceb5f73e9c18cc555e768f43857e549 100644
|
||||
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
@@ -225,24 +225,38 @@ public abstract class AbstractContainerMenu {
|
||||
}
|
||||
|
||||
public void broadcastChanges() {
|
||||
+ // Leaf start - Only broadcast carried item if changed
|
||||
+ // Avoid allocating supplier if no changes
|
||||
+ boolean hasChanges = false;
|
||||
+
|
||||
for (int i = 0; i < this.slots.size(); i++) {
|
||||
ItemStack item = this.slots.get(i).getItem();
|
||||
- Supplier<ItemStack> supplier = Suppliers.memoize(item::copy);
|
||||
- this.triggerSlotListeners(i, item, supplier);
|
||||
- this.synchronizeSlotToRemote(i, item, supplier);
|
||||
+ ItemStack lastItem = this.lastSlots.get(i);
|
||||
+
|
||||
+ // Fast path - reference equality check first
|
||||
+ if (item != lastItem && !ItemStack.matches(lastItem, item)) {
|
||||
+ hasChanges = true;
|
||||
+ Supplier<ItemStack> supplier = Suppliers.memoize(item::copy);
|
||||
+ this.triggerSlotListeners(i, item, supplier);
|
||||
+ this.synchronizeSlotToRemote(i, item, supplier);
|
||||
+ }
|
||||
}
|
||||
|
||||
- this.synchronizeCarriedToRemote();
|
||||
+ // Only synchronize carried item if there were slot changes
|
||||
+ if (hasChanges) {
|
||||
+ this.synchronizeCarriedToRemote();
|
||||
+ }
|
||||
|
||||
+ // Data slot synchronization
|
||||
for (int i = 0; i < this.dataSlots.size(); i++) {
|
||||
DataSlot dataSlot = this.dataSlots.get(i);
|
||||
- int i1 = dataSlot.get();
|
||||
+ int value = dataSlot.get(); // OBFHELPER
|
||||
if (dataSlot.checkAndClearUpdateFlag()) {
|
||||
- this.updateDataSlotListeners(i, i1);
|
||||
+ this.updateDataSlotListeners(i, value);
|
||||
}
|
||||
-
|
||||
- this.synchronizeDataSlotToRemote(i, i1);
|
||||
+ this.synchronizeDataSlotToRemote(i, value);
|
||||
}
|
||||
+ // Leaf end - Only broadcast carried item if changed
|
||||
}
|
||||
|
||||
public void broadcastFullState() {
|
||||
Reference in New Issue
Block a user