From fed47073978ba494be2e98aec403080cc94e865a Mon Sep 17 00:00:00 2001 From: solonovamax Date: Sat, 3 Aug 2024 18:15:30 -0400 Subject: [PATCH] Add extension functions for retrieving worlds by id Signed-off-by: solonovamax --- .../silk/core/server/ServerExtensions.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/silk-core/src/main/kotlin/net/silkmc/silk/core/server/ServerExtensions.kt b/silk-core/src/main/kotlin/net/silkmc/silk/core/server/ServerExtensions.kt index f9ec9a74..5714b68b 100644 --- a/silk-core/src/main/kotlin/net/silkmc/silk/core/server/ServerExtensions.kt +++ b/silk-core/src/main/kotlin/net/silkmc/silk/core/server/ServerExtensions.kt @@ -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 @@ -42,3 +46,37 @@ val MinecraftServer.players: List ) 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)