Skip to content

Commit

Permalink
Add extension functions for retrieving worlds by id
Browse files Browse the repository at this point in the history
Signed-off-by: solonovamax <[email protected]>
  • Loading branch information
solonovamax committed Aug 3, 2024
1 parent a5b6886 commit fed4707
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package net.silkmc.silk.core.server

import net.minecraft.commands.CommandSourceStack
import net.minecraft.core.registries.Registries
import net.minecraft.resources.ResourceKey
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.MinecraftServer
import net.minecraft.server.level.ServerLevel
import net.minecraft.server.level.ServerPlayer
import java.nio.file.Path
import kotlin.io.path.absolute
Expand Down Expand Up @@ -42,3 +46,37 @@ val MinecraftServer.players: List<ServerPlayer>
)
val MinecraftServer.serverPath: Path
get() = serverDirectory.absolute()

/**
* Retrieves the level for an associated with an id is present
*
* @param id The id of the level to check
* @return The level
*/
fun MinecraftServer.getLevel(id: ResourceLocation): ServerLevel? = getLevel(ResourceKey.create(Registries.DIMENSION, id))

// alias for yarn
/**
* Retrieves the world for an associated with an id is present
*
* @param id The id of the world to check
* @return The world
*/
fun MinecraftServer.getWorld(id: ResourceLocation): ServerLevel? = getLevel(id)

/**
* Checks if the level associated with an id is present
*
* @param id The id of the level to check
* @return If the level is present
*/
fun MinecraftServer.hasLevel(id: ResourceLocation): Boolean = getLevel(id) != null

// alias for yarn
/**
* Checks if the world associated with an id is present
*
* @param id The id of the world to check
* @return If the world is present
*/
fun MinecraftServer.hasWorld(id: ResourceLocation): Boolean = hasLevel(id)

0 comments on commit fed4707

Please sign in to comment.