| 1 | package net.minecraft.world.level.levelgen;
|
| 2 |
|
| 3 | import com.mojang.serialization.MapCodec;
|
| 4 | import com.mojang.serialization.codecs.RecordCodecBuilder;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Set;
|
| 7 | import java.util.concurrent.CompletableFuture;
|
| 8 | import java.util.stream.Collectors;
|
| 9 | import java.util.stream.StreamSupport;
|
| 10 | import net.minecraft.core.BlockPos;
|
| 11 | import net.minecraft.core.Holder;
|
| 12 | import net.minecraft.core.SectionPos;
|
| 13 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 14 | import net.minecraft.resources.RegistryOps;
|
| 15 | import net.minecraft.server.level.WorldGenRegion;
|
| 16 | import net.minecraft.util.Mth;
|
| 17 | import net.minecraft.world.level.ChunkPos;
|
| 18 | import net.minecraft.world.level.LevelHeightAccessor;
|
| 19 | import net.minecraft.world.level.NoiseColumn;
|
| 20 | import net.minecraft.world.level.StructureManager;
|
| 21 | import net.minecraft.world.level.WorldGenLevel;
|
| 22 | import net.minecraft.world.level.biome.Biome;
|
| 23 | import net.minecraft.world.level.biome.BiomeManager;
|
| 24 | import net.minecraft.world.level.biome.Biomes;
|
| 25 | import net.minecraft.world.level.biome.FixedBiomeSource;
|
| 26 | import net.minecraft.world.level.block.Blocks;
|
| 27 | import net.minecraft.world.level.block.state.BlockState;
|
| 28 | import net.minecraft.world.level.chunk.ChunkAccess;
|
| 29 | import net.minecraft.world.level.chunk.ChunkGenerator;
|
| 30 | import net.minecraft.world.level.levelgen.blending.Blender;
|
| 31 | import net.minecraft.world.level.levelgen.densityfunction.SamplerContext;
|
| 32 | import org.jspecify.annotations.Nullable;
|
| 33 |
|
| 34 | public class DebugLevelSource extends ChunkGenerator {
|
| 35 | public static final MapCodec<DebugLevelSource> CODEC = RecordCodecBuilder.mapCodec(
|
| 36 | i -> i.group(RegistryOps.retrieveElement(Biomes.PLAINS)).apply(i, i.stable(DebugLevelSource::new))
|
| 37 | );
|
| 38 | private static final int BLOCK_MARGIN = 2;
|
| 39 | private static final List<BlockState> ALL_BLOCKS = StreamSupport.stream(BuiltInRegistries.BLOCK.spliterator(), false)
|
| 40 | .flatMap(b -> b.getStateDefinition().getPossibleStates().stream())
|
| 41 | .collect(Collectors.toList());
|
| 42 | private static final int GRID_WIDTH = Mth.ceil(Mth.sqrt(ALL_BLOCKS.size()));
|
| 43 | private static final int GRID_HEIGHT = Mth.ceil((float)ALL_BLOCKS.size() / GRID_WIDTH);
|
| 44 | protected static final BlockState AIR = Blocks.AIR.defaultBlockState();
|
| 45 | protected static final BlockState BARRIER = Blocks.BARRIER.defaultBlockState();
|
| 46 | public static final int HEIGHT = 70;
|
| 47 | public static final int BARRIER_HEIGHT = 60;
|
| 48 |
|
| 49 | public DebugLevelSource(final Holder.Reference<Biome> plains) {
|
| 50 | super(new FixedBiomeSource(plains));
|
| 51 | }
|
| 52 |
|
| 53 | @Override
|
| 54 | protected MapCodec<? extends ChunkGenerator> codec() {
|
| 55 | return CODEC;
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | public void applyBiomeDecoration(final WorldGenLevel level, final ChunkAccess chunk, final StructureManager structureManager) {
|
| 60 | BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
|
| 61 | ChunkPos centerPos = chunk.getPos();
|
| 62 | int chunkX = centerPos.x();
|
| 63 | int chunkZ = centerPos.z();
|
| 64 |
|
| 65 | for (int x = 0; x < 16; x++) {
|
| 66 | for (int z = 0; z < 16; z++) {
|
| 67 | int worldX = SectionPos.sectionToBlockCoord(chunkX, x);
|
| 68 | int worldZ = SectionPos.sectionToBlockCoord(chunkZ, z);
|
| 69 | level.setBlock(blockPos.set(worldX, 60, worldZ), BARRIER, 2);
|
| 70 | BlockState state = getBlockStateFor(worldX, worldZ);
|
| 71 | level.setBlock(blockPos.set(worldX, 70, worldZ), state, 2);
|
| 72 | }
|
| 73 | }
|
| 74 | }
|
| 75 |
|
| 76 | @Override
|
| 77 | public CompletableFuture<ChunkAccess> buildTerrain(
|
| 78 | final ChunkAccess chunk,
|
| 79 | final Blender blender,
|
| 80 | final RandomState randomState,
|
| 81 | final StructureManager structureManager,
|
| 82 | final BiomeManager biomeManager,
|
| 83 | final @Nullable WorldGenRegion carverBiomeRegion,
|
| 84 | final Set<Holder<Biome>> possibleBiomes
|
| 85 | ) {
|
| 86 | return CompletableFuture.completedFuture(chunk);
|
| 87 | }
|
| 88 |
|
| 89 | @Override
|
| 90 | public int getBaseHeight(final int x, final int z, final Heightmap.Types type, final LevelHeightAccessor heightAccessor, final RandomState randomState) {
|
| 91 | return 0;
|
| 92 | }
|
| 93 |
|
| 94 | @Override
|
| 95 | public NoiseColumn getBaseColumn(final int x, final int z, final LevelHeightAccessor heightAccessor, final RandomState randomState) {
|
| 96 | return new NoiseColumn(0, new BlockState[0]);
|
| 97 | }
|
| 98 |
|
| 99 | @Override
|
| 100 | public void addDebugScreenInfo(final List<String> result, final RandomState randomState, final BlockPos feetPos, final SamplerContext samplerContext) {
|
| 101 | }
|
| 102 |
|
| 103 | public static BlockState getBlockStateFor(int worldX, int worldZ) {
|
| 104 | BlockState state = AIR;
|
| 105 | if (worldX > 0 && worldZ > 0 && worldX % 2 != 0 && worldZ % 2 != 0) {
|
| 106 | worldX /= 2;
|
| 107 | worldZ /= 2;
|
| 108 | if (worldX <= GRID_WIDTH && worldZ <= GRID_HEIGHT) {
|
| 109 | int index = Mth.abs(worldX * GRID_WIDTH + worldZ);
|
| 110 | if (index < ALL_BLOCKS.size()) {
|
| 111 | state = ALL_BLOCKS.get(index);
|
| 112 | }
|
| 113 | }
|
| 114 | }
|
| 115 |
|
| 116 | return state;
|
| 117 | }
|
| 118 |
|
| 119 | @Override
|
| 120 | public void spawnOriginalMobs(final WorldGenRegion worldGenRegion) {
|
| 121 | }
|
| 122 |
|
| 123 | @Override
|
| 124 | public int getMinY() {
|
| 125 | return 0;
|
| 126 | }
|
| 127 |
|
| 128 | @Override
|
| 129 | public int getGenDepth() {
|
| 130 | return 384;
|
| 131 | }
|
| 132 |
|
| 133 | @Override
|
| 134 | public int getSeaLevel() {
|
| 135 | return 63;
|
| 136 | }
|
| 137 | }
|
| 138 |
|