Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
at master 37 lines 1.5 kB view raw
1package net.lerariemann.infinity.features; 2 3import com.mojang.serialization.Codec; 4import net.minecraft.core.BlockPos; 5import net.minecraft.util.Mth; 6import net.minecraft.util.RandomSource; 7import net.minecraft.world.level.WorldGenLevel; 8import net.minecraft.world.level.levelgen.feature.Feature; 9import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext; 10import net.minecraft.world.level.levelgen.feature.configurations.BlockStateConfiguration; 11 12public class RandomEndIslandFeature extends Feature<BlockStateConfiguration> { 13 public RandomEndIslandFeature(Codec<BlockStateConfiguration> codec) { 14 super(codec); 15 } 16 17 @Override 18 public boolean place(FeaturePlaceContext<BlockStateConfiguration> context) { 19 WorldGenLevel structureWorldAccess = context.level(); 20 RandomSource random = context.random(); 21 BlockPos blockPos = context.origin(); 22 float f = (float)random.nextInt(3) + 4.0f; 23 int i = 0; 24 while (f > 0.5f) { 25 for (int j = Mth.floor(-f); j <= Mth.ceil(f); ++j) { 26 for (int k = Mth.floor(-f); k <= Mth.ceil(f); ++k) { 27 if (!((float)(j * j + k * k) <= (f + 1.0f) * (f + 1.0f))) continue; 28 this.setBlock(structureWorldAccess, blockPos.offset(j, i, k), context.config().state); 29 } 30 } 31 f -= (float)random.nextInt(2) + 0.5f; 32 --i; 33 } 34 return true; 35 } 36} 37