Add trail ruins structure set seed in spigot config (#9327)

Also adds a server test to ensure the defaults match and that a seed
exists for each structure set
This commit is contained in:
Jake Potrebic 2023-06-17 12:12:23 -07:00 committed by GitHub
parent 3a0373901e
commit 072b78a713
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 11 deletions

View file

@ -933,10 +933,10 @@ index 0000000000000000000000000000000000000000..69add4a7f1147015806bc9b63a8340d1
+}
diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
new file mode 100644
index 0000000000000000000000000000000000000000..f6b9d216c24d8858802f85209fe1a869e5a9be31
index 0000000000000000000000000000000000000000..ad2177cdbc61a6f41c7e2ed81af262d4ffe7d861
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
@@ -0,0 +1,439 @@
@@ -0,0 +1,440 @@
+package io.papermc.paper.configuration;
+
+import com.google.common.base.Suppliers;
@ -1066,7 +1066,8 @@ index 0000000000000000000000000000000000000000..f6b9d216c24d8858802f85209fe1a869
+ See https://docs.papermc.io/paper/configuration for more information.
+ """;
+
+ private static final Supplier<SpigotWorldConfig> SPIGOT_WORLD_DEFAULTS = Suppliers.memoize(() -> new SpigotWorldConfig(RandomStringUtils.randomAlphabetic(255)) {
+ @VisibleForTesting
+ public static final Supplier<SpigotWorldConfig> SPIGOT_WORLD_DEFAULTS = Suppliers.memoize(() -> new SpigotWorldConfig(RandomStringUtils.randomAlphabetic(255)) {
+ @Override // override to ensure "verbose" is false
+ public void init() {
+ SpigotConfig.readConfig(SpigotWorldConfig.class, this);

View file

@ -33,7 +33,7 @@ index eee2239cd715d01c5adbf1cd79282e115f42cd2e..8bab3fcfc6aa6c0b37621474a69f15e9
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
index a310bfbf0d08187375ea17f4b04b276a0b7d0b9f..51a05900d02dc116ea215730713cd2cf2a4f1c23 100644
index a310bfbf0d08187375ea17f4b04b276a0b7d0b9f..f8cd23fb6ea7909b8f30bd21d3f2c7bcc483ef21 100644
--- 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 {
@ -79,7 +79,7 @@ index a310bfbf0d08187375ea17f4b04b276a0b7d0b9f..51a05900d02dc116ea215730713cd2cf
String name = holder.unwrapKey().orElseThrow().location().getPath();
int seed = randomConfig.salt;
@@ -118,11 +129,21 @@ public class ChunkGeneratorStructureState {
@@ -118,11 +129,24 @@ public class ChunkGeneratorStructureState {
case "villages":
seed = conf.villageSeed;
break;
@ -87,6 +87,9 @@ index a310bfbf0d08187375ea17f4b04b276a0b7d0b9f..51a05900d02dc116ea215730713cd2cf
+ case "ancient_cities":
+ seed = conf.ancientCitySeed;
+ break;
+ case "trail_ruins":
+ seed = conf.trailRuinsSeed;
+ break;
+ // Paper end
}
@ -103,7 +106,7 @@ index a310bfbf0d08187375ea17f4b04b276a0b7d0b9f..51a05900d02dc116ea215730713cd2cf
}).collect(Collectors.toUnmodifiableList());
}
// Spigot end
@@ -139,12 +160,13 @@ public class ChunkGeneratorStructureState {
@@ -139,12 +163,13 @@ public class ChunkGeneratorStructureState {
return stream.anyMatch(set::contains);
}
@ -118,7 +121,7 @@ index a310bfbf0d08187375ea17f4b04b276a0b7d0b9f..51a05900d02dc116ea215730713cd2cf
}
public List<Holder<StructureSet>> possibleStructureSets() {
@@ -198,7 +220,13 @@ public class ChunkGeneratorStructureState {
@@ -198,7 +223,13 @@ public class ChunkGeneratorStructureState {
HolderSet<Biome> holderset = placement.preferredBiomes();
RandomSource randomsource = RandomSource.create();
@ -132,7 +135,7 @@ index a310bfbf0d08187375ea17f4b04b276a0b7d0b9f..51a05900d02dc116ea215730713cd2cf
double d0 = randomsource.nextDouble() * 3.141592653589793D * 2.0D;
int l = 0;
int i1 = 0;
@@ -275,7 +303,7 @@ public class ChunkGeneratorStructureState {
@@ -275,7 +306,7 @@ public class ChunkGeneratorStructureState {
for (int l = centerChunkX - chunkCount; l <= centerChunkX + chunkCount; ++l) {
for (int i1 = centerChunkZ - chunkCount; i1 <= centerChunkZ + chunkCount; ++i1) {
@ -229,15 +232,16 @@ index 65dcb14241baadb2c9f8f16919d7b562198ad9c3..594a2dd3b1d4c29c969d1992b8e93795
@Override
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
index 38da4cc3fe3be86e43432de942a1290fa8215474..5638290c72e0daeddfa79fd55e87334fa7d86f72 100644
index 38da4cc3fe3be86e43432de942a1290fa8215474..5b5109e942b18418b3a3a0e2109fe4ef15045fe5 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -368,6 +368,16 @@ public class SpigotWorldConfig
@@ -368,6 +368,17 @@ public class SpigotWorldConfig
public int mansionSeed;
public int fossilSeed;
public int portalSeed;
+ // Paper start - add missing structure set configs
+ public int ancientCitySeed;
+ public int trailRuinsSeed;
+ public int buriedTreasureSeed;
+ public Integer mineshaftSeed;
+ public Long strongholdSeed;
@ -249,12 +253,13 @@ index 38da4cc3fe3be86e43432de942a1290fa8215474..5638290c72e0daeddfa79fd55e87334f
private void initWorldGenSeeds()
{
this.villageSeed = this.getInt( "seed-village", 10387312 );
@@ -385,6 +395,12 @@ public class SpigotWorldConfig
@@ -385,6 +396,13 @@ public class SpigotWorldConfig
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.trailRuinsSeed = this.getInt("seed-trailruins", 83469867);
+ 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);
@ -262,3 +267,83 @@ index 38da4cc3fe3be86e43432de942a1290fa8215474..5638290c72e0daeddfa79fd55e87334f
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 );
}
diff --git a/src/test/java/io/papermc/paper/world/structure/StructureSeedConfigTest.java b/src/test/java/io/papermc/paper/world/structure/StructureSeedConfigTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..9bdf311f625402dcc27262b8b93bee9b7e8ba87a
--- /dev/null
+++ b/src/test/java/io/papermc/paper/world/structure/StructureSeedConfigTest.java
@@ -0,0 +1,74 @@
+package io.papermc.paper.world.structure;
+
+import io.papermc.paper.configuration.PaperConfigurations;
+import java.io.File;
+import java.lang.reflect.Field;
+import net.minecraft.core.Registry;
+import net.minecraft.core.registries.Registries;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.level.levelgen.structure.BuiltinStructureSets;
+import net.minecraft.world.level.levelgen.structure.StructureSet;
+import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.support.AbstractTestingBase;
+import org.jetbrains.annotations.NotNull;
+import org.junit.Test;
+import org.spigotmc.SpigotConfig;
+import org.spigotmc.SpigotWorldConfig;
+
+import static org.junit.Assert.assertEquals;
+
+public class StructureSeedConfigTest extends AbstractTestingBase {
+
+ @Test
+ public void checkStructureSeedDefaults() throws ReflectiveOperationException {
+ SpigotConfig.config = new YamlConfiguration() {
+ @Override
+ public void save(final @NotNull File file) {
+ // no-op
+ }
+ };
+ final SpigotWorldConfig config = PaperConfigurations.SPIGOT_WORLD_DEFAULTS.get();
+
+
+ final Registry<StructureSet> structureSets = AbstractTestingBase.REGISTRY_CUSTOM.registryOrThrow(Registries.STRUCTURE_SET);
+ for (final ResourceKey<StructureSet> setKey : structureSets.registryKeySet()) {
+ assertEquals(ResourceLocation.DEFAULT_NAMESPACE, setKey.location().getNamespace());
+ final StructureSet set = structureSets.getOrThrow(setKey);
+ if (setKey == BuiltinStructureSets.STRONGHOLDS) { // special case due to seed matching world seed
+ assertEquals(0, set.placement().salt);
+ continue;
+ }
+ int salt = switch (setKey.location().getPath()) {
+ case "villages" -> config.villageSeed;
+ case "desert_pyramids" -> config.desertSeed;
+ case "igloos" -> config.iglooSeed;
+ case "jungle_temples" -> config.jungleSeed;
+ case "swamp_huts" -> config.swampSeed;
+ case "pillager_outposts" -> config.outpostSeed;
+ case "ocean_monuments" -> config.monumentSeed;
+ case "woodland_mansions" -> config.mansionSeed;
+ case "buried_treasures" -> config.buriedTreasureSeed;
+ case "mineshafts" -> config.mineshaftSeed == null ? 0 : config.mineshaftSeed; // mineshaft seed is set differently
+ case "ruined_portals" -> config.portalSeed;
+ case "shipwrecks" -> config.shipwreckSeed;
+ case "ocean_ruins" -> config.oceanSeed;
+ case "nether_complexes" -> config.netherSeed;
+ case "nether_fossils" -> config.fossilSeed;
+ case "end_cities" -> config.endCitySeed;
+ case "ancient_cities" -> config.ancientCitySeed;
+ case "trail_ruins" -> config.trailRuinsSeed;
+ default -> throw new AssertionError("Missing structure set seed in SpigotWorldConfig for " + setKey);
+ };
+ if (setKey == BuiltinStructureSets.BURIED_TREASURES) {
+ final Field field = StructurePlacement.class.getDeclaredField("HIGHLY_ARBITRARY_RANDOM_SALT");
+ field.trySetAccessible();
+ assertEquals(0, set.placement().salt);
+ assertEquals("Mismatched default seed for " + setKey + ". Should be " + field.get(null), field.get(null), salt);
+ continue;
+ }
+ assertEquals("Mismatched default seed for " + setKey + ". Should be " + set.placement().salt, set.placement().salt, salt);
+ }
+ }
+}