137 lines
		
	
	
	
		
			4.6 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			137 lines
		
	
	
	
		
			4.6 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.minecraft.world.level.levelgen;
 | |
| 
 | |
| import com.mojang.serialization.MapCodec;
 | |
| import com.mojang.serialization.codecs.RecordCodecBuilder;
 | |
| import java.util.List;
 | |
| import java.util.concurrent.CompletableFuture;
 | |
| import java.util.stream.Collectors;
 | |
| import java.util.stream.StreamSupport;
 | |
| import net.minecraft.core.BlockPos;
 | |
| import net.minecraft.core.Holder;
 | |
| import net.minecraft.core.SectionPos;
 | |
| import net.minecraft.core.registries.BuiltInRegistries;
 | |
| import net.minecraft.resources.RegistryOps;
 | |
| import net.minecraft.server.level.WorldGenRegion;
 | |
| import net.minecraft.util.Mth;
 | |
| import net.minecraft.world.level.ChunkPos;
 | |
| import net.minecraft.world.level.LevelHeightAccessor;
 | |
| import net.minecraft.world.level.NoiseColumn;
 | |
| import net.minecraft.world.level.StructureManager;
 | |
| import net.minecraft.world.level.WorldGenLevel;
 | |
| import net.minecraft.world.level.biome.Biome;
 | |
| import net.minecraft.world.level.biome.BiomeManager;
 | |
| import net.minecraft.world.level.biome.Biomes;
 | |
| import net.minecraft.world.level.biome.FixedBiomeSource;
 | |
| import net.minecraft.world.level.block.Blocks;
 | |
| import net.minecraft.world.level.block.state.BlockState;
 | |
| import net.minecraft.world.level.chunk.ChunkAccess;
 | |
| import net.minecraft.world.level.chunk.ChunkGenerator;
 | |
| import net.minecraft.world.level.levelgen.blending.Blender;
 | |
| 
 | |
| public class DebugLevelSource extends ChunkGenerator {
 | |
| 	public static final MapCodec<DebugLevelSource> CODEC = RecordCodecBuilder.mapCodec(
 | |
| 		instance -> instance.group(RegistryOps.retrieveElement(Biomes.PLAINS)).apply(instance, instance.stable(DebugLevelSource::new))
 | |
| 	);
 | |
| 	private static final int BLOCK_MARGIN = 2;
 | |
| 	/**
 | |
| 	 * A list of all valid block states.
 | |
| 	 */
 | |
| 	private static final List<BlockState> ALL_BLOCKS = (List<BlockState>)StreamSupport.stream(BuiltInRegistries.BLOCK.spliterator(), false)
 | |
| 		.flatMap(block -> block.getStateDefinition().getPossibleStates().stream())
 | |
| 		.collect(Collectors.toList());
 | |
| 	private static final int GRID_WIDTH = Mth.ceil(Mth.sqrt(ALL_BLOCKS.size()));
 | |
| 	private static final int GRID_HEIGHT = Mth.ceil((float)ALL_BLOCKS.size() / GRID_WIDTH);
 | |
| 	protected static final BlockState AIR = Blocks.AIR.defaultBlockState();
 | |
| 	protected static final BlockState BARRIER = Blocks.BARRIER.defaultBlockState();
 | |
| 	public static final int HEIGHT = 70;
 | |
| 	public static final int BARRIER_HEIGHT = 60;
 | |
| 
 | |
| 	public DebugLevelSource(Holder.Reference<Biome> biome) {
 | |
| 		super(new FixedBiomeSource(biome));
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	protected MapCodec<? extends ChunkGenerator> codec() {
 | |
| 		return CODEC;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void buildSurface(WorldGenRegion level, StructureManager structureManager, RandomState random, ChunkAccess chunk) {
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void applyBiomeDecoration(WorldGenLevel level, ChunkAccess chunk, StructureManager structureManager) {
 | |
| 		BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
 | |
| 		ChunkPos chunkPos = chunk.getPos();
 | |
| 		int i = chunkPos.x;
 | |
| 		int j = chunkPos.z;
 | |
| 
 | |
| 		for (int k = 0; k < 16; k++) {
 | |
| 			for (int l = 0; l < 16; l++) {
 | |
| 				int m = SectionPos.sectionToBlockCoord(i, k);
 | |
| 				int n = SectionPos.sectionToBlockCoord(j, l);
 | |
| 				level.setBlock(mutableBlockPos.set(m, 60, n), BARRIER, 2);
 | |
| 				BlockState blockState = getBlockStateFor(m, n);
 | |
| 				level.setBlock(mutableBlockPos.set(m, 70, n), blockState, 2);
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public CompletableFuture<ChunkAccess> fillFromNoise(Blender blender, RandomState randomState, StructureManager structureManager, ChunkAccess chunk) {
 | |
| 		return CompletableFuture.completedFuture(chunk);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public int getBaseHeight(int x, int z, Heightmap.Types type, LevelHeightAccessor level, RandomState random) {
 | |
| 		return 0;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public NoiseColumn getBaseColumn(int x, int z, LevelHeightAccessor height, RandomState random) {
 | |
| 		return new NoiseColumn(0, new BlockState[0]);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void addDebugScreenInfo(List<String> info, RandomState random, BlockPos pos) {
 | |
| 	}
 | |
| 
 | |
| 	public static BlockState getBlockStateFor(int chunkX, int chunkZ) {
 | |
| 		BlockState blockState = AIR;
 | |
| 		if (chunkX > 0 && chunkZ > 0 && chunkX % 2 != 0 && chunkZ % 2 != 0) {
 | |
| 			chunkX /= 2;
 | |
| 			chunkZ /= 2;
 | |
| 			if (chunkX <= GRID_WIDTH && chunkZ <= GRID_HEIGHT) {
 | |
| 				int i = Mth.abs(chunkX * GRID_WIDTH + chunkZ);
 | |
| 				if (i < ALL_BLOCKS.size()) {
 | |
| 					blockState = (BlockState)ALL_BLOCKS.get(i);
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		return blockState;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void applyCarvers(WorldGenRegion level, long seed, RandomState random, BiomeManager biomeManager, StructureManager structureManager, ChunkAccess chunk) {
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void spawnOriginalMobs(WorldGenRegion level) {
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public int getMinY() {
 | |
| 		return 0;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public int getGenDepth() {
 | |
| 		return 384;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public int getSeaLevel() {
 | |
| 		return 63;
 | |
| 	}
 | |
| }
 |