2022-10-09 22:19:35 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 13 Jan 2022 23:05:53 -0800
Subject: [PATCH] Add missing structure set seed configs
The 4 missing structure set seed configs are strongholds, mineshafts,
buried treasure, and ancient cities.
Strongholds use a ring placement scheme which isn't random so they
utilize the world seed by default, this adds a config to override it
for just generating the ring positions.
Mineshafts and Buried Treasure structure sets are special cases
where the "salt" that can be defined for them via datapacks has 0
effect because the difference between the spacing and separation is 1
which is used as the upper bound in the random with salt. So the random
always returns the same int (0) so the salt has no effect. This adds
seeds/salts to the frequency reducer which has a similar effect.
Co-authored-by: William Blake Galbreath <blake.galbreath@gmail.com>
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
2023-03-14 21:55:49 +01:00
index 31955f62253feb111239247c4f8c2215b3080c1d..42ecfc1237bfc724dc9134a6a8bae3670251449e 100644
2022-10-09 22:19:35 +02:00
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
2023-02-28 17:36:01 +01:00
@@ -568,7 +568,7 @@ public abstract class ChunkGenerator {
2022-12-08 20:06:54 +01:00
}
}
- if (structureplacement.isStructureChunk(placementCalculator, chunkcoordintpair.x, chunkcoordintpair.z)) {
2022-12-08 21:15:18 +01:00
+ if (structureplacement.isStructureChunk(placementCalculator, chunkcoordintpair.x, chunkcoordintpair.z, structureplacement instanceof net.minecraft.world.level.chunk.ChunkGeneratorStructureState.KeyedRandomSpreadStructurePlacement keyed ? keyed.key : null)) { // Paper - add missing structure set configs
2022-12-08 20:06:54 +01:00
if (list.size() == 1) {
this.tryGenerateStructure((StructureSet.StructureSelectionEntry) list.get(0), structureAccessor, registryManager, randomstate, structureTemplateManager, placementCalculator.getLevelSeed(), chunk, chunkcoordintpair, sectionposition);
} else {
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
2022-12-08 21:15:18 +01:00
index a310bfbf0d08187375ea17f4b04b276a0b7d0b9f..51a05900d02dc116ea215730713cd2cf2a4f1c23 100644
2022-12-08 20:06:54 +01:00
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
@@ -50,13 +50,14 @@ public class ChunkGeneratorStructureState {
private final Map<ConcentricRingsStructurePlacement, CompletableFuture<List<ChunkPos>>> ringPositions = new Object2ObjectArrayMap();
private boolean hasGeneratedPositions;
private final List<Holder<StructureSet>> possibleStructureSets;
+ public final SpigotWorldConfig conf; // Paper
public static ChunkGeneratorStructureState createForFlat(RandomState randomstate, long i, BiomeSource worldchunkmanager, Stream<Holder<StructureSet>> stream, SpigotWorldConfig conf) { // Spigot
List<Holder<StructureSet>> list = stream.filter((holder) -> {
return ChunkGeneratorStructureState.hasBiomesForStructureSet((StructureSet) holder.value(), worldchunkmanager);
}).toList();
- return new ChunkGeneratorStructureState(randomstate, worldchunkmanager, i, 0L, ChunkGeneratorStructureState.injectSpigot(list, conf)); // Spigot
+ return new ChunkGeneratorStructureState(randomstate, worldchunkmanager, i, 0L, ChunkGeneratorStructureState.injectSpigot(list, conf), conf); // Spigot
}
public static ChunkGeneratorStructureState createForNormal(RandomState randomstate, long i, BiomeSource worldchunkmanager, HolderLookup<StructureSet> holderlookup, SpigotWorldConfig conf) { // Spigot
2022-12-08 21:15:18 +01:00
@@ -64,14 +65,24 @@ public class ChunkGeneratorStructureState {
2022-12-08 20:06:54 +01:00
return ChunkGeneratorStructureState.hasBiomesForStructureSet((StructureSet) holder_c.value(), worldchunkmanager);
}).collect(Collectors.toUnmodifiableList());
- return new ChunkGeneratorStructureState(randomstate, worldchunkmanager, i, i, ChunkGeneratorStructureState.injectSpigot(list, conf)); // Spigot
+ return new ChunkGeneratorStructureState(randomstate, worldchunkmanager, i, i, ChunkGeneratorStructureState.injectSpigot(list, conf), conf); // Spigot
}
2022-12-08 21:15:18 +01:00
+ // Paper start - horrible hack because spigot creates a ton of direct Holders which lose track of the identifying key
+ public static final class KeyedRandomSpreadStructurePlacement extends RandomSpreadStructurePlacement {
+ public final net.minecraft.resources.ResourceKey<StructureSet> key;
+ public KeyedRandomSpreadStructurePlacement(net.minecraft.resources.ResourceKey<StructureSet> key, net.minecraft.core.Vec3i locateOffset, FrequencyReductionMethod frequencyReductionMethod, float frequency, int salt, java.util.Optional<StructurePlacement.ExclusionZone> exclusionZone, int spacing, int separation, net.minecraft.world.level.levelgen.structure.placement.RandomSpreadType spreadType) {
+ super(locateOffset, frequencyReductionMethod, frequency, salt, exclusionZone, spacing, separation, spreadType);
+ this.key = key;
+ }
+ }
+ // Paper end
2022-12-08 20:06:54 +01:00
2022-10-09 22:19:35 +02:00
// Spigot start
2022-12-08 20:06:54 +01:00
private static List<Holder<StructureSet>> injectSpigot(List<Holder<StructureSet>> list, SpigotWorldConfig conf) {
return list.stream().map((holder) -> {
StructureSet structureset = holder.value();
2022-10-09 22:19:35 +02:00
- if (structureset.placement() instanceof RandomSpreadStructurePlacement randomConfig) {
2022-12-08 21:15:18 +01:00
+ final Holder<StructureSet> newHolder; // Paper
2022-12-08 20:06:54 +01:00
+ if (structureset.placement() instanceof RandomSpreadStructurePlacement randomConfig && holder.unwrapKey().orElseThrow().location().getNamespace().equals(net.minecraft.resources.ResourceLocation.DEFAULT_NAMESPACE)) { // Paper - check namespace cause datapacks could add structure sets with the same path
String name = holder.unwrapKey().orElseThrow().location().getPath();
2022-10-09 22:19:35 +02:00
int seed = randomConfig.salt;
2022-12-08 21:15:18 +01:00
@@ -118,11 +129,21 @@ public class ChunkGeneratorStructureState {
2022-10-09 22:19:35 +02:00
case "villages":
seed = conf.villageSeed;
break;
2022-12-08 20:06:54 +01:00
+ // Paper start
2022-10-09 22:19:35 +02:00
+ case "ancient_cities":
+ seed = conf.ancientCitySeed;
+ break;
2022-12-08 20:06:54 +01:00
+ // Paper end
2022-10-09 22:19:35 +02:00
}
2022-12-08 21:15:18 +01:00
- structureset = new StructureSet(structureset.structures(), new RandomSpreadStructurePlacement(randomConfig.locateOffset, randomConfig.frequencyReductionMethod, randomConfig.frequency, seed, randomConfig.exclusionZone, randomConfig.spacing(), randomConfig.separation(), randomConfig.spreadType()));
+ // Paper start
+ structureset = new StructureSet(structureset.structures(), new KeyedRandomSpreadStructurePlacement(holder.unwrapKey().orElseThrow(), randomConfig.locateOffset, randomConfig.frequencyReductionMethod, randomConfig.frequency, seed, randomConfig.exclusionZone, randomConfig.spacing(), randomConfig.separation(), randomConfig.spreadType()));
+ newHolder = Holder.direct(structureset); // I really wish we didn't have to do this here
+ } else {
+ newHolder = holder;
}
- return Holder.direct(structureset);
+ return newHolder;
+ // Paper end
}).collect(Collectors.toUnmodifiableList());
}
// Spigot end
@@ -139,12 +160,13 @@ public class ChunkGeneratorStructureState {
2022-12-08 20:06:54 +01:00
return stream.anyMatch(set::contains);
}
- private ChunkGeneratorStructureState(RandomState noiseConfig, BiomeSource biomeSource, long structureSeed, long concentricRingSeed, List<Holder<StructureSet>> structureSets) {
+ private ChunkGeneratorStructureState(RandomState noiseConfig, BiomeSource biomeSource, long structureSeed, long concentricRingSeed, List<Holder<StructureSet>> structureSets, SpigotWorldConfig conf) { // Paper
this.randomState = noiseConfig;
this.levelSeed = structureSeed;
this.biomeSource = biomeSource;
this.concentricRingsSeed = concentricRingSeed;
this.possibleStructureSets = structureSets;
+ this.conf = conf; // Paper
}
public List<Holder<StructureSet>> possibleStructureSets() {
2022-12-08 21:15:18 +01:00
@@ -198,7 +220,13 @@ public class ChunkGeneratorStructureState {
2022-12-08 20:06:54 +01:00
HolderSet<Biome> holderset = placement.preferredBiomes();
2022-10-09 22:19:35 +02:00
RandomSource randomsource = RandomSource.create();
+ // Paper start
2022-12-08 20:06:54 +01:00
+ if (this.conf.strongholdSeed != null && structureSetEntry.is(net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.STRONGHOLDS)) {
2022-10-09 22:19:35 +02:00
+ randomsource.setSeed(this.conf.strongholdSeed);
+ } else {
+ // Paper end
2022-12-08 20:06:54 +01:00
randomsource.setSeed(this.concentricRingsSeed);
+ } // Paper
2022-10-09 22:19:35 +02:00
double d0 = randomsource.nextDouble() * 3.141592653589793D * 2.0D;
int l = 0;
int i1 = 0;
2022-12-08 21:15:18 +01:00
@@ -275,7 +303,7 @@ public class ChunkGeneratorStructureState {
2022-12-08 20:06:54 +01:00
for (int l = centerChunkX - chunkCount; l <= centerChunkX + chunkCount; ++l) {
for (int i1 = centerChunkZ - chunkCount; i1 <= centerChunkZ + chunkCount; ++i1) {
- if (structureplacement.isStructureChunk(this, l, i1)) {
2022-12-08 21:15:18 +01:00
+ if (structureplacement.isStructureChunk(this, l, i1, structureplacement instanceof KeyedRandomSpreadStructurePlacement keyed ? keyed.key : null)) { // Paper - add missing structure set configs
2022-12-08 20:06:54 +01:00
return true;
2022-10-09 22:19:35 +02:00
}
}
diff --git a/src/main/java/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java b/src/main/java/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
2022-12-08 21:15:18 +01:00
index 65dcb14241baadb2c9f8f16919d7b562198ad9c3..594a2dd3b1d4c29c969d1992b8e93795da00e682 100644
2022-10-09 22:19:35 +02:00
--- a/src/main/java/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
+++ b/src/main/java/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
2022-12-08 20:06:54 +01:00
@@ -59,10 +59,24 @@ public abstract class StructurePlacement {
2022-10-09 22:19:35 +02:00
return this.exclusionZone;
}
+ @Deprecated @io.papermc.paper.annotation.DoNotUse // Paper
2022-12-08 20:06:54 +01:00
public boolean isStructureChunk(ChunkGeneratorStructureState calculator, int chunkX, int chunkZ) {
2022-10-09 22:19:35 +02:00
+ // Paper start - add missing structure set configs
2022-12-08 20:06:54 +01:00
+ return this.isStructureChunk(calculator, chunkX, chunkZ, null);
2022-10-09 22:19:35 +02:00
+ }
2022-12-08 21:15:18 +01:00
+ public boolean isStructureChunk(ChunkGeneratorStructureState calculator, int chunkX, int chunkZ, @org.jetbrains.annotations.Nullable net.minecraft.resources.ResourceKey<StructureSet> structureSetKey) {
2022-10-09 22:19:35 +02:00
+ Integer saltOverride = null;
2022-12-08 21:15:18 +01:00
+ if (structureSetKey != null) {
+ if (structureSetKey == net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.MINESHAFTS) {
2022-12-08 20:06:54 +01:00
+ saltOverride = calculator.conf.mineshaftSeed;
2022-12-08 21:15:18 +01:00
+ } else if (structureSetKey == net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.BURIED_TREASURES) {
2022-12-08 20:06:54 +01:00
+ saltOverride = calculator.conf.buriedTreasureSeed;
+ }
2022-10-09 22:19:35 +02:00
+ }
+ // Paper end
2022-12-08 20:06:54 +01:00
if (!this.isPlacementChunk(calculator, chunkX, chunkZ)) {
2022-10-09 22:19:35 +02:00
return false;
2022-12-08 20:06:54 +01:00
- } else if (this.frequency < 1.0F && !this.frequencyReductionMethod.shouldGenerate(calculator.getLevelSeed(), this.salt, chunkX, chunkZ, this.frequency)) {
+ } else if (this.frequency < 1.0F && !this.frequencyReductionMethod.shouldGenerate(calculator.getLevelSeed(), this.salt, chunkX, chunkZ, this.frequency, saltOverride)) { // Paper
2022-10-09 22:19:35 +02:00
return false;
} else {
2022-12-08 20:06:54 +01:00
return !this.exclusionZone.isPresent() || !this.exclusionZone.get().isPlacementForbidden(calculator, chunkX, chunkZ);
@@ -77,25 +91,31 @@ public abstract class StructurePlacement {
2022-10-09 22:19:35 +02:00
public abstract StructurePlacementType<?> type();
- private static boolean probabilityReducer(long seed, int salt, int chunkX, int chunkZ, float frequency) {
+ private static boolean probabilityReducer(long seed, int salt, int chunkX, int chunkZ, float frequency, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - ignore here
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
worldgenRandom.setLargeFeatureWithSalt(seed, salt, chunkX, chunkZ);
return worldgenRandom.nextFloat() < frequency;
}
- private static boolean legacyProbabilityReducerWithDouble(long seed, int salt, int chunkX, int chunkZ, float frequency) {
+ private static boolean legacyProbabilityReducerWithDouble(long seed, int salt, int chunkX, int chunkZ, float frequency, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
+ if (saltOverride == null) { // Paper
worldgenRandom.setLargeFeatureSeed(seed, chunkX, chunkZ);
+ // Paper start
+ } else {
+ worldgenRandom.setLargeFeatureWithSalt(seed, chunkX, chunkZ, saltOverride);
+ }
+ // Paper end
return worldgenRandom.nextDouble() < (double)frequency;
}
- private static boolean legacyArbitrarySaltProbabilityReducer(long seed, int salt, int chunkX, int chunkZ, float frequency) {
+ private static boolean legacyArbitrarySaltProbabilityReducer(long seed, int salt, int chunkX, int chunkZ, float frequency, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
- worldgenRandom.setLargeFeatureWithSalt(seed, chunkX, chunkZ, 10387320);
2022-12-08 21:15:18 +01:00
+ worldgenRandom.setLargeFeatureWithSalt(seed, chunkX, chunkZ, saltOverride != null ? saltOverride : HIGHLY_ARBITRARY_RANDOM_SALT); // Paper
2022-10-09 22:19:35 +02:00
return worldgenRandom.nextFloat() < frequency;
}
- private static boolean legacyPillagerOutpostReducer(long seed, int salt, int chunkX, int chunkZ, float frequency) {
+ private static boolean legacyPillagerOutpostReducer(long seed, int salt, int chunkX, int chunkZ, float frequency, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - ignore here
int i = chunkX >> 4;
int j = chunkZ >> 4;
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
2022-12-08 20:06:54 +01:00
@@ -118,7 +138,7 @@ public abstract class StructurePlacement {
2022-10-09 22:19:35 +02:00
@FunctionalInterface
public interface FrequencyReducer {
- boolean shouldGenerate(long seed, int salt, int chunkX, int chunkZ, float chance);
+ boolean shouldGenerate(long seed, int salt, int chunkX, int chunkZ, float chance, @org.jetbrains.annotations.Nullable Integer saltOverride); // Paper
}
public static enum FrequencyReductionMethod implements StringRepresentable {
2022-12-08 20:06:54 +01:00
@@ -136,8 +156,8 @@ public abstract class StructurePlacement {
2022-10-09 22:19:35 +02:00
this.reducer = generationPredicate;
}
- public boolean shouldGenerate(long seed, int salt, int chunkX, int chunkZ, float chance) {
- return this.reducer.shouldGenerate(seed, salt, chunkX, chunkZ, chance);
+ public boolean shouldGenerate(long seed, int salt, int chunkX, int chunkZ, float chance, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper
+ return this.reducer.shouldGenerate(seed, salt, chunkX, chunkZ, chance, saltOverride); // Paper
}
@Override
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2023-05-12 13:10:08 +02:00
index fb1495f9afe87ad80098beedbaa44efb66e36bca..39a823c03c9542a193b6c9555a01a1562be7d339 100644
2022-10-09 22:19:35 +02:00
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2023-05-12 13:10:08 +02:00
@@ -364,6 +364,16 @@ public class SpigotWorldConfig
2022-10-09 22:19:35 +02:00
public int mansionSeed;
public int fossilSeed;
public int portalSeed;
+ // Paper start - add missing structure set configs
+ public int ancientCitySeed;
+ public int buriedTreasureSeed;
+ public Integer mineshaftSeed;
+ public Long strongholdSeed;
+ private <N extends Number> N getSeed(String path, java.util.function.Function<String, N> toNumberFunc) {
+ final String value = this.getString(path, "default");
+ return org.apache.commons.lang3.math.NumberUtils.isParsable(value) ? toNumberFunc.apply(value) : null;
+ }
+ // Paper end
private void initWorldGenSeeds()
{
this.villageSeed = this.getInt( "seed-village", 10387312 );
2023-05-12 13:10:08 +02:00
@@ -381,6 +391,12 @@ public class SpigotWorldConfig
2022-10-09 22:19:35 +02:00
this.mansionSeed = this.getInt( "seed-mansion", 10387319 );
this.fossilSeed = this.getInt( "seed-fossil", 14357921 );
this.portalSeed = this.getInt( "seed-portal", 34222645 );
+ // Paper start - add missing structure set configs
+ this.ancientCitySeed = this.getInt("seed-ancientcity", 20083232);
+ this.buriedTreasureSeed = this.getInt("seed-buriedtreasure", 10387320); // StructurePlacement#HIGHLY_ARBITRARY_RANDOM_SALT
+ this.mineshaftSeed = this.getSeed("seed-mineshaft", Integer::parseInt);
+ this.strongholdSeed = this.getSeed("seed-stronghold", Long::parseLong);
+ // Paper end
this.log( "Custom Map Seeds: Village: " + this.villageSeed + " Desert: " + this.desertSeed + " Igloo: " + this.iglooSeed + " Jungle: " + this.jungleSeed + " Swamp: " + this.swampSeed + " Monument: " + this.monumentSeed
+ " Ocean: " + this.oceanSeed + " Shipwreck: " + this.shipwreckSeed + " End City: " + this.endCitySeed + " Slime: " + this.slimeSeed + " Nether: " + this.netherSeed + " Mansion: " + this.mansionSeed + " Fossil: " + this.fossilSeed + " Portal: " + this.portalSeed );
}