| 1 | package net.minecraft.world.level.levelgen;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import com.mojang.serialization.codecs.RecordCodecBuilder;
|
| 5 | import java.util.HashMap;
|
| 6 | import java.util.Objects;
|
| 7 | import net.minecraft.core.RegistryAccess;
|
| 8 | import net.minecraft.core.registries.Registries;
|
| 9 | import net.minecraft.resources.Identifier;
|
| 10 | import net.minecraft.util.datafix.DataFixTypes;
|
| 11 | import net.minecraft.world.level.saveddata.SavedData;
|
| 12 | import net.minecraft.world.level.saveddata.SavedDataType;
|
| 13 |
|
| 14 | public final class WorldGenSettings extends SavedData {
|
| 15 | public static final Codec<WorldGenSettings> CODEC = RecordCodecBuilder.create(
|
| 16 | i -> i.group(WorldOptions.CODEC.forGetter(WorldGenSettings::options), WorldDimensions.CODEC.forGetter(WorldGenSettings::dimensions))
|
| 17 | .apply(i, i.stable(WorldGenSettings::new))
|
| 18 | );
|
| 19 | public static final SavedDataType<WorldGenSettings> TYPE = new SavedDataType<>(
|
| 20 | Identifier.withDefaultNamespace("world_gen_settings"),
|
| 21 | () -> new WorldGenSettings(WorldOptions.defaultWithRandomSeed(), new WorldDimensions(new HashMap<>())),
|
| 22 | CODEC,
|
| 23 | DataFixTypes.SAVED_DATA_WORLD_GEN_SETTINGS
|
| 24 | );
|
| 25 | private final WorldOptions options;
|
| 26 | private final WorldDimensions dimensions;
|
| 27 |
|
| 28 | public WorldGenSettings(final WorldOptions options, final WorldDimensions dimensions) {
|
| 29 | this.options = options;
|
| 30 | this.dimensions = dimensions;
|
| 31 | }
|
| 32 |
|
| 33 | public static WorldGenSettings of(final WorldOptions options, final RegistryAccess registryAccess) {
|
| 34 | return new WorldGenSettings(options, new WorldDimensions(registryAccess.lookupOrThrow(Registries.LEVEL_STEM)));
|
| 35 | }
|
| 36 |
|
| 37 | public WorldOptions options() {
|
| 38 | return this.options;
|
| 39 | }
|
| 40 |
|
| 41 | public WorldDimensions dimensions() {
|
| 42 | return this.dimensions;
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | public int hashCode() {
|
| 47 | return Objects.hash(this.options, this.dimensions);
|
| 48 | }
|
| 49 |
|
| 50 | @Override
|
| 51 | public String toString() {
|
| 52 | return "WorldGenSettings[options=" + this.options + ", dimensions=" + this.dimensions + "]";
|
| 53 | }
|
| 54 | }
|
| 55 |
|