| 1 | package net.minecraft.world.level.levelgen.flat;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableSet;
|
| 4 | import java.util.Optional;
|
| 5 | import java.util.Set;
|
| 6 | import java.util.stream.Collectors;
|
| 7 | import net.minecraft.core.HolderGetter;
|
| 8 | import net.minecraft.core.HolderSet;
|
| 9 | import net.minecraft.core.registries.Registries;
|
| 10 | import net.minecraft.data.worldgen.BootstrapContext;
|
| 11 | import net.minecraft.resources.Identifier;
|
| 12 | import net.minecraft.resources.ResourceKey;
|
| 13 | import net.minecraft.world.item.Items;
|
| 14 | import net.minecraft.world.level.ItemLike;
|
| 15 | import net.minecraft.world.level.biome.Biome;
|
| 16 | import net.minecraft.world.level.biome.Biomes;
|
| 17 | import net.minecraft.world.level.block.Blocks;
|
| 18 | import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
| 19 | import net.minecraft.world.level.levelgen.structure.BuiltinStructureSets;
|
| 20 | import net.minecraft.world.level.levelgen.structure.StructureSet;
|
| 21 |
|
| 22 | public class FlatLevelGeneratorPresets {
|
| 23 | public static final ResourceKey<FlatLevelGeneratorPreset> CLASSIC_FLAT = register("classic_flat");
|
| 24 | public static final ResourceKey<FlatLevelGeneratorPreset> TUNNELERS_DREAM = register("tunnelers_dream");
|
| 25 | public static final ResourceKey<FlatLevelGeneratorPreset> WATER_WORLD = register("water_world");
|
| 26 | public static final ResourceKey<FlatLevelGeneratorPreset> OVERWORLD = register("overworld");
|
| 27 | public static final ResourceKey<FlatLevelGeneratorPreset> SNOWY_KINGDOM = register("snowy_kingdom");
|
| 28 | public static final ResourceKey<FlatLevelGeneratorPreset> BOTTOMLESS_PIT = register("bottomless_pit");
|
| 29 | public static final ResourceKey<FlatLevelGeneratorPreset> DESERT = register("desert");
|
| 30 | public static final ResourceKey<FlatLevelGeneratorPreset> REDSTONE_READY = register("redstone_ready");
|
| 31 | public static final ResourceKey<FlatLevelGeneratorPreset> TEST_WORLD = register("test_world");
|
| 32 | public static final ResourceKey<FlatLevelGeneratorPreset> THE_VOID = register("the_void");
|
| 33 |
|
| 34 | public static void bootstrap(final BootstrapContext<FlatLevelGeneratorPreset> context) {
|
| 35 | new FlatLevelGeneratorPresets.Bootstrap(context).run();
|
| 36 | }
|
| 37 |
|
| 38 | private static ResourceKey<FlatLevelGeneratorPreset> register(final String name) {
|
| 39 | return ResourceKey.create(Registries.FLAT_LEVEL_GENERATOR_PRESET, Identifier.withDefaultNamespace(name));
|
| 40 | }
|
| 41 |
|
| 42 | private static class Bootstrap {
|
| 43 | private final BootstrapContext<FlatLevelGeneratorPreset> context;
|
| 44 |
|
| 45 | private Bootstrap(final BootstrapContext<FlatLevelGeneratorPreset> context) {
|
| 46 | this.context = context;
|
| 47 | }
|
| 48 |
|
| 49 | private void register(
|
| 50 | final ResourceKey<FlatLevelGeneratorPreset> key,
|
| 51 | final ItemLike icon,
|
| 52 | final ResourceKey<Biome> biome,
|
| 53 | final Set<ResourceKey<StructureSet>> structures,
|
| 54 | final boolean decoration,
|
| 55 | final boolean addLakes,
|
| 56 | final FlatLayerInfo... layers
|
| 57 | ) {
|
| 58 | HolderGetter<StructureSet> structureSets = this.context.lookup(Registries.STRUCTURE_SET);
|
| 59 | HolderGetter<PlacedFeature> placedFeatures = this.context.lookup(Registries.PLACED_FEATURE);
|
| 60 | HolderGetter<Biome> biomes = this.context.lookup(Registries.BIOME);
|
| 61 | HolderSet.Direct<StructureSet> structuresHolder = HolderSet.direct(structures.stream().map(structureSets::getOrThrow).collect(Collectors.toList()));
|
| 62 | FlatLevelGeneratorSettings generator = new FlatLevelGeneratorSettings(
|
| 63 | Optional.of(structuresHolder), biomes.getOrThrow(biome), FlatLevelGeneratorSettings.createLakesList(placedFeatures)
|
| 64 | );
|
| 65 | if (decoration) {
|
| 66 | generator.setDecoration();
|
| 67 | }
|
| 68 |
|
| 69 | if (addLakes) {
|
| 70 | generator.setAddLakes();
|
| 71 | }
|
| 72 |
|
| 73 | for (int i = layers.length - 1; i >= 0; i--) {
|
| 74 | generator.getLayersInfo().add(layers[i]);
|
| 75 | }
|
| 76 |
|
| 77 | this.context.register(key, new FlatLevelGeneratorPreset(icon.asItem().builtInRegistryHolder(), generator));
|
| 78 | }
|
| 79 |
|
| 80 | public void run() {
|
| 81 | this.register(
|
| 82 | FlatLevelGeneratorPresets.CLASSIC_FLAT,
|
| 83 | Blocks.GRASS_BLOCK,
|
| 84 | Biomes.PLAINS,
|
| 85 | ImmutableSet.of(BuiltinStructureSets.VILLAGES),
|
| 86 | false,
|
| 87 | false,
|
| 88 | new FlatLayerInfo(1, Blocks.GRASS_BLOCK),
|
| 89 | new FlatLayerInfo(2, Blocks.DIRT),
|
| 90 | new FlatLayerInfo(1, Blocks.BEDROCK)
|
| 91 | );
|
| 92 | this.register(
|
| 93 | FlatLevelGeneratorPresets.TUNNELERS_DREAM,
|
| 94 | Blocks.STONE,
|
| 95 | Biomes.WINDSWEPT_HILLS,
|
| 96 | ImmutableSet.of(BuiltinStructureSets.MINESHAFTS, BuiltinStructureSets.STRONGHOLDS),
|
| 97 | true,
|
| 98 | false,
|
| 99 | new FlatLayerInfo(1, Blocks.GRASS_BLOCK),
|
| 100 | new FlatLayerInfo(5, Blocks.DIRT),
|
| 101 | new FlatLayerInfo(230, Blocks.STONE),
|
| 102 | new FlatLayerInfo(1, Blocks.BEDROCK)
|
| 103 | );
|
| 104 | this.register(
|
| 105 | FlatLevelGeneratorPresets.WATER_WORLD,
|
| 106 | Items.WATER_BUCKET,
|
| 107 | Biomes.DEEP_OCEAN,
|
| 108 | ImmutableSet.of(BuiltinStructureSets.OCEAN_RUINS, BuiltinStructureSets.SHIPWRECKS, BuiltinStructureSets.OCEAN_MONUMENTS),
|
| 109 | false,
|
| 110 | false,
|
| 111 | new FlatLayerInfo(90, Blocks.WATER),
|
| 112 | new FlatLayerInfo(5, Blocks.GRAVEL),
|
| 113 | new FlatLayerInfo(5, Blocks.DIRT),
|
| 114 | new FlatLayerInfo(5, Blocks.STONE),
|
| 115 | new FlatLayerInfo(64, Blocks.DEEPSLATE),
|
| 116 | new FlatLayerInfo(1, Blocks.BEDROCK)
|
| 117 | );
|
| 118 | this.register(
|
| 119 | FlatLevelGeneratorPresets.OVERWORLD,
|
| 120 | Blocks.SHORT_GRASS,
|
| 121 | Biomes.PLAINS,
|
| 122 | ImmutableSet.of(
|
| 123 | BuiltinStructureSets.VILLAGES,
|
| 124 | BuiltinStructureSets.MINESHAFTS,
|
| 125 | BuiltinStructureSets.PILLAGER_OUTPOSTS,
|
| 126 | BuiltinStructureSets.RUINED_PORTALS,
|
| 127 | BuiltinStructureSets.STRONGHOLDS
|
| 128 | ),
|
| 129 | true,
|
| 130 | true,
|
| 131 | new FlatLayerInfo(1, Blocks.GRASS_BLOCK),
|
| 132 | new FlatLayerInfo(3, Blocks.DIRT),
|
| 133 | new FlatLayerInfo(59, Blocks.STONE),
|
| 134 | new FlatLayerInfo(1, Blocks.BEDROCK)
|
| 135 | );
|
| 136 | this.register(
|
| 137 | FlatLevelGeneratorPresets.SNOWY_KINGDOM,
|
| 138 | Blocks.SNOW,
|
| 139 | Biomes.SNOWY_PLAINS,
|
| 140 | ImmutableSet.of(BuiltinStructureSets.VILLAGES, BuiltinStructureSets.IGLOOS),
|
| 141 | false,
|
| 142 | false,
|
| 143 | new FlatLayerInfo(1, Blocks.SNOW),
|
| 144 | new FlatLayerInfo(1, Blocks.GRASS_BLOCK),
|
| 145 | new FlatLayerInfo(3, Blocks.DIRT),
|
| 146 | new FlatLayerInfo(59, Blocks.STONE),
|
| 147 | new FlatLayerInfo(1, Blocks.BEDROCK)
|
| 148 | );
|
| 149 | this.register(
|
| 150 | FlatLevelGeneratorPresets.BOTTOMLESS_PIT,
|
| 151 | Items.FEATHER,
|
| 152 | Biomes.PLAINS,
|
| 153 | ImmutableSet.of(BuiltinStructureSets.VILLAGES),
|
| 154 | false,
|
| 155 | false,
|
| 156 | new FlatLayerInfo(1, Blocks.GRASS_BLOCK),
|
| 157 | new FlatLayerInfo(3, Blocks.DIRT),
|
| 158 | new FlatLayerInfo(2, Blocks.COBBLESTONE)
|
| 159 | );
|
| 160 | this.register(
|
| 161 | FlatLevelGeneratorPresets.DESERT,
|
| 162 | Blocks.SAND,
|
| 163 | Biomes.DESERT,
|
| 164 | ImmutableSet.of(BuiltinStructureSets.VILLAGES, BuiltinStructureSets.DESERT_PYRAMIDS, BuiltinStructureSets.MINESHAFTS, BuiltinStructureSets.STRONGHOLDS),
|
| 165 | true,
|
| 166 | false,
|
| 167 | new FlatLayerInfo(8, Blocks.SAND),
|
| 168 | new FlatLayerInfo(52, Blocks.SANDSTONE),
|
| 169 | new FlatLayerInfo(3, Blocks.STONE),
|
| 170 | new FlatLayerInfo(1, Blocks.BEDROCK)
|
| 171 | );
|
| 172 | this.register(
|
| 173 | FlatLevelGeneratorPresets.REDSTONE_READY,
|
| 174 | Items.REDSTONE,
|
| 175 | Biomes.DESERT,
|
| 176 | ImmutableSet.of(),
|
| 177 | false,
|
| 178 | false,
|
| 179 | new FlatLayerInfo(116, Blocks.SANDSTONE),
|
| 180 | new FlatLayerInfo(3, Blocks.STONE),
|
| 181 | new FlatLayerInfo(1, Blocks.BEDROCK)
|
| 182 | );
|
| 183 | this.register(FlatLevelGeneratorPresets.THE_VOID, Blocks.BARRIER, Biomes.THE_VOID, ImmutableSet.of(), true, false, new FlatLayerInfo(1, Blocks.AIR));
|
| 184 | }
|
| 185 | }
|
| 186 | }
|
| 187 |
|