Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
at master 55 lines 2.6 kB view raw
1package net.lerariemann.infinity.structure; 2 3import net.lerariemann.infinity.registry.core.ModStructureTypes; 4import net.minecraft.core.BlockPos; 5import net.minecraft.core.Direction; 6import net.minecraft.nbt.CompoundTag; 7import net.minecraft.util.RandomSource; 8import net.minecraft.world.level.ChunkPos; 9import net.minecraft.world.level.StructureManager; 10import net.minecraft.world.level.WorldGenLevel; 11import net.minecraft.world.level.block.Blocks; 12import net.minecraft.world.level.block.state.BlockState; 13import net.minecraft.world.level.chunk.ChunkGenerator; 14import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider; 15import net.minecraft.world.level.levelgen.structure.BoundingBox; 16import net.minecraft.world.level.levelgen.structure.ScatteredFeaturePiece; 17import net.minecraft.world.level.levelgen.structure.Structure; 18 19public class PyramidGenerator extends ScatteredFeaturePiece { 20 int y, y0; 21 BlockStateProvider b; 22 23 public PyramidGenerator(int x, int y, int z, int width, int height, int depth, BlockStateProvider provider) { 24 super(ModStructureTypes.PYRAMID_PIECE.get(), x, y, z, width, height, depth, Direction.EAST); 25 b = provider; 26 } 27 28 public static PyramidGenerator of(Structure.GenerationContext context, int top_y, int bottom_y, BlockStateProvider provider) { 29 int deltaY = top_y-bottom_y; 30 int x = context.chunkPos().getMinBlockX(); 31 int z = context.chunkPos().getMinBlockZ(); 32 return new PyramidGenerator(x - deltaY, bottom_y, z - deltaY, 2*deltaY + 1, deltaY, 2*deltaY + 1, provider); 33 } 34 35 public PyramidGenerator(CompoundTag nbt) { 36 super(ModStructureTypes.PYRAMID_PIECE.get(), nbt); 37 } 38 39 @Override 40 public void postProcess(WorldGenLevel world, StructureManager structureAccessor, ChunkGenerator chunkGenerator, RandomSource random, BoundingBox box, ChunkPos chunkPos, BlockPos pivot) { 41 int size = y-y0; 42 for(int j = 0; j <= size; j++) { 43 for (int i = j; i <= 2*size - j; ++i) { 44 for (int k = j; k <= 2*size - j; ++k) { 45 if (this.getBlock(world, i, j, k, box).isAir() || this.getBlock(world, i, j, k, box).is(Blocks.WATER)) { 46 BlockState state; 47 if (b == null) state = Blocks.BRICKS.defaultBlockState(); 48 else state = b.getState(random, new BlockPos(i, j, k)); 49 this.placeBlock(world, state, i, j, k, box); 50 } 51 } 52 } 53 } 54 } 55}