Files
Shiroha/shiroha-server/minecraft-patches/features/0068-Leaf-Lithium-faster-hash-palette.patch
T
NanaChiyo0721 1bb895c165
Shiroha CI / build (push) Canceled after 0s
Shiroha CI / Event File (push) Canceled after 0s
Fix incorrect ticket lock size computing
Yeah this would fully solve the issue of chunk unloading race condition

The same fix was already initially added at "Force clamp grid-exponent to 1~6"
2026-08-09 14:57:32 +08:00

84 lines
5.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NanaChiyo0721 <nanachiyo0721@163.com>
Date: Mon, 20 Jul 2026 20:41:53 +0800
Subject: [PATCH] Leaf: Lithium: faster hash palette
This is a part of Leaf(https://github.com/Winds-Studio/Leaf/blob/8293ae2d0ada9df24e944f755b50e93208c1496d/leaf-server/minecraft-patches/features/0281-Lithium-faster-hash-palette.patch)
Original proj license: https://github.com/Winds-Studio/Leaf/blob/8293ae2d0ada9df24e944f755b50e93208c1496d/LICENSE.md
This patch is based on the following mixins:
* "net/caffeinemc/mods/lithium/mixin/chunk/palette/StrategyMixin.java"
By: 2No2Name <2No2Name@web.de>
As part of: Lithium (https://github.com/CaffeineMC/lithium)
Licensed under: LGPL-3.0-only (https://www.gnu.org/licenses/lgpl-3.0.html)
diff --git a/net/minecraft/world/level/chunk/HashMapPalette.java b/net/minecraft/world/level/chunk/HashMapPalette.java
index 3ee35885ea1f997bb5a36dd8d5f83b168883ba61..2cee753e9927f04d8c77e179f34442ef8469de76 100644
--- a/net/minecraft/world/level/chunk/HashMapPalette.java
+++ b/net/minecraft/world/level/chunk/HashMapPalette.java
@@ -14,7 +14,7 @@ public class HashMapPalette<T> implements Palette<T>, ca.spottedleaf.moonrise.pa
// Paper start - optimise palette reads
@Override
- public final T[] moonrise$getRawPalette(final ca.spottedleaf.moonrise.patches.fast_palette.FastPaletteData<T> container) {
+ public T[] moonrise$getRawPalette(final ca.spottedleaf.moonrise.patches.fast_palette.FastPaletteData<T> container) { // Leaf - Lithium - faster hash palette - public final -> public
return ((ca.spottedleaf.moonrise.patches.fast_palette.FastPalette<T>)this.values).moonrise$getRawPalette(container);
}
// Paper end - optimise palette reads
@@ -28,6 +28,14 @@ public class HashMapPalette<T> implements Palette<T>, ca.spottedleaf.moonrise.pa
this(bits, CrudeIncrementalIntIdentityHashBiMap.create((1 << bits) + 1)); // Paper - Perf: Avoid unnecessary resize operation in CrudeIncrementalIntIdentityHashBiMap
}
+ // Leaf start - Lithium - faster hash palette
+ protected HashMapPalette(int bits, boolean dummy) {
+ this.bits = bits;
+ //noinspection DataFlowIssue
+ this.values = dummy ? null : CrudeIncrementalIntIdentityHashBiMap.create((1 << bits) + 1);
+ }
+ // Leaf end - Lithium - faster hash palette
+
private HashMapPalette(final int bits, final CrudeIncrementalIntIdentityHashBiMap<T> values) {
this.bits = bits;
this.values = values;
diff --git a/net/minecraft/world/level/chunk/Strategy.java b/net/minecraft/world/level/chunk/Strategy.java
index 958be147cd940ac430576ca5b4ada70fa5d051e3..d88f93a581c7087540872e8ad0e82d1d3f676db2 100644
--- a/net/minecraft/world/level/chunk/Strategy.java
+++ b/net/minecraft/world/level/chunk/Strategy.java
@@ -4,6 +4,15 @@ import net.minecraft.core.IdMap;
import net.minecraft.util.Mth;
public abstract class Strategy<T> {
+ // Leaf start - Lithium - faster hash palette
+ private static final Palette.Factory HASH = net.caffeinemc.mods.lithium.common.world.chunk.LithiumHashPalette::create;
+ //private static final Configuration HASH_3BIT = new Configuration.Simple(HASH, 3);
+ private static final Configuration HASH_4BIT = new Configuration.Simple(HASH, 4);
+ private static final Configuration HASH_5BIT = new Configuration.Simple(HASH, 5);
+ private static final Configuration HASH_6BIT = new Configuration.Simple(HASH, 6);
+ private static final Configuration HASH_7BIT = new Configuration.Simple(HASH, 7);
+ private static final Configuration HASH_8BIT = new Configuration.Simple(HASH, 8);
+ // Leaf end - Lithium - faster hash palette
public static final Palette.Factory SINGLE_VALUE_PALETTE_FACTORY = SingleValuePalette::create; // Paper - Anti-Xray
private static final Palette.Factory LINEAR_PALETTE_FACTORY = LinearPalette::create;
private static final Palette.Factory HASHMAP_PALETTE_FACTORY = HashMapPalette::create;
@@ -36,11 +45,14 @@ public abstract class Strategy<T> {
public Configuration getConfigurationForBitCount(final int entryBits) {
return switch (entryBits) {
case 0 -> Strategy.ZERO_BITS;
- case 1, 2, 3, 4 -> Strategy.FOUR_BITS_LINEAR;
- case 5 -> Strategy.FIVE_BITS_HASHMAP;
- case 6 -> Strategy.SIX_BITS_HASHMAP;
- case 7 -> Strategy.SEVEN_BITS_HASHMAP;
- case 8 -> Strategy.EIGHT_BITS_HASHMAP;
+ // Leaf start - Lithium - faster hash palette
+ case 1, 2 -> Strategy.FOUR_BITS_LINEAR;
+ case 3, 4 -> Strategy.HASH_4BIT;
+ case 5 -> Strategy.HASH_5BIT;
+ case 6 -> Strategy.HASH_6BIT;
+ case 7 -> Strategy.HASH_7BIT;
+ case 8 -> Strategy.HASH_8BIT;
+ // Leaf end - Lithium - faster hash palette
default -> new Configuration.Global(this.globalPaletteBitsInMemory, entryBits);
};
}