aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0794-Configurable-feature-seeds.patch
diff options
context:
space:
mode:
authorOwen <[email protected]>2022-03-11 15:13:46 -0500
committerGitHub <[email protected]>2022-03-11 21:13:46 +0100
commitea1efef1164aa7653119eb4be000749930e5b4da (patch)
tree104968ec407cf897e14388b14d2bf397844c8279 /patches/server/0794-Configurable-feature-seeds.patch
parent1790528a6104c7c801e02a6f6d2ec0dda70e2af9 (diff)
downloadPaper-ea1efef1164aa7653119eb4be000749930e5b4da.tar.gz
Paper-ea1efef1164aa7653119eb4be000749930e5b4da.zip
Remove Patches (#7541)
Diffstat (limited to 'patches/server/0794-Configurable-feature-seeds.patch')
-rw-r--r--patches/server/0794-Configurable-feature-seeds.patch110
1 files changed, 110 insertions, 0 deletions
diff --git a/patches/server/0794-Configurable-feature-seeds.patch b/patches/server/0794-Configurable-feature-seeds.patch
new file mode 100644
index 0000000000..31778d1a17
--- /dev/null
+++ b/patches/server/0794-Configurable-feature-seeds.patch
@@ -0,0 +1,110 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Nassim Jahnke <[email protected]>
+Date: Tue, 31 Aug 2021 17:05:27 +0200
+Subject: [PATCH] Configurable feature seeds
+
+Co-authored-by: Thonk <[email protected]>
+
+diff --git a/src/main/java/co/aikar/timings/TimingsExport.java b/src/main/java/co/aikar/timings/TimingsExport.java
+index ee72086b2dee2bd6415803e77825b2b1cb83cd3d..309dbf5fce3ce940d5e1b57d267b9d6b2c5ff5b6 100644
+--- a/src/main/java/co/aikar/timings/TimingsExport.java
++++ b/src/main/java/co/aikar/timings/TimingsExport.java
+@@ -280,7 +280,7 @@ public class TimingsExport extends Thread {
+ 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);
+diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+index 5cae8f1c0d1d9642ad6ee53d9897b28eab02c4cd..ed49f70d6a259dcbc72d9fe8addc42c4717a9e59 100644
+--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
++++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+@@ -941,6 +941,55 @@ public class PaperWorldConfig {
+ 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<>();
++ final java.util.Random random = new java.security.SecureRandom();
++ 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);
+ }
+diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
+index 97b29671a8df6d102be3982443f6f784e2e1d6e1..8bdf3ec461d870204452833bf6f65fe6c35595d8 100644
+--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
++++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
+@@ -527,7 +527,7 @@ public abstract class ChunkGenerator implements BiomeManager.NoiseBiomeSource {
+ int j = list.size();
+
+ try {
+- Registry<PlacedFeature> iregistry1 = generatoraccessseed.registryAccess().registryOrThrow(Registry.PLACED_FEATURE_REGISTRY);
++ Registry<PlacedFeature> iregistry1 = generatoraccessseed.registryAccess().registryOrThrow(Registry.PLACED_FEATURE_REGISTRY); // Paper - diff on change
+ int k = Math.max(GenerationStep.Decoration.values().length, j);
+
+ for (int l = 0; l < k; ++l) {
+@@ -600,7 +600,15 @@ public abstract class ChunkGenerator implements BiomeManager.NoiseBiomeSource {
+ return (String) optional.orElseGet(placedfeature::toString);
+ };
+
+- seededrandom.setFeatureSeed(i, l1, l);
++ // Paper start - change populationSeed used in random
++ long featurePopulationSeed = i;
++ final net.minecraft.resources.ResourceLocation location = iregistry1.getKey(placedfeature);
++ 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
++ }
++ seededrandom.setFeatureSeed(featurePopulationSeed, l1, l);
++ // Paper end
+
+ try {
+ generatoraccessseed.setCurrentlyGenerating(supplier1);