Files
Shiroha/camellia-server/minecraft-patches/features/0048-Secure-seed-V2-with-Blake3.patch
T
2026-07-09 14:36:37 +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..20536f4ed6d19ec2cc6a54aa9c5c980d2ffea0ef 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(); // Camellia - Add secure seed V2 with Blake3
+ // Camellia start - Add secure seed V2 with Blake3
+ final long[] secureWorldSeed = (moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.enabled && moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.version == 2)
+ ? su.plo.matter.HashingV2.expandLevelSeedTo1024Bits(seed)
+ : null;
+
+ long terrainSeed = (moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.enabled && moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.version == 2)
+ ? su.plo.matter.HashingV2.getTerrainSeed(secureWorldSeed, su.plo.matter.HashingV2.TerrainType.BASE_TERRAIN)
+ : seed;
+ long aquiferSeed = (moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.enabled && moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.version == 2)
+ ? su.plo.matter.HashingV2.getTerrainSeed(secureWorldSeed, su.plo.matter.HashingV2.TerrainType.AQUIFER)
+ : seed;
+ long oreSeed = (moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.enabled && moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.version == 2)
+ ? su.plo.matter.HashingV2.getTerrainSeed(secureWorldSeed, su.plo.matter.HashingV2.TerrainType.ORE)
+ : seed;
+ // Camellia end
+ this.random = settings.getRandomSource().newInstance(terrainSeed).forkPositional(); // Camellia - 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(); // Camellia - Add secure seed V2 with Blake3
+ //this.oreRandom = this.random.fromHashOf(Identifier.withDefaultNamespace("ore")).forkPositional(); // Camellia - Add secure seed V2 with Blake3
+ this.aquiferRandom = settings.getRandomSource().newInstance(aquiferSeed).forkPositional(); // Camellia - Add secure seed V2 with Blake3
+ this.oreRandom = settings.getRandomSource().newInstance(oreSeed).forkPositional(); // Camellia - 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) {
+ // Camellia start - Add secure seed V2 with Blake3
+ if (moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.enabled && moe.monnairealms.camellia.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);
+ }
+ // Camellia 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)// Camellia - Add secure seed V2 with Blake3
+ // Camellia start - Add secure seed V2 with Blake3
+ ? new DensityFunctions.EndIslandDensityFunction((moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.enabled && moe.monnairealms.camellia.config.modules.function.SecureSeedConfig.version == 2)
+ ? su.plo.matter.HashingV2.getTerrainSeed(secureWorldSeed, su.plo.matter.HashingV2.TerrainType.SURFACE)
+ : seed)
+ // Camellia end
+ : function;
}
}