Add support for bonus chest configuration in WorldCreator (#12344)

This commit is contained in:
David 2025-04-14 17:24:19 +02:00 committed by GitHub
parent de410d13ef
commit 33e8928f53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 3 deletions

View File

@ -2870,6 +2870,13 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
*/ */
public boolean canGenerateStructures(); public boolean canGenerateStructures();
/**
* Checks if the bonus chest is enabled.
*
* @return {@code true} if the bonus chest is enabled, {@code false} otherwise
*/
boolean hasBonusChest();
/** /**
* Gets whether the world is hardcore or not. * Gets whether the world is hardcore or not.
* *

View File

@ -23,6 +23,7 @@ public class WorldCreator {
private boolean generateStructures = true; private boolean generateStructures = true;
private String generatorSettings = ""; private String generatorSettings = "";
private boolean hardcore = false; private boolean hardcore = false;
private boolean bonusChest = false;
private net.kyori.adventure.util.TriState keepSpawnLoaded = net.kyori.adventure.util.TriState.NOT_SET; // Paper private net.kyori.adventure.util.TriState keepSpawnLoaded = net.kyori.adventure.util.TriState.NOT_SET; // Paper
/** /**
@ -123,6 +124,7 @@ public class WorldCreator {
type = world.getWorldType(); type = world.getWorldType();
generateStructures = world.canGenerateStructures(); generateStructures = world.canGenerateStructures();
hardcore = world.isHardcore(); hardcore = world.isHardcore();
bonusChest = world.hasBonusChest();
this.keepSpawnLoaded = net.kyori.adventure.util.TriState.byBoolean(world.getKeepSpawnInMemory()); // Paper this.keepSpawnLoaded = net.kyori.adventure.util.TriState.byBoolean(world.getKeepSpawnInMemory()); // Paper
return this; return this;
@ -146,6 +148,7 @@ public class WorldCreator {
generateStructures = creator.generateStructures(); generateStructures = creator.generateStructures();
generatorSettings = creator.generatorSettings(); generatorSettings = creator.generatorSettings();
hardcore = creator.hardcore(); hardcore = creator.hardcore();
bonusChest = creator.bonusChest();
keepSpawnLoaded = creator.keepSpawnLoaded(); // Paper keepSpawnLoaded = creator.keepSpawnLoaded(); // Paper
return this; return this;
@ -451,7 +454,7 @@ public class WorldCreator {
/** /**
* Gets whether the world will be hardcore or not. * Gets whether the world will be hardcore or not.
* * <p>
* In a hardcore world the difficulty will be locked to hard. * In a hardcore world the difficulty will be locked to hard.
* *
* @return hardcore status * @return hardcore status
@ -460,6 +463,27 @@ public class WorldCreator {
return hardcore; return hardcore;
} }
/**
* Sets whether a bonus chest should be generated or not.
*
* @param bonusChest indicating whether the bonus chest should be generated
* @return This object, for chaining
*/
@NotNull
public WorldCreator bonusChest(final boolean bonusChest) {
this.bonusChest = bonusChest;
return this;
}
/**
* Gets whether the bonus chest feature is enabled.
*
* @return true if the bonus chest is enabled, false otherwise.
*/
public boolean bonusChest() {
return bonusChest;
}
/** /**
* Sets whether the spawn chunks will be kept loaded. <br> * Sets whether the spawn chunks will be kept loaded. <br>
* Setting this to false will also stop the spawn chunks from being generated * Setting this to false will also stop the spawn chunks from being generated

View File

@ -250,7 +250,7 @@
+ // Paper start - expose FeatureElement wrapper for GameRules.Type. + // Paper start - expose FeatureElement wrapper for GameRules.Type.
+ // Chosen over simply adding this to the inheritance to avoid reobf issues with spigot... + // Chosen over simply adding this to the inheritance to avoid reobf issues with spigot...
+ public net.minecraft.world.flag.FeatureElement asFeatureElement() { + public net.minecraft.world.flag.FeatureElement asFeatureElement() {
+ return net.minecraft.world.level.GameRules.Type.this::requiredFeatures; + return GameRules.Type.this::requiredFeatures;
+ } + }
+ // Paper end - expose FeatureElement wrapper for GameRules.Type. + // Paper end - expose FeatureElement wrapper for GameRules.Type.
} }

View File

@ -1345,7 +1345,7 @@ public final class CraftServer implements Server {
registryAccess = levelDataAndDimensions.dimensions().dimensionsRegistryAccess(); registryAccess = levelDataAndDimensions.dimensions().dimensionsRegistryAccess();
} else { } else {
LevelSettings levelSettings; LevelSettings levelSettings;
WorldOptions worldOptions = new WorldOptions(creator.seed(), creator.generateStructures(), false); WorldOptions worldOptions = new WorldOptions(creator.seed(), creator.generateStructures(), creator.bonusChest());
WorldDimensions worldDimensions; WorldDimensions worldDimensions;
DedicatedServerProperties.WorldDimensionData properties = new DedicatedServerProperties.WorldDimensionData(GsonHelper.parse((creator.generatorSettings().isEmpty()) ? "{}" : creator.generatorSettings()), creator.type().name().toLowerCase(Locale.ROOT)); DedicatedServerProperties.WorldDimensionData properties = new DedicatedServerProperties.WorldDimensionData(GsonHelper.parse((creator.generatorSettings().isEmpty()) ? "{}" : creator.generatorSettings()), creator.type().name().toLowerCase(Locale.ROOT));

View File

@ -1620,6 +1620,11 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return this.world.serverLevelData.worldGenOptions().generateStructures(); return this.world.serverLevelData.worldGenOptions().generateStructures();
} }
@Override
public boolean hasBonusChest() {
return this.world.serverLevelData.worldGenOptions().generateBonusChest();
}
@Override @Override
public boolean isHardcore() { public boolean isHardcore() {
return this.world.getLevelData().isHardcore(); return this.world.getLevelData().isHardcore();