// Get instance manager
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
// Create new instance
InstanceContainer lobby = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);
// Configure instance
lobby.setTime(1000); // Set to day
lobby.setTimeRate(20); // Normal time passage
lobby.setDifficulty(Difficulty.EASY);
// Create flat world
for (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 instance
Player player = // ... get player
player.setInstance(lobby);
player.teleport(new Pos(0, 64, 0));
// Get all players in instance
List<Player> players = lobby.getPlayers();
// Create instance from saved world
InstanceContainer 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 instance
lobby.setBlock(new Pos(0, 64, 0), Block.SPONGE);
lobby.setBlock(new Pos(5, 64, 5), Block.DIAMOND_BLOCK);
// Get block from instance
Block block = lobby.getBlock(new Pos(0, 64, 0));
// Instance-specific properties
lobby.setTimeRate(0); // Freeze time
lobby.setDifficulty(Difficulty.HARD);
// Each instance is independent
InstanceContainer gameWorld1 = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);
InstanceContainer gameWorld2 = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);
// These are completely separate worlds