2021-09-01 11:54:41 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nassim Jahnke <jahnke.nassim@gmail.com>
Date: Tue, 31 Aug 2021 17:05:27 +0200
Subject: [PATCH] Configurable feature seeds
Co-authored-by: Thonk <30448663+ExcessiveAmountsOfZombies@users.noreply.github.com>
2021-09-14 15:31:45 +02:00
diff --git a/src/main/java/co/aikar/timings/TimingsExport.java b/src/main/java/co/aikar/timings/TimingsExport.java
2021-11-25 13:05:53 +01:00
index ee53453440177537fc653ea156785d7591498614..5e3b7fb2e0b7608610555cd23e7ad25a05883181 100644
2021-09-14 15:31:45 +02:00
--- a/src/main/java/co/aikar/timings/TimingsExport.java
+++ b/src/main/java/co/aikar/timings/TimingsExport.java
2021-11-25 13:05:53 +01:00
@@ -273,7 +273,7 @@ public class TimingsExport extends Thread {
2021-09-14 15:31:45 +02:00
JSONObject object = new JSONObject();
for (String key : config.getKeys(false)) {
String fullKey = (parentKey != null ? parentKey + "." + key : key);
- if (fullKey.equals("database") || fullKey.equals("settings.bungeecord-addresses") || TimingsManager.hiddenConfigs.contains(fullKey) || key.startsWith("seed-") || key.equals("worldeditregentempworld")) {
+ if (fullKey.equals("database") || fullKey.equals("settings.bungeecord-addresses") || TimingsManager.hiddenConfigs.contains(fullKey) || key.startsWith("seed-") || key.equals("worldeditregentempworld") || key.equals("feature-seeds")) {
continue;
}
final Object val = config.get(key);
2021-09-01 11:54:41 +02:00
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2021-12-01 02:31:13 +01:00
index 6dc4c20464783c021104f5f20e76eca48323e81f..21e502716f312849b5232d1a3c5c87dc76394fee 100644
2021-09-01 11:54:41 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2021-12-01 02:31:13 +01:00
@@ -946,6 +946,55 @@ public class PaperWorldConfig {
2021-09-01 11:54:41 +02:00
return table;
}
+ public it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<net.minecraft.resources.ResourceLocation> featureSeeds = new it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<>();
+ private void featureSeeds() {
+ featureSeeds.defaultReturnValue(-1);
+ final boolean randomise = getBoolean("feature-seeds.generate-random-seeds-for-all", false);
+ final ConfigurationSection defaultSection = config.getConfigurationSection("world-settings.default.feature-seeds");
+ final ConfigurationSection section = config.getConfigurationSection("world-settings." + worldName + ".feature-seeds");
+ final net.minecraft.core.Registry<net.minecraft.world.level.levelgen.feature.ConfiguredFeature<?, ?>> registry
+ = net.minecraft.server.MinecraftServer.getServer().registryAccess().registryOrThrow(net.minecraft.core.Registry.CONFIGURED_FEATURE_REGISTRY);
+ if (section != null) {
+ loadFeatureSeeds(section, registry);
+ }
+
+ // Also use default set seeds if not already set per world
+ loadFeatureSeeds(defaultSection, registry);
+
+ if (randomise) {
+ final Map<String, Object> randomisedSeeds = new HashMap<>();
2021-10-19 16:25:04 +02:00
+ final java.util.Random random = new java.security.SecureRandom();
2021-09-01 11:54:41 +02:00
+ for (final net.minecraft.resources.ResourceLocation resourceLocation : registry.keySet()) {
+ if (featureSeeds.containsKey(resourceLocation)) {
+ continue;
+ }
+
+ final long seed = random.nextLong();
+ randomisedSeeds.put("world-settings." + worldName + ".feature-seeds." + resourceLocation.getPath(), seed);
+ featureSeeds.put(resourceLocation, seed);
+ }
+ if (!randomisedSeeds.isEmpty()) {
+ config.addDefaults(randomisedSeeds);
+ }
+ }
+ }
+
+ private void loadFeatureSeeds(final ConfigurationSection section, final net.minecraft.core.Registry<net.minecraft.world.level.levelgen.feature.ConfiguredFeature<?, ?>> registry) {
+ for (final String key : section.getKeys(false)) {
+ if (!(section.get(key) instanceof Number)) {
+ continue;
+ }
+
+ final net.minecraft.resources.ResourceLocation location = new net.minecraft.resources.ResourceLocation(key);
+ if (!registry.containsKey(location)) {
+ logError("Invalid feature resource location: " + location);
+ continue;
+ }
+
+ featureSeeds.putIfAbsent(location, section.getLong(key));
+ }
+ }
+
public int getBehaviorTickRate(String typeName, String entityType, int def) {
return getIntOrDefault(behaviorTickRates, typeName, entityType, def);
}
2021-11-25 13:05:53 +01:00
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
2021-11-26 15:17:28 +01:00
index e2b7da265e9616ac47e6be72cc6e6d2c75cfec44..e4591c0b3c8547cc6f4e2a0891fc378ee4334d9e 100644
2021-11-25 13:05:53 +01:00
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
2021-11-26 15:17:28 +01:00
@@ -277,7 +277,7 @@ public abstract class ChunkGenerator implements BiomeManager.NoiseBiomeSource {
int j = list.size();
2021-09-01 11:54:41 +02:00
2021-11-25 13:05:53 +01:00
try {
2021-11-26 15:17:28 +01:00
- Registry<PlacedFeature> iregistry = generatoraccessseed.registryAccess().registryOrThrow(Registry.PLACED_FEATURE_REGISTRY);
+ Registry<PlacedFeature> iregistry = generatoraccessseed.registryAccess().registryOrThrow(Registry.PLACED_FEATURE_REGISTRY); // Paper - diff on change
Registry<StructureFeature<?>> iregistry1 = generatoraccessseed.registryAccess().registryOrThrow(Registry.STRUCTURE_FEATURE_REGISTRY);
2021-11-25 13:05:53 +01:00
int k = Math.max(GenerationStep.Decoration.values().length, j);
2021-09-01 11:54:41 +02:00
2021-11-26 15:17:28 +01:00
@@ -351,7 +351,15 @@ public abstract class ChunkGenerator implements BiomeManager.NoiseBiomeSource {
return (String) optional.orElseGet(placedfeature::toString);
};
2021-11-25 13:05:53 +01:00
2021-11-26 15:17:28 +01:00
- seededrandom.setFeatureSeed(i, l1, l);
2021-11-25 13:05:53 +01:00
+ // Paper start - change populationSeed used in random
+ long featurePopulationSeed = i;
2021-11-26 15:17:28 +01:00
+ final net.minecraft.resources.ResourceLocation location = iregistry.getKey(placedfeature);
2021-11-25 13:05:53 +01:00
+ final long configFeatureSeed = generatoraccessseed.getMinecraftWorld().paperConfig.featureSeeds.getLong(location);
+ if (configFeatureSeed != -1) {
+ featurePopulationSeed = seededrandom.setDecorationSeed(configFeatureSeed, blockposition.getX(), blockposition.getZ()); // See seededrandom.setDecorationSeed from above
+ }
2021-11-26 15:17:28 +01:00
+ seededrandom.setFeatureSeed(featurePopulationSeed, l1, l);
2021-11-25 13:05:53 +01:00
+ // Paper end
2021-09-01 11:54:41 +02:00
2021-11-26 15:17:28 +01:00
try {
generatoraccessseed.setCurrentlyGenerating(supplier1);