mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
Fast BiomeManager seed obfuscation
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||||
|
Date: Tue, 9 Nov 2077 00:00:00 +0800
|
||||||
|
Subject: [PATCH] Fast BiomeManager seed obfuscation
|
||||||
|
|
||||||
|
Pretty tiny optimization, but better than nothing
|
||||||
|
|
||||||
|
diff --git a/net/minecraft/world/level/biome/BiomeManager.java b/net/minecraft/world/level/biome/BiomeManager.java
|
||||||
|
index 00122472991ba0c1a0ea77053aad71cdfa92a7bd..2d3cfa8659d882585b9e698ac8edf5c704623b95 100644
|
||||||
|
--- a/net/minecraft/world/level/biome/BiomeManager.java
|
||||||
|
+++ b/net/minecraft/world/level/biome/BiomeManager.java
|
||||||
|
@@ -34,9 +34,18 @@ public class BiomeManager {
|
||||||
|
// Leaf end - cache getBiome
|
||||||
|
}
|
||||||
|
|
||||||
|
+ // Leaf start - Replace SHA-256 with XXHash
|
||||||
|
+ private static final net.jpountz.xxhash.XXHash64 XXHASH = net.jpountz.xxhash.XXHashFactory.fastestInstance().hash64();
|
||||||
|
public static long obfuscateSeed(long seed) {
|
||||||
|
- return Hashing.sha256().hashLong(seed).asLong();
|
||||||
|
+ if (org.dreeam.leaf.config.modules.opt.FastBiomeManagerSeedObfuscation.enabled) {
|
||||||
|
+ java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocate(8);
|
||||||
|
+ buf.putLong(0, seed);
|
||||||
|
+ return XXHASH.hash(buf, org.dreeam.leaf.config.modules.opt.FastBiomeManagerSeedObfuscation.seedObfuscationKey);
|
||||||
|
+ } else {
|
||||||
|
+ return Hashing.sha256().hashLong(seed).asLong();
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
+ // Leaf end - Replace SHA-256 with XXHash
|
||||||
|
|
||||||
|
public BiomeManager withDifferentSource(BiomeManager.NoiseBiomeSource newSource) {
|
||||||
|
return new BiomeManager(newSource, this.biomeZoomSeed);
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package org.dreeam.leaf.config.modules.opt;
|
||||||
|
|
||||||
|
import org.dreeam.leaf.config.ConfigModules;
|
||||||
|
import org.dreeam.leaf.config.EnumConfigCategory;
|
||||||
|
import org.dreeam.leaf.config.annotations.Experimental;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
public class FastBiomeManagerSeedObfuscation extends ConfigModules {
|
||||||
|
|
||||||
|
public String getBasePath() {
|
||||||
|
return EnumConfigCategory.PERF.getBaseKeyName() + ".fast-biome-manager-seed-obfuscation";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Experimental
|
||||||
|
public static boolean enabled = false;
|
||||||
|
public static long seedObfuscationKey = ThreadLocalRandom.current().nextLong();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoaded() {
|
||||||
|
enabled = config.getBoolean(getBasePath() + ".enabled", enabled,
|
||||||
|
config.pickStringRegionBased(
|
||||||
|
"""
|
||||||
|
**EXPERMIENTAL FEATURE**
|
||||||
|
Replace vanilla SHA-256 seed obfuscation in BiomeManager with XXHash.""",
|
||||||
|
"""
|
||||||
|
**实验性功能**
|
||||||
|
将原版 BiomeManager 的 SHA-256 种子混淆换成 XXHash."""));
|
||||||
|
seedObfuscationKey = config.getLong(getBasePath() + ".seed-obfuscation-key", seedObfuscationKey,
|
||||||
|
config.pickStringRegionBased(
|
||||||
|
"Seed obfuscation key for XXHash.",
|
||||||
|
"XXHash 的混淆种子."));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user