From e1c2939c11184b2d337d28086a8030104b9e34cb Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 9 Jun 2022 13:16:00 +0200 Subject: [PATCH] Update configurable feature seed patch --- patches/server/0004-Paper-config-files.patch | 45 ++++++++++++++----- patches/server/0009-Paper-command.patch | 4 +- patches/server/0011-Paper-Metrics.patch | 6 +-- patches/server/0353-Anti-Xray.patch | 4 +- ...-Add-tick-times-API-and-mspt-command.patch | 4 +- .../0783-Configurable-feature-seeds.patch | 16 ++----- 6 files changed, 45 insertions(+), 34 deletions(-) diff --git a/patches/server/0004-Paper-config-files.patch b/patches/server/0004-Paper-config-files.patch index fcd4ab6b8b..1afd2ccde1 100644 --- a/patches/server/0004-Paper-config-files.patch +++ b/patches/server/0004-Paper-config-files.patch @@ -743,10 +743,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..6c19825de43b82ba3fe6e44123e7d24748698614 +index 0000000000000000000000000000000000000000..aa52663a65381f175411a37f9b0731de5ed772aa --- /dev/null +++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java -@@ -0,0 +1,325 @@ +@@ -0,0 +1,323 @@ +package io.papermc.paper.configuration; + +import com.google.common.collect.Table; @@ -815,32 +815,30 @@ index 0000000000000000000000000000000000000000..6c19825de43b82ba3fe6e44123e7d247 + + private static final String GLOBAL_HEADER = """ + This is the global configuration file for Paper. -+ As you can see, there's tons to configure. Some options may impact gameplay, so use ++ As you can see, there's a lot to configure. Some options may impact gameplay, so use + with caution, and make sure you know what each option does before configuring. + + If you need help with the configuration or have any questions related to Paper, -+ join us in our Discord or IRC channel. ++ join us in our Discord or check the docs page. + + The world configuration options have been moved to their own files. + + Discord: https://discord.gg/papermc -+ IRC: #paper @ irc.esper.net ( https://webchat.esper.net/?channels=paper ) + Website: https://papermc.io/ + Docs: https://docs.papermc.io/"""; + + private static final String WORLD_DEFAULTS_HEADER = """ + This is the world defaults configuration file for Paper. -+ As you can see, there's tons to configure. Some options may impact gameplay, so use ++ As you can see, there's a lot to configure. Some options may impact gameplay, so use + with caution, and make sure you know what each option does before configuring. + + If you need help with the configuration or have any questions related to Paper, -+ join us in our Discord or IRC channel. ++ join us in our Discord or check the docs page. + + Configuration options here apply to all worlds, unless you specify overrides inside + the world-specific config file inside each world folder. + + Discord: https://discord.gg/papermc -+ IRC: #paper @ irc.esper.net ( https://webchat.esper.net/?channels=paper ) + Website: https://papermc.io/ + Docs: https://docs.papermc.io/"""; + @@ -1074,15 +1072,16 @@ index 0000000000000000000000000000000000000000..6c19825de43b82ba3fe6e44123e7d247 +} diff --git a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java new file mode 100644 -index 0000000000000000000000000000000000000000..87ebdc61a3802ea33d3c77904122d5005fac77c2 +index 0000000000000000000000000000000000000000..163f02b4bf34da712b30166e80d859a96bf8d911 --- /dev/null +++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java -@@ -0,0 +1,447 @@ +@@ -0,0 +1,470 @@ +package io.papermc.paper.configuration; + +import com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; ++import com.mojang.logging.LogUtils; +import io.papermc.paper.configuration.constraint.Constraint; +import io.papermc.paper.configuration.constraint.Constraints; +import io.papermc.paper.configuration.legacy.MaxEntityCollisionsInitializer; @@ -1110,6 +1109,7 @@ index 0000000000000000000000000000000000000000..87ebdc61a3802ea33d3c77904122d500 +import net.minecraft.world.item.Items; +import net.minecraft.world.level.NaturalSpawner; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; ++import org.slf4j.Logger; +import org.spigotmc.SpigotWorldConfig; +import org.spongepowered.configurate.objectmapping.ConfigSerializable; +import org.spongepowered.configurate.objectmapping.meta.Required; @@ -1123,6 +1123,7 @@ index 0000000000000000000000000000000000000000..87ebdc61a3802ea33d3c77904122d500 + +@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal", "NotNullFieldNotInitialized", "InnerClassMayBeStatic"}) +public class WorldConfiguration extends ConfigurationPart { ++ private static final Logger LOGGER = LogUtils.getLogger(); + static final int CURRENT_VERSION = 28; + + private transient final SpigotWorldConfig spigotConfig; @@ -1500,10 +1501,30 @@ index 0000000000000000000000000000000000000000..87ebdc61a3802ea33d3c77904122d500 + + public FeatureSeeds featureSeeds; + -+ public class FeatureSeeds extends ConfigurationPart { ++ public class FeatureSeeds extends ConfigurationPart.Post { + public boolean generateRandomSeedsForAll = false; + public Reference2LongMap>> features = new Reference2LongOpenHashMap<>(); -+ // TODO post processing to generate random seeds if generateRandomSeedsForAll == true ++ ++ @Override ++ public void postProcess() { ++ features.defaultReturnValue(-1); ++ if (generateRandomSeedsForAll) { ++ final java.util.Random random = new java.security.SecureRandom(); ++ boolean added[] = {false}; ++ net.minecraft.server.MinecraftServer.getServer().registryAccess().registry(Registry.CONFIGURED_FEATURE_REGISTRY).get().holders().forEach(holder -> { ++ if (features.containsKey(holder)) { ++ return; ++ } ++ ++ final long seed = random.nextLong(); ++ features.put(holder, seed); ++ added[0] = true; ++ }); ++ if (added[0]) { ++ LOGGER.info("Generated random feature seeds."); ++ } ++ } ++ } + } + + public Misc misc; diff --git a/patches/server/0009-Paper-command.patch b/patches/server/0009-Paper-command.patch index 9252181e56..7e7b8fd9a1 100644 --- a/patches/server/0009-Paper-command.patch +++ b/patches/server/0009-Paper-command.patch @@ -297,7 +297,7 @@ index 0000000000000000000000000000000000000000..e75134a6aa92c86aa86430c7603e1112 + } +} diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java -index 6c19825de43b82ba3fe6e44123e7d24748698614..f06f130b2fa703e105f9d49bc755e8374d023f2e 100644 +index aa52663a65381f175411a37f9b0731de5ed772aa..d9f5c4154516d136c0e3488be07c8df84cb3ea35 100644 --- a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java +++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java @@ -1,5 +1,6 @@ @@ -307,7 +307,7 @@ index 6c19825de43b82ba3fe6e44123e7d24748698614..f06f130b2fa703e105f9d49bc755e837 import com.google.common.collect.Table; import com.mojang.logging.LogUtils; import io.leangen.geantyref.TypeToken; -@@ -283,6 +284,7 @@ public class PaperConfigurations extends Configurations COMMANDS = new HashMap<>(); static { diff --git a/patches/server/0011-Paper-Metrics.patch b/patches/server/0011-Paper-Metrics.patch index f49fd015ac..c0915892b0 100644 --- a/patches/server/0011-Paper-Metrics.patch +++ b/patches/server/0011-Paper-Metrics.patch @@ -690,7 +690,7 @@ index 0000000000000000000000000000000000000000..5a19e30a9b7e65a70f68a429b8ca741f + } +} diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java -index f06f130b2fa703e105f9d49bc755e8374d023f2e..ef407d6a961c327631656cfd4cc610a22a9e53ac 100644 +index d9f5c4154516d136c0e3488be07c8df84cb3ea35..e279559cd8929642d80eea89b9a89d7ebe982586 100644 --- a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java +++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java @@ -1,5 +1,6 @@ @@ -700,7 +700,7 @@ index f06f130b2fa703e105f9d49bc755e8374d023f2e..ef407d6a961c327631656cfd4cc610a2 import com.destroystokyo.paper.PaperCommand; import com.google.common.collect.Table; import com.mojang.logging.LogUtils; -@@ -283,6 +284,7 @@ public class PaperConfigurations extends Configurations COMMANDS = new HashMap<>(); @@ -708,7 +708,7 @@ index f06f130b2fa703e105f9d49bc755e8374d023f2e..ef407d6a961c327631656cfd4cc610a2 static { COMMANDS.put("paper", new PaperCommand("paper")); } -@@ -291,6 +293,11 @@ public class PaperConfigurations extends Configurations { server.server.getCommandMap().register(s, "Paper", command); }); diff --git a/patches/server/0353-Anti-Xray.patch b/patches/server/0353-Anti-Xray.patch index 9d7c7c60f5..2f17e65dc9 100644 --- a/patches/server/0353-Anti-Xray.patch +++ b/patches/server/0353-Anti-Xray.patch @@ -1017,7 +1017,7 @@ index 0000000000000000000000000000000000000000..80a2dfb266ae1221680a7b24fee2f7e2 + } +} diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java -index ef407d6a961c327631656cfd4cc610a22a9e53ac..0f185ff1af93d40519e8f093b1e63b530656d616 100644 +index e279559cd8929642d80eea89b9a89d7ebe982586..7a2d1cf4343f8bb4c0682b0ab9bb87957d8b3284 100644 --- a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java +++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java @@ -2,6 +2,7 @@ package io.papermc.paper.configuration; @@ -1028,7 +1028,7 @@ index ef407d6a961c327631656cfd4cc610a22a9e53ac..0f185ff1af93d40519e8f093b1e63b53 import com.google.common.collect.Table; import com.mojang.logging.LogUtils; import io.leangen.geantyref.TypeToken; -@@ -171,6 +172,7 @@ public class PaperConfigurations extends Configurations iregistry1 = generatoraccessseed.registryAccess().registryOrThrow(Registry.PLACED_FEATURE_REGISTRY); -+ Registry 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) { -@@ -603,7 +603,15 @@ public abstract class ChunkGenerator { +@@ -603,7 +603,14 @@ public abstract class ChunkGenerator { 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.features.getLong(location); // TODO this wont work ++ final long configFeatureSeed = generatoraccessseed.getMinecraftWorld().paperConfig().featureSeeds.features.getLong(placedfeature.feature()); + if (configFeatureSeed != -1) { + featurePopulationSeed = seededrandom.setDecorationSeed(configFeatureSeed, blockposition.getX(), blockposition.getZ()); // See seededrandom.setDecorationSeed from above + }