139 lines
5.8 KiB
Java
139 lines
5.8 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.mojang.datafixers.kinds.App
|
|
* com.mojang.datafixers.kinds.Applicative
|
|
* com.mojang.serialization.MapCodec
|
|
* com.mojang.serialization.codecs.RecordCodecBuilder
|
|
*/
|
|
package net.minecraft.world.level.levelgen;
|
|
|
|
import com.mojang.datafixers.kinds.App;
|
|
import com.mojang.datafixers.kinds.Applicative;
|
|
import com.mojang.serialization.MapCodec;
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
import java.util.List;
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.stream.Stream;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.HolderLookup;
|
|
import net.minecraft.core.HolderSet;
|
|
import net.minecraft.server.level.WorldGenRegion;
|
|
import net.minecraft.util.Util;
|
|
import net.minecraft.world.level.LevelHeightAccessor;
|
|
import net.minecraft.world.level.NoiseColumn;
|
|
import net.minecraft.world.level.StructureManager;
|
|
import net.minecraft.world.level.biome.BiomeManager;
|
|
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.chunk.ChunkGeneratorStructureState;
|
|
import net.minecraft.world.level.levelgen.Heightmap;
|
|
import net.minecraft.world.level.levelgen.RandomState;
|
|
import net.minecraft.world.level.levelgen.blending.Blender;
|
|
import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorSettings;
|
|
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
|
|
|
public class FlatLevelSource
|
|
extends ChunkGenerator {
|
|
public static final MapCodec<FlatLevelSource> CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)FlatLevelGeneratorSettings.CODEC.fieldOf("settings").forGetter(FlatLevelSource::settings)).apply((Applicative)i, i.stable(FlatLevelSource::new)));
|
|
private final FlatLevelGeneratorSettings settings;
|
|
|
|
public FlatLevelSource(FlatLevelGeneratorSettings generatorSettings) {
|
|
super(new FixedBiomeSource(generatorSettings.getBiome()), Util.memoize(generatorSettings::adjustGenerationSettings));
|
|
this.settings = generatorSettings;
|
|
}
|
|
|
|
@Override
|
|
public ChunkGeneratorStructureState createState(HolderLookup<StructureSet> structureSets, RandomState randomState, long levelSeed) {
|
|
Stream structures = this.settings.structureOverrides().map(HolderSet::stream).orElseGet(() -> structureSets.listElements().map(e -> e));
|
|
return ChunkGeneratorStructureState.createForFlat(randomState, levelSeed, this.biomeSource, structures);
|
|
}
|
|
|
|
@Override
|
|
protected MapCodec<? extends ChunkGenerator> codec() {
|
|
return CODEC;
|
|
}
|
|
|
|
public FlatLevelGeneratorSettings settings() {
|
|
return this.settings;
|
|
}
|
|
|
|
@Override
|
|
public void buildSurface(WorldGenRegion level, StructureManager structureManager, RandomState randomState, ChunkAccess protoChunk) {
|
|
}
|
|
|
|
@Override
|
|
public int getSpawnHeight(LevelHeightAccessor heightAccessor) {
|
|
return heightAccessor.getMinY() + Math.min(heightAccessor.getHeight(), this.settings.getLayers().size());
|
|
}
|
|
|
|
@Override
|
|
public CompletableFuture<ChunkAccess> fillFromNoise(Blender blender, RandomState randomState, StructureManager structureManager, ChunkAccess centerChunk) {
|
|
List<BlockState> layers = this.settings.getLayers();
|
|
BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
|
|
Heightmap oceanFloor = centerChunk.getOrCreateHeightmapUnprimed(Heightmap.Types.OCEAN_FLOOR_WG);
|
|
Heightmap worldSurface = centerChunk.getOrCreateHeightmapUnprimed(Heightmap.Types.WORLD_SURFACE_WG);
|
|
for (int layerIndex = 0; layerIndex < Math.min(centerChunk.getHeight(), layers.size()); ++layerIndex) {
|
|
BlockState blockState = layers.get(layerIndex);
|
|
if (blockState == null) continue;
|
|
int y = centerChunk.getMinY() + layerIndex;
|
|
for (int x = 0; x < 16; ++x) {
|
|
for (int z = 0; z < 16; ++z) {
|
|
centerChunk.setBlockState(blockPos.set(x, y, z), blockState);
|
|
oceanFloor.update(x, y, z, blockState);
|
|
worldSurface.update(x, y, z, blockState);
|
|
}
|
|
}
|
|
}
|
|
return CompletableFuture.completedFuture(centerChunk);
|
|
}
|
|
|
|
@Override
|
|
public int getBaseHeight(int x, int z, Heightmap.Types type, LevelHeightAccessor heightAccessor, RandomState randomState) {
|
|
List<BlockState> layers = this.settings.getLayers();
|
|
for (int layerIndex = Math.min(layers.size() - 1, heightAccessor.getMaxY()); layerIndex >= 0; --layerIndex) {
|
|
BlockState state = layers.get(layerIndex);
|
|
if (state == null || !type.isOpaque().test(state)) continue;
|
|
return heightAccessor.getMinY() + layerIndex + 1;
|
|
}
|
|
return heightAccessor.getMinY();
|
|
}
|
|
|
|
@Override
|
|
public NoiseColumn getBaseColumn(int x, int z, LevelHeightAccessor heightAccessor, RandomState randomState) {
|
|
return new NoiseColumn(heightAccessor.getMinY(), (BlockState[])this.settings.getLayers().stream().limit(heightAccessor.getHeight()).map(state -> state == null ? Blocks.AIR.defaultBlockState() : state).toArray(BlockState[]::new));
|
|
}
|
|
|
|
@Override
|
|
public void addDebugScreenInfo(List<String> result, RandomState randomState, BlockPos feetPos) {
|
|
}
|
|
|
|
@Override
|
|
public void applyCarvers(WorldGenRegion region, long seed, RandomState randomState, BiomeManager biomeManager, StructureManager structureManager, ChunkAccess chunk) {
|
|
}
|
|
|
|
@Override
|
|
public void spawnOriginalMobs(WorldGenRegion worldGenRegion) {
|
|
}
|
|
|
|
@Override
|
|
public int getMinY() {
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public int getGenDepth() {
|
|
return 384;
|
|
}
|
|
|
|
@Override
|
|
public int getSeaLevel() {
|
|
return -63;
|
|
}
|
|
}
|
|
|