From 5908fd8804779c9c38bb01a82d2f843eeb05845e Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Tue, 18 Aug 2026 13:44:12 +0800 Subject: [PATCH 1/3] Fix crash caused by accessing registry too early --- ...eaves-Fork-cache-item-max-stack-size.patch | 38 +++++++++++++++---- ...-retracting-piston-collision-shapes.patch} | 0 ...nfigurable-locator-bar-max-distance.patch} | 0 3 files changed, 30 insertions(+), 8 deletions(-) rename leaf-server/minecraft-patches/features/{0327-Lithium-Cache-retracting-piston-collision-shapes.patch => 0326-Lithium-Cache-retracting-piston-collision-shapes.patch} (100%) rename leaf-server/minecraft-patches/features/{0327-Configurable-locator-bar-max-distance.patch => 0328-Configurable-locator-bar-max-distance.patch} (100%) diff --git a/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch b/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch index 7a1d27cbf..20b6ff579 100644 --- a/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch +++ b/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch @@ -9,18 +9,31 @@ Original license: GPL-3.0-only Original project: https://github.com/Lumine1909/Leaves_Fork diff --git a/net/minecraft/core/component/PatchedDataComponentMap.java b/net/minecraft/core/component/PatchedDataComponentMap.java -index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..a41e358035655236f4539a9fb2e5e1aff99cecb8 100644 +index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..8bca63d8903fa443754b1cccc1dcf7554f075e77 100644 --- a/net/minecraft/core/component/PatchedDataComponentMap.java +++ b/net/minecraft/core/component/PatchedDataComponentMap.java -@@ -18,6 +18,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -18,8 +18,20 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff private final DataComponentMap prototype; private Reference2ObjectMap, Optional> patch; private boolean copyOnWrite; + private int maxStackSize; // Leaves - cache item max stack size private net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber subscriber; // Leaf - Lithium - equipment tracking ++ // Leaves start - cache item max stack size ++ // This is for ItemStack.EMPTY init ++ // To avoid triggering registry access too early. ++ public PatchedDataComponentMap(final @Nullable Void nullMarker) { ++ this.prototype = DataComponentMap.EMPTY; ++ this.patch = Reference2ObjectMaps.emptyMap(); ++ this.copyOnWrite = true; ++ this.maxStackSize = 1; ++ } ++ // Leaves end - cache item max stack size ++ public PatchedDataComponentMap(final DataComponentMap prototype) { -@@ -30,6 +31,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff + this(prototype, Reference2ObjectMaps.emptyMap(), true); + } +@@ -30,6 +42,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff this.prototype = prototype; this.patch = patch; this.copyOnWrite = copyOnWrite; @@ -28,7 +41,7 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..a41e358035655236f4539a9fb2e5e1af } public static PatchedDataComponentMap fromPatch(final DataComponentMap prototype, final DataComponentPatch patch) { -@@ -77,6 +79,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -77,6 +90,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff lastValue = (Optional)this.patch.put(type, Optional.ofNullable(value)); } @@ -36,7 +49,7 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..a41e358035655236f4539a9fb2e5e1af return lastValue != null ? lastValue.orElse(defaultValue) : defaultValue; } -@@ -94,6 +97,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -94,6 +108,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff lastValue = (Optional)this.patch.remove(type); } @@ -44,7 +57,7 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..a41e358035655236f4539a9fb2e5e1af return (T)(lastValue != null ? lastValue.orElse(null) : defaultValue); } -@@ -118,17 +122,20 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -118,17 +133,20 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff } else { this.patch.remove(type); } @@ -65,7 +78,7 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..a41e358035655236f4539a9fb2e5e1af } public void setAll(final DataComponentMap components) { -@@ -266,4 +273,16 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -266,4 +284,16 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff public String toString() { return "{" + this.stream().map(TypedDataComponent::toString).collect(Collectors.joining(", ")) + "}"; } @@ -83,9 +96,18 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..a41e358035655236f4539a9fb2e5e1af + // Leaves end - cache item max stack size } diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java -index 006a3c8bf13d93570e264added86a179dc90f7fb..3707037438162daec6535e7e5c5bfab6d365bd53 100644 +index 006a3c8bf13d93570e264added86a179dc90f7fb..a8fdf479302f614f392f7889925bfcdd3eb0c715 100644 --- a/net/minecraft/world/item/ItemStack.java +++ b/net/minecraft/world/item/ItemStack.java +@@ -282,7 +282,7 @@ public final class ItemStack implements DataComponentHolder, ItemInstance, net.c + + private ItemStack(final @Nullable Void nullMarker) { + this.item = null; +- this.components = new PatchedDataComponentMap(DataComponentMap.EMPTY); ++ this.components = new PatchedDataComponentMap((Void) null); // Leaves - cache item max stack size + } + + private static DataResult validateComponents(final DataComponentMap components) { @@ -1372,6 +1372,13 @@ public final class ItemStack implements DataComponentHolder, ItemInstance, net.c return this.getCount(); } diff --git a/leaf-server/minecraft-patches/features/0327-Lithium-Cache-retracting-piston-collision-shapes.patch b/leaf-server/minecraft-patches/features/0326-Lithium-Cache-retracting-piston-collision-shapes.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0327-Lithium-Cache-retracting-piston-collision-shapes.patch rename to leaf-server/minecraft-patches/features/0326-Lithium-Cache-retracting-piston-collision-shapes.patch diff --git a/leaf-server/minecraft-patches/features/0327-Configurable-locator-bar-max-distance.patch b/leaf-server/minecraft-patches/features/0328-Configurable-locator-bar-max-distance.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0327-Configurable-locator-bar-max-distance.patch rename to leaf-server/minecraft-patches/features/0328-Configurable-locator-bar-max-distance.patch From b6aa363123a66102fa139aaec8852ed1400fc3aa Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Tue, 18 Aug 2026 16:15:44 +0800 Subject: [PATCH 2/3] Use better approach Thanks to Lumine!!! --- ...eaves-Fork-cache-item-max-stack-size.patch | 44 ++++++------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch b/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch index 20b6ff579..84bec4ae1 100644 --- a/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch +++ b/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch @@ -9,39 +9,30 @@ Original license: GPL-3.0-only Original project: https://github.com/Lumine1909/Leaves_Fork diff --git a/net/minecraft/core/component/PatchedDataComponentMap.java b/net/minecraft/core/component/PatchedDataComponentMap.java -index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..8bca63d8903fa443754b1cccc1dcf7554f075e77 100644 +index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..99e814bd6db6f2ca25dcde210381fcc8128c6893 100644 --- a/net/minecraft/core/component/PatchedDataComponentMap.java +++ b/net/minecraft/core/component/PatchedDataComponentMap.java -@@ -18,8 +18,20 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -18,6 +18,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff private final DataComponentMap prototype; private Reference2ObjectMap, Optional> patch; private boolean copyOnWrite; + private int maxStackSize; // Leaves - cache item max stack size private net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber subscriber; // Leaf - Lithium - equipment tracking -+ // Leaves start - cache item max stack size -+ // This is for ItemStack.EMPTY init -+ // To avoid triggering registry access too early. -+ public PatchedDataComponentMap(final @Nullable Void nullMarker) { -+ this.prototype = DataComponentMap.EMPTY; -+ this.patch = Reference2ObjectMaps.emptyMap(); -+ this.copyOnWrite = true; -+ this.maxStackSize = 1; -+ } -+ // Leaves end - cache item max stack size -+ public PatchedDataComponentMap(final DataComponentMap prototype) { - this(prototype, Reference2ObjectMaps.emptyMap(), true); - } -@@ -30,6 +42,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -30,6 +31,11 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff this.prototype = prototype; this.patch = patch; this.copyOnWrite = copyOnWrite; -+ this.detectMaxStackSizeChange(null); // Leaves - cache item max stack size ++ // Leaves start - cache item max stack size ++ if (!prototype.isEmpty() || !patch.isEmpty()) { ++ detectMaxStackSizeChange(null); ++ } ++ // Leaves end - cache item max stack size } public static PatchedDataComponentMap fromPatch(final DataComponentMap prototype, final DataComponentPatch patch) { -@@ -77,6 +90,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -77,6 +83,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff lastValue = (Optional)this.patch.put(type, Optional.ofNullable(value)); } @@ -49,7 +40,7 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..8bca63d8903fa443754b1cccc1dcf755 return lastValue != null ? lastValue.orElse(defaultValue) : defaultValue; } -@@ -94,6 +108,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -94,6 +101,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff lastValue = (Optional)this.patch.remove(type); } @@ -57,7 +48,7 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..8bca63d8903fa443754b1cccc1dcf755 return (T)(lastValue != null ? lastValue.orElse(null) : defaultValue); } -@@ -118,17 +133,20 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -118,17 +126,20 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff } else { this.patch.remove(type); } @@ -78,7 +69,7 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..8bca63d8903fa443754b1cccc1dcf755 } public void setAll(final DataComponentMap components) { -@@ -266,4 +284,16 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -266,4 +277,16 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff public String toString() { return "{" + this.stream().map(TypedDataComponent::toString).collect(Collectors.joining(", ")) + "}"; } @@ -96,18 +87,9 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..8bca63d8903fa443754b1cccc1dcf755 + // Leaves end - cache item max stack size } diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java -index 006a3c8bf13d93570e264added86a179dc90f7fb..a8fdf479302f614f392f7889925bfcdd3eb0c715 100644 +index 006a3c8bf13d93570e264added86a179dc90f7fb..3707037438162daec6535e7e5c5bfab6d365bd53 100644 --- a/net/minecraft/world/item/ItemStack.java +++ b/net/minecraft/world/item/ItemStack.java -@@ -282,7 +282,7 @@ public final class ItemStack implements DataComponentHolder, ItemInstance, net.c - - private ItemStack(final @Nullable Void nullMarker) { - this.item = null; -- this.components = new PatchedDataComponentMap(DataComponentMap.EMPTY); -+ this.components = new PatchedDataComponentMap((Void) null); // Leaves - cache item max stack size - } - - private static DataResult validateComponents(final DataComponentMap components) { @@ -1372,6 +1372,13 @@ public final class ItemStack implements DataComponentHolder, ItemInstance, net.c return this.getCount(); } From 7ffb5264d1b0fa0b117f79424df172268d8e7228 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Wed, 19 Aug 2026 05:33:46 +0800 Subject: [PATCH 3/3] Add default fallback --- ...321-Leaves-Fork-cache-item-max-stack-size.patch | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch b/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch index 84bec4ae1..e5f98e9ed 100644 --- a/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch +++ b/leaf-server/minecraft-patches/features/0321-Leaves-Fork-cache-item-max-stack-size.patch @@ -9,7 +9,7 @@ Original license: GPL-3.0-only Original project: https://github.com/Lumine1909/Leaves_Fork diff --git a/net/minecraft/core/component/PatchedDataComponentMap.java b/net/minecraft/core/component/PatchedDataComponentMap.java -index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..99e814bd6db6f2ca25dcde210381fcc8128c6893 100644 +index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..d685efdb9241e2d82b5a270444d140646d2f4f3b 100644 --- a/net/minecraft/core/component/PatchedDataComponentMap.java +++ b/net/minecraft/core/component/PatchedDataComponentMap.java @@ -18,6 +18,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff @@ -20,19 +20,21 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..99e814bd6db6f2ca25dcde210381fcc8 private net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber subscriber; // Leaf - Lithium - equipment tracking public PatchedDataComponentMap(final DataComponentMap prototype) { -@@ -30,6 +31,11 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -30,6 +31,13 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff this.prototype = prototype; this.patch = patch; this.copyOnWrite = copyOnWrite; + // Leaves start - cache item max stack size + if (!prototype.isEmpty() || !patch.isEmpty()) { + detectMaxStackSizeChange(null); ++ } else { ++ this.maxStackSize = 1; + } + // Leaves end - cache item max stack size } public static PatchedDataComponentMap fromPatch(final DataComponentMap prototype, final DataComponentPatch patch) { -@@ -77,6 +83,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -77,6 +85,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff lastValue = (Optional)this.patch.put(type, Optional.ofNullable(value)); } @@ -40,7 +42,7 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..99e814bd6db6f2ca25dcde210381fcc8 return lastValue != null ? lastValue.orElse(defaultValue) : defaultValue; } -@@ -94,6 +101,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -94,6 +103,7 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff lastValue = (Optional)this.patch.remove(type); } @@ -48,7 +50,7 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..99e814bd6db6f2ca25dcde210381fcc8 return (T)(lastValue != null ? lastValue.orElse(null) : defaultValue); } -@@ -118,17 +126,20 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -118,17 +128,20 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff } else { this.patch.remove(type); } @@ -69,7 +71,7 @@ index b0967af2a3f85dad242ec7475ec9d4f7d7badfc7..99e814bd6db6f2ca25dcde210381fcc8 } public void setAll(final DataComponentMap components) { -@@ -266,4 +277,16 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff +@@ -266,4 +279,16 @@ public final class PatchedDataComponentMap implements DataComponentMap, net.caff public String toString() { return "{" + this.stream().map(TypedDataComponent::toString).collect(Collectors.joining(", ")) + "}"; }