Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
at master 44 lines 1.9 kB view raw
1package net.lerariemann.infinity.structure; 2 3import com.mojang.serialization.Codec; 4import com.mojang.serialization.MapCodec; 5import com.mojang.serialization.codecs.RecordCodecBuilder; 6import net.lerariemann.infinity.registry.core.ModStructureTypes; 7import net.minecraft.world.level.levelgen.Heightmap; 8import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider; 9import net.minecraft.world.level.levelgen.structure.Structure; 10import net.minecraft.world.level.levelgen.structure.StructureType; 11import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder; 12import java.util.Optional; 13 14public class PyramidStructure extends Structure { 15 public static final MapCodec<PyramidStructure> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( 16 PyramidStructure.settingsCodec(instance), 17 (Codec.INT.fieldOf("top_y")).forGetter(a -> a.top_y), 18 (Codec.INT.fieldOf("bottom_y")).forGetter(a -> a.top_y), 19 (BlockStateProvider.CODEC.fieldOf("block")).forGetter(a -> a.block)).apply(instance, PyramidStructure::new)); 20 int top_y; 21 int bottom_y; 22 BlockStateProvider block; 23 24 PyramidStructure(StructureSettings config, int i, int j, BlockStateProvider p) { 25 super(config); 26 top_y = i; 27 bottom_y = j; 28 block = p; 29 } 30 31 @Override 32 public Optional<GenerationStub> findGenerationPoint(GenerationContext context) { 33 return PyramidStructure.onTopOfChunkCenter(context, Heightmap.Types.WORLD_SURFACE_WG, collector -> addPieces(collector, context)); 34 } 35 36 private void addPieces(StructurePiecesBuilder collector, GenerationContext context) { 37 collector.addPiece(PyramidGenerator.of(context, top_y, bottom_y, block)); 38 } 39 40 @Override 41 public StructureType<?> type() { 42 return ModStructureTypes.PYRAMID.get(); 43 } 44}