Code

// Get instance managerInstanceManager instanceManager = MinecraftServer.getInstanceManager();// Create new instanceInstanceContainer lobby = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);// Configure instancelobby.setTime(1000); // Set to daylobby.setTimeRate(20); // Normal time passagelobby.setDifficulty(Difficulty.EASY);// Create flat worldfor (int x = -10; x <= 10; x++) {    for (int z = -10; z <= 10; z++) {        for (int y = 0; y < 64; y++) {            if (y == 0) {                lobby.setBlock(new Pos(x, y, z), Block.BEDROCK);            } else if (y < 61) {                lobby.setBlock(new Pos(x, y, z), Block.STONE);            } else if (y < 63) {                lobby.setBlock(new Pos(x, y, z), Block.DIRT);            } else {                lobby.setBlock(new Pos(x, y, z), Block.GRASS_BLOCK);            }        }    }}// Move player to instancePlayer player = // ... get playerplayer.setInstance(lobby);player.teleport(new Pos(0, 64, 0));// Get all players in instanceList<Player> players = lobby.getPlayers();// Create instance from saved worldInstanceContainer survivalWorld = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);survivalWorld.setChunkLoader(new AnvilLoader(Path.of("worlds/survival")));// Create void world (empty)InstanceContainer voidWorld = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);// No blocks placed = void world// Set blocks in instancelobby.setBlock(new Pos(0, 64, 0), Block.SPONGE);lobby.setBlock(new Pos(5, 64, 5), Block.DIAMOND_BLOCK);// Get block from instanceBlock block = lobby.getBlock(new Pos(0, 64, 0));// Instance-specific propertieslobby.setTimeRate(0); // Freeze timelobby.setDifficulty(Difficulty.HARD);// Each instance is independentInstanceContainer gameWorld1 = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);InstanceContainer gameWorld2 = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);// These are completely separate worlds

Comments

No comments yet. Be the first!