Package net.commoble.infiniverse.api

# Interface InfiniverseAPI

All Known Implementing Classes:
  `DimensionManager`

public interface InfiniverseAPI
API for creating and removing dimensions/levels during game runtime.
Static (single/individual) dimensions like the nether should be declared in json instead of using InfiniverseAPI to create them.

## Method Summary

Modifier and Type
Method
Description
`static InfiniverseAPI`
`get()`
`Set<net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level>>`
`getLevelsPendingUnregistration()`
`net.minecraft.server.level.ServerLevel`
`getOrCreateLevel(net.minecraft.server.MinecraftServer server, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> levelKey, Supplier<net.minecraft.world.level.dimension.LevelStem> dimensionFactory)`
Gets a level, dynamically creating and registering one if it doesn't exist.
The dimension registry is stored in the server's level file, all previously registered dimensions are loaded and recreated and reregistered whenever the server starts.
This can be used for making dynamic dimensions at runtime; static dimensions should be defined in json instead.
`void`
`markDimensionForUnregistration(net.minecraft.server.MinecraftServer server, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> levelToRemove)`
Schedules a non-vanilla level/dimension to be unregistered and removed at the end of the current server tick.
This will have the following effects:
Unregistered levels will stop ticking.

## Method Details

### get

static InfiniverseAPI get()

Returns:
  The API. For best results, avoid caching this, and only use while the server is running.

### getOrCreateLevel

net.minecraft.server.level.ServerLevel getOrCreateLevel(net.minecraft.server.MinecraftServer server, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> levelKey, Supplier<net.minecraft.world.level.dimension.LevelStem> dimensionFactory)
Gets a level, dynamically creating and registering one if it doesn't exist.
The dimension registry is stored in the server's level file, all previously registered dimensions are loaded and recreated and reregistered whenever the server starts.
This can be used for making dynamic dimensions at runtime; static dimensions should be defined in json instead.

Parameters:
  `server` - a MinecraftServer instance (you can get this from a ServerPlayerEntity or ServerWorld)
  `levelKey` - A ResourceKey for your level
  `dimensionFactory` - A function that produces a new LevelStem (dimension) instance if necessary
  If this factory is used, it should be assumed that intended dimension has not been created or registered yet, so making the factory attempt to get this dimension from the server's dimension registry will fail
Returns:
  Returns a ServerLevel, creating and registering a world and dimension for it if the world does not already exist

### markDimensionForUnregistration

void markDimensionForUnregistration(net.minecraft.server.MinecraftServer server, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> levelToRemove)
Schedules a non-vanilla level/dimension to be unregistered and removed at the end of the current server tick.
This will have the following effects:

- Unregistered levels will stop ticking.
- Unregistered dimensions will not be loaded on server startup unless and until they are registered again (via `DimensionManager.getOrCreateLevel(net.minecraft.server.MinecraftServer, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level>, java.util.function.Supplier<net.minecraft.world.level.dimension.LevelStem>)`.
- Players still present in the given level will, when the level is removed, be ejected to their spawn points.
- Players who have respawn points in levels being unloaded will have their spawn points reset to the overworld and respawned there.

Unregistering a level does not delete the region files or other persistant data associated with the level.
If a level is reregistered after unregistering it, the level will retain all prior data (unless manually deleted by a server admin.)
This has no effect on the vanilla dimensions (The Overworld, The Nether, and The End); this is because vanilla will automatically reconstitute these anyway if we try to remove them, so we disallow their removal to avoid strangeness.
(datapack dimensions removed here will also be reconstituted at next server startup but we can't filter these so we don't check for them)

Parameters:
  `server` - The server to remove the dimension from
  `levelToRemove` - The resource key for the level to be unregistered

### getLevelsPendingUnregistration

Set<net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level>> getLevelsPendingUnregistration()

Returns:
  An immutable copy of the dimensions that will be unregistered at the end of the current server tick. (returns an empty set if called while no server is running)