|
| 1 | +package xyz.nucleoid.fantasy.util; |
| 2 | + |
| 3 | +import com.mojang.serialization.Codec; |
| 4 | +import com.mojang.serialization.codecs.RecordCodecBuilder; |
| 5 | +import net.minecraft.block.BlockState; |
| 6 | +import net.minecraft.server.world.ServerWorld; |
| 7 | +import net.minecraft.structure.StructureManager; |
| 8 | +import net.minecraft.util.math.BlockPos; |
| 9 | +import net.minecraft.util.math.ChunkPos; |
| 10 | +import net.minecraft.util.registry.DynamicRegistryManager; |
| 11 | +import net.minecraft.util.registry.Registry; |
| 12 | +import net.minecraft.util.registry.RegistryKey; |
| 13 | +import net.minecraft.world.ChunkRegion; |
| 14 | +import net.minecraft.world.HeightLimitView; |
| 15 | +import net.minecraft.world.Heightmap; |
| 16 | +import net.minecraft.world.StructureWorldAccess; |
| 17 | +import net.minecraft.world.biome.Biome; |
| 18 | +import net.minecraft.world.biome.BiomeKeys; |
| 19 | +import net.minecraft.world.biome.source.BiomeAccess; |
| 20 | +import net.minecraft.world.biome.source.FixedBiomeSource; |
| 21 | +import net.minecraft.world.chunk.Chunk; |
| 22 | +import net.minecraft.world.gen.GenerationStep; |
| 23 | +import net.minecraft.world.gen.StructureAccessor; |
| 24 | +import net.minecraft.world.gen.chunk.ChunkGenerator; |
| 25 | +import net.minecraft.world.gen.chunk.StructuresConfig; |
| 26 | +import net.minecraft.world.gen.chunk.VerticalBlockSample; |
| 27 | +import net.minecraft.world.gen.feature.StructureFeature; |
| 28 | +import org.jetbrains.annotations.Nullable; |
| 29 | + |
| 30 | +import java.util.Collections; |
| 31 | +import java.util.Optional; |
| 32 | +import java.util.concurrent.CompletableFuture; |
| 33 | +import java.util.concurrent.Executor; |
| 34 | +import java.util.function.Supplier; |
| 35 | + |
| 36 | +public class VoidChunkGenerator extends ChunkGenerator { |
| 37 | + public static final Codec<VoidChunkGenerator> CODEC = RecordCodecBuilder.create(instance -> { |
| 38 | + return instance.group( |
| 39 | + Biome.REGISTRY_CODEC.stable().fieldOf("biome").forGetter(g -> g.biome) |
| 40 | + ).apply(instance, instance.stable(VoidChunkGenerator::new)); |
| 41 | + }); |
| 42 | + |
| 43 | + private static final VerticalBlockSample EMPTY_SAMPLE = new VerticalBlockSample(0, new BlockState[0]); |
| 44 | + |
| 45 | + private final Supplier<Biome> biome; |
| 46 | + |
| 47 | + public VoidChunkGenerator(Supplier<Biome> biome) { |
| 48 | + super(new FixedBiomeSource(biome), new StructuresConfig(Optional.empty(), Collections.emptyMap())); |
| 49 | + this.biome = biome; |
| 50 | + } |
| 51 | + |
| 52 | + public VoidChunkGenerator(Registry<Biome> biomeRegistry) { |
| 53 | + this(biomeRegistry, BiomeKeys.THE_VOID); |
| 54 | + } |
| 55 | + |
| 56 | + public VoidChunkGenerator(Registry<Biome> biomeRegistry, RegistryKey<Biome> biome) { |
| 57 | + this(() -> biomeRegistry.get(biome)); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + protected Codec<? extends ChunkGenerator> getCodec() { |
| 62 | + return CODEC; |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public ChunkGenerator withSeed(long seed) { |
| 67 | + return this; |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public void setStructureStarts(DynamicRegistryManager registryManager, StructureAccessor accessor, Chunk chunk, StructureManager manager, long seed) { |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public void addStructureReferences(StructureWorldAccess world, StructureAccessor accessor, Chunk chunk) { |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public CompletableFuture<Chunk> populateNoise(Executor executor, StructureAccessor accessor, Chunk chunk) { |
| 80 | + return CompletableFuture.completedFuture(chunk); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public void buildSurface(ChunkRegion region, Chunk chunk) { |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) { |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void generateFeatures(ChunkRegion region, StructureAccessor accessor) { |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + public void populateEntities(ChunkRegion region) { |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + public int getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView world) { |
| 101 | + return 0; |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world) { |
| 106 | + return EMPTY_SAMPLE; |
| 107 | + } |
| 108 | + |
| 109 | + @Nullable |
| 110 | + @Override |
| 111 | + public BlockPos locateStructure(ServerWorld world, StructureFeature<?> feature, BlockPos center, int radius, boolean skipExistingChunks) { |
| 112 | + return null; |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public boolean isStrongholdStartingChunk(ChunkPos chunkPos) { |
| 117 | + return false; |
| 118 | + } |
| 119 | +} |
0 commit comments