Files
Shiroha/shiroha-server/minecraft-patches/features/0061-Secure-seed-V2-with-Blake3.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

71 lines
5.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Libalpm64 <libalpm@proton.me>
Date: Mon, 2 Mar 2026 00:00:00 +0000
Subject: [PATCH] Secure seed V2 with Blake3
diff --git a/net/minecraft/world/level/levelgen/RandomState.java b/net/minecraft/world/level/levelgen/RandomState.java
index 7b74440fbbe79c018ad59d24b99da0c6d4a9d007..cd81b8e9167cb537b6f880b7d3f0dad15007891e 100644
--- a/net/minecraft/world/level/levelgen/RandomState.java
+++ b/net/minecraft/world/level/levelgen/RandomState.java
@@ -33,10 +33,28 @@ public final class RandomState {
}
private RandomState(final NoiseGeneratorSettings settings, final HolderGetter<NormalNoise.NoiseParameters> noises, final long seed) {
- this.random = settings.getRandomSource().newInstance(seed).forkPositional();
+ // this.random = settings.getRandomSource().newInstance(seed).forkPositional(); // Shiroha - Add secure seed V2 with Blake3
+ // Shiroha start - Add secure seed V2 with Blake3
+ final long[] secureWorldSeed = (io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.enabled && io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.version == 2)
+ ? su.plo.matter.HashingV2.expandLevelSeedTo1024Bits(seed)
+ : null;
+
+ long terrainSeed = (io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.enabled && io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.version == 2)
+ ? su.plo.matter.HashingV2.getTerrainSeed(secureWorldSeed, su.plo.matter.HashingV2.TerrainType.BASE_TERRAIN)
+ : seed;
+ long aquiferSeed = (io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.enabled && io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.version == 2)
+ ? su.plo.matter.HashingV2.getTerrainSeed(secureWorldSeed, su.plo.matter.HashingV2.TerrainType.AQUIFER)
+ : seed;
+ long oreSeed = (io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.enabled && io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.version == 2)
+ ? su.plo.matter.HashingV2.getTerrainSeed(secureWorldSeed, su.plo.matter.HashingV2.TerrainType.ORE)
+ : seed;
+ // Shiroha end
+ this.random = settings.getRandomSource().newInstance(terrainSeed).forkPositional(); // Shiroha - Add secure seed V2 with Blake3
this.noises = noises;
- this.aquiferRandom = this.random.fromHashOf(Identifier.withDefaultNamespace("aquifer")).forkPositional();
- this.oreRandom = this.random.fromHashOf(Identifier.withDefaultNamespace("ore")).forkPositional();
+ //this.aquiferRandom = this.random.fromHashOf(Identifier.withDefaultNamespace("aquifer")).forkPositional(); // Shiroha - Add secure seed V2 with Blake3
+ //this.oreRandom = this.random.fromHashOf(Identifier.withDefaultNamespace("ore")).forkPositional(); // Shiroha - Add secure seed V2 with Blake3
+ this.aquiferRandom = settings.getRandomSource().newInstance(aquiferSeed).forkPositional(); // Shiroha - Add secure seed V2 with Blake3
+ this.oreRandom = settings.getRandomSource().newInstance(oreSeed).forkPositional(); // Shiroha - Add secure seed V2 with Blake3
this.noiseIntances = new ConcurrentHashMap<>();
this.positionalRandoms = new ConcurrentHashMap<>();
this.surfaceSystem = new SurfaceSystem(this, settings.defaultBlock(), settings.seaLevel(), this.random);
@@ -46,6 +64,12 @@ public final class RandomState {
private final Map<DensityFunction, DensityFunction> wrapped = new HashMap<>();
private RandomSource newLegacyInstance(final long seedOffset) {
+ // Shiroha start - Add secure seed V2 with Blake3
+ if (io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.enabled && io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.version == 2) {
+ long climateSeed = su.plo.matter.HashingV2.getTerrainSeed(secureWorldSeed, su.plo.matter.HashingV2.TerrainType.CLIMATE);
+ return new su.plo.matter.WorldgenCryptoRandom(0, 0, su.plo.matter.Globals.Salt.UNDEFINED, climateSeed + seed);
+ }
+ // Shiroha end
return new LegacyRandomSource(seed + seedOffset);
}
@@ -71,7 +95,13 @@ public final class RandomState {
: RandomState.this.random.fromHashOf(Identifier.withDefaultNamespace("terrain"));
return noise.withNewRandom(terrainRandom);
} else {
- return function instanceof DensityFunctions.EndIslandDensityFunction ? new DensityFunctions.EndIslandDensityFunction(seed) : function;
+ return function instanceof DensityFunctions.EndIslandDensityFunction //? new DensityFunctions.EndIslandDensityFunction(seed)// Shiroha - Add secure seed V2 with Blake3
+ // Shiroha start - Add secure seed V2 with Blake3
+ ? new DensityFunctions.EndIslandDensityFunction((io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.enabled && io.nanachiyo0721.shiroha.config.modules.function.SecureSeedConfig.version == 2)
+ ? su.plo.matter.HashingV2.getTerrainSeed(secureWorldSeed, su.plo.matter.HashingV2.TerrainType.SURFACE)
+ : seed)
+ // Shiroha end
+ : function;
}
}