package net.minecraft.world.level.levelgen.flat; import com.google.common.collect.ImmutableSet; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import net.minecraft.core.Holder; import net.minecraft.core.HolderGetter; import net.minecraft.core.HolderSet; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.resources.Identifier; import net.minecraft.resources.ResourceKey; import net.minecraft.world.item.Items; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.levelgen.structure.BuiltinStructureSets; import net.minecraft.world.level.levelgen.structure.StructureSet; public class FlatLevelGeneratorPresets { public static final ResourceKey CLASSIC_FLAT = register("classic_flat"); public static final ResourceKey TUNNELERS_DREAM = register("tunnelers_dream"); public static final ResourceKey WATER_WORLD = register("water_world"); public static final ResourceKey OVERWORLD = register("overworld"); public static final ResourceKey SNOWY_KINGDOM = register("snowy_kingdom"); public static final ResourceKey BOTTOMLESS_PIT = register("bottomless_pit"); public static final ResourceKey DESERT = register("desert"); public static final ResourceKey REDSTONE_READY = register("redstone_ready"); public static final ResourceKey THE_VOID = register("the_void"); public static void bootstrap(final BootstrapContext context) { new FlatLevelGeneratorPresets.Bootstrap(context).run(); } private static ResourceKey register(final String name) { return ResourceKey.create(Registries.FLAT_LEVEL_GENERATOR_PRESET, Identifier.withDefaultNamespace(name)); } private static class Bootstrap { private final BootstrapContext context; private Bootstrap(final BootstrapContext context) { this.context = context; } private void register( final ResourceKey key, final ItemLike icon, final ResourceKey biome, final Set> structures, final boolean decoration, final boolean addLakes, final FlatLayerInfo... layers ) { HolderGetter structureSets = this.context.lookup(Registries.STRUCTURE_SET); HolderGetter placedFeatures = this.context.lookup(Registries.PLACED_FEATURE); HolderGetter biomes = this.context.lookup(Registries.BIOME); HolderSet.Direct structuresHolder = HolderSet.direct( (List>)structures.stream().map(structureSets::getOrThrow).collect(Collectors.toList()) ); FlatLevelGeneratorSettings generator = new FlatLevelGeneratorSettings( Optional.of(structuresHolder), biomes.getOrThrow(biome), FlatLevelGeneratorSettings.createLakesList(placedFeatures) ); if (decoration) { generator.setDecoration(); } if (addLakes) { generator.setAddLakes(); } for (int i = layers.length - 1; i >= 0; i--) { generator.getLayersInfo().add(layers[i]); } this.context.register(key, new FlatLevelGeneratorPreset(icon.asItem().builtInRegistryHolder(), generator)); } public void run() { this.register( FlatLevelGeneratorPresets.CLASSIC_FLAT, Blocks.GRASS_BLOCK, Biomes.PLAINS, ImmutableSet.of(BuiltinStructureSets.VILLAGES), false, false, new FlatLayerInfo(1, Blocks.GRASS_BLOCK), new FlatLayerInfo(2, Blocks.DIRT), new FlatLayerInfo(1, Blocks.BEDROCK) ); this.register( FlatLevelGeneratorPresets.TUNNELERS_DREAM, Blocks.STONE, Biomes.WINDSWEPT_HILLS, ImmutableSet.of(BuiltinStructureSets.MINESHAFTS, BuiltinStructureSets.STRONGHOLDS), true, false, new FlatLayerInfo(1, Blocks.GRASS_BLOCK), new FlatLayerInfo(5, Blocks.DIRT), new FlatLayerInfo(230, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK) ); this.register( FlatLevelGeneratorPresets.WATER_WORLD, Items.WATER_BUCKET, Biomes.DEEP_OCEAN, ImmutableSet.of(BuiltinStructureSets.OCEAN_RUINS, BuiltinStructureSets.SHIPWRECKS, BuiltinStructureSets.OCEAN_MONUMENTS), false, false, new FlatLayerInfo(90, Blocks.WATER), new FlatLayerInfo(5, Blocks.GRAVEL), new FlatLayerInfo(5, Blocks.DIRT), new FlatLayerInfo(5, Blocks.STONE), new FlatLayerInfo(64, Blocks.DEEPSLATE), new FlatLayerInfo(1, Blocks.BEDROCK) ); this.register( FlatLevelGeneratorPresets.OVERWORLD, Blocks.SHORT_GRASS, Biomes.PLAINS, ImmutableSet.of( BuiltinStructureSets.VILLAGES, BuiltinStructureSets.MINESHAFTS, BuiltinStructureSets.PILLAGER_OUTPOSTS, BuiltinStructureSets.RUINED_PORTALS, BuiltinStructureSets.STRONGHOLDS ), true, true, new FlatLayerInfo(1, Blocks.GRASS_BLOCK), new FlatLayerInfo(3, Blocks.DIRT), new FlatLayerInfo(59, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK) ); this.register( FlatLevelGeneratorPresets.SNOWY_KINGDOM, Blocks.SNOW, Biomes.SNOWY_PLAINS, ImmutableSet.of(BuiltinStructureSets.VILLAGES, BuiltinStructureSets.IGLOOS), false, false, new FlatLayerInfo(1, Blocks.SNOW), new FlatLayerInfo(1, Blocks.GRASS_BLOCK), new FlatLayerInfo(3, Blocks.DIRT), new FlatLayerInfo(59, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK) ); this.register( FlatLevelGeneratorPresets.BOTTOMLESS_PIT, Items.FEATHER, Biomes.PLAINS, ImmutableSet.of(BuiltinStructureSets.VILLAGES), false, false, new FlatLayerInfo(1, Blocks.GRASS_BLOCK), new FlatLayerInfo(3, Blocks.DIRT), new FlatLayerInfo(2, Blocks.COBBLESTONE) ); this.register( FlatLevelGeneratorPresets.DESERT, Blocks.SAND, Biomes.DESERT, ImmutableSet.of(BuiltinStructureSets.VILLAGES, BuiltinStructureSets.DESERT_PYRAMIDS, BuiltinStructureSets.MINESHAFTS, BuiltinStructureSets.STRONGHOLDS), true, false, new FlatLayerInfo(8, Blocks.SAND), new FlatLayerInfo(52, Blocks.SANDSTONE), new FlatLayerInfo(3, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK) ); this.register( FlatLevelGeneratorPresets.REDSTONE_READY, Items.REDSTONE, Biomes.DESERT, ImmutableSet.of(), false, false, new FlatLayerInfo(116, Blocks.SANDSTONE), new FlatLayerInfo(3, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK) ); this.register(FlatLevelGeneratorPresets.THE_VOID, Blocks.BARRIER, Biomes.THE_VOID, ImmutableSet.of(), true, false, new FlatLayerInfo(1, Blocks.AIR)); } } }