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>
This commit is contained in:
@@ -322,6 +322,18 @@ 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 trialChambersSeed;
|
||||
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 );
|
||||
@@ -339,6 +351,14 @@ 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.trialChambersSeed = this.getInt("seed-trialchambers", 94251327);
|
||||
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 );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
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.RegistryHelper;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.spigotmc.SpigotConfig;
|
||||
import org.spigotmc.SpigotWorldConfig;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@AllFeatures
|
||||
public class StructureSeedConfigTest {
|
||||
|
||||
@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 = RegistryHelper.getRegistry().lookupOrThrow(Registries.STRUCTURE_SET);
|
||||
for (final ResourceKey<StructureSet> setKey : structureSets.registryKeySet()) {
|
||||
assertEquals(ResourceLocation.DEFAULT_NAMESPACE, setKey.location().getNamespace());
|
||||
final StructureSet set = structureSets.getValueOrThrow(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;
|
||||
case "trial_chambers" -> config.trialChambersSeed;
|
||||
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(field.get(null), salt, "Mismatched default seed for " + setKey + ". Should be " + field.get(null));
|
||||
continue;
|
||||
}
|
||||
assertEquals(set.placement().salt, salt, "Mismatched default seed for " + setKey + ". Should be " + set.placement().salt);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user