Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
at master 67 lines 2.6 kB view raw
1package net.lerariemann.infinity.util.config; 2 3import net.lerariemann.infinity.InfinityMod; 4import net.lerariemann.infinity.access.MinecraftServerAccess; 5import net.lerariemann.infinity.registry.core.ModBlocks; 6import net.minecraft.core.BlockPos; 7import net.minecraft.server.level.ServerLevel; 8import net.minecraft.server.level.ServerPlayer; 9import net.minecraft.world.level.block.Blocks; 10import net.minecraft.world.level.block.state.BlockState; 11import java.util.HashMap; 12import java.util.Map; 13import java.util.Set; 14 15public class ConfigGenInvocation { 16 protected Map<String, BlockState> map; 17 public static int[] offsets = new int[]{-1, 0, 1}; 18 public static int[] offsets_y = new int[]{1, 2, 3}; 19 public ServerLevel world; 20 public BlockPos pos; 21 22 public static void invokeOn(ServerPlayer player) { 23 //? if <1.21.2 { 24 /*ServerLevel w = player.serverLevel(); 25 int y = w.getMaxBuildHeight() - 10; 26 *///?} else { 27 ServerLevel w = player.level(); 28 int y= w.getMaxY(); 29 //?} 30 BlockPos pos = new BlockPos(player.getBlockX(), y, player.getBlockZ()); 31 (new ConfigGenInvocation(w, pos)).run(); 32 } 33 34 public ConfigGenInvocation(ServerLevel w, BlockPos p) { 35 world = w; 36 pos = p; 37 map = new HashMap<>(); 38 } 39 40 public void run() { 41 InfinityMod.LOGGER.info("Invoking the name of the Cosmic Altar..."); 42 //setting up space 43 map.put("0,0,0", world.getBlockState(pos)); 44 world.setBlockAndUpdate(pos, ModBlocks.COSMIC_ALTAR.get().defaultBlockState()); 45 for (int i : offsets) for (int j : offsets_y) for (int k : offsets) { 46 map.put(i + "," + j + "," + k, world.getBlockState(pos.offset(i, j, k))); 47 world.setBlockAndUpdate(pos.offset(i, j, k), Blocks.AIR.defaultBlockState()); 48 } 49 //invocation 50 ConfigGenerator.generateAll(world.getServer()); 51 Set<String> fluidBlockNames = ConfigGenerator.generateFluids(); 52 ConfigGenerator.generateBlocks(world, pos.above(2), pos.above(), fluidBlockNames); 53 //putting everything back 54 for (int i : offsets) for (int j : offsets_y) for (int k : offsets) { 55 world.setBlockAndUpdate(pos.offset(i, j, k), fromMap(i, j, k)); 56 } 57 world.setBlockAndUpdate(pos, fromMap(0, 0, 0)); 58 59 ((MinecraftServerAccess)world.getServer()).infinity$onInvocation(); 60 } 61 62 BlockState fromMap(int i, int j, int k) { 63 BlockState s = map.get(i + "," + j + "," + k); 64 if (s==null) s = Blocks.AIR.defaultBlockState(); 65 return s; 66 } 67}