9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-archived-patches/removed/hardfork/server/0110-Cache-ItemStack-max-stack-size.patch
2025-06-07 12:17:33 +08:00

67 lines
3.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Fri, 7 Feb 2025 21:41:51 +0100
Subject: [PATCH] Cache ItemStack max stack size
Abandoned plan, maybe research deeper in this part in the future, maybe not
diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java
index fd7c1e800cbd4919a1a47f6c468c8776535bd028..fdd7e89bacc98e23f067ba17d0bd93ee84a388cb 100644
--- a/net/minecraft/world/item/ItemStack.java
+++ b/net/minecraft/world/item/ItemStack.java
@@ -194,6 +194,7 @@ public final class ItemStack implements DataComponentHolder, net.caffeinemc.mods
private static final Logger LOGGER = LogUtils.getLogger();
public static final ItemStack EMPTY = new ItemStack((Void)null);
private static final Component DISABLED_ITEM_TOOLTIP = Component.translatable("item.disabled").withStyle(ChatFormatting.RED);
+ private int maxStackSize;
private int count;
private int popTime;
@Deprecated
@@ -289,11 +290,13 @@ public final class ItemStack implements DataComponentHolder, net.caffeinemc.mods
this.count = count;
this.components = components;
this.getItem().verifyComponentsAfterLoad(this);
+ this.maxStackSize = getMaxStackSizeInternal(); // Leaf - Cache ItemStack max stack size
}
private ItemStack(@Nullable Void unused) {
this.item = null;
this.components = new PatchedDataComponentMap(DataComponentMap.EMPTY);
+ this.maxStackSize = 1; // Leaf - Cache ItemStack max stack size - taken from ItemStack#isEmpty
}
public static DataResult<Unit> validateComponents(DataComponentMap components) {
@@ -619,9 +622,15 @@ public final class ItemStack implements DataComponentHolder, net.caffeinemc.mods
}
public int getMaxStackSize() {
- return this.getOrDefault(DataComponents.MAX_STACK_SIZE, Integer.valueOf(1));
+ return maxStackSize; // Leaf - Cache ItemStack max stack size
}
+ // Leaf start - Cache ItemStack max stack size
+ private int getMaxStackSizeInternal() {
+ return this.getOrDefault(DataComponents.MAX_STACK_SIZE, 1);
+ }
+ // Leaf end - Cache ItemStack max stack size
+
public boolean isStackable() {
return this.getMaxStackSize() > 1 && (!this.isDamageableItem() || !this.isDamaged());
}
@@ -1339,6 +1348,7 @@ public final class ItemStack implements DataComponentHolder, net.caffeinemc.mods
this.components = new PatchedDataComponentMap(this.item.components());
this.applyComponents(patch);
// Paper end - change base component prototype
+ this.maxStackSize = getMaxStackSizeInternal(); // Leaf - Cache ItemStack max stack size
}
// CraftBukkit end
@@ -1396,6 +1406,7 @@ public final class ItemStack implements DataComponentHolder, net.caffeinemc.mods
}
// Leaf end - Lithium - equipment tracking
this.count = count;
+ maxStackSize = count <= 0 ? 1 : getMaxStackSizeInternal(); // Leaf - Cache ItemStack max stack size - taken from ItemStack#isEmpty
}
public void limitSize(int maxSize) {