diff --git a/andesite-protocol/andesite-protocol-common/src/jvmMain/kotlin/resource.kt b/andesite-protocol/andesite-protocol-common/src/jvmMain/kotlin/resource.kt index cffa077..2bb8ead 100644 --- a/andesite-protocol/andesite-protocol-common/src/jvmMain/kotlin/resource.kt +++ b/andesite-protocol/andesite-protocol-common/src/jvmMain/kotlin/resource.kt @@ -24,3 +24,9 @@ public fun resource(path: String): File { ?.let(::File) ?: error("Can not find resource $path") } + +public fun readResource(path: String): ByteArray { + return ClassLoader.getSystemResource(path) + ?.readBytes() + ?: error("Can not find resource $path") +} diff --git a/andesite-server/andesite-server-java/src/jvmMain/kotlin/server/JavaMinecraftServer.kt b/andesite-server/andesite-server-java/src/jvmMain/kotlin/server/JavaMinecraftServer.kt index 90f3063..056d6e7 100644 --- a/andesite-server/andesite-server-java/src/jvmMain/kotlin/server/JavaMinecraftServer.kt +++ b/andesite-server/andesite-server-java/src/jvmMain/kotlin/server/JavaMinecraftServer.kt @@ -34,7 +34,6 @@ import andesite.protocol.java.data.Dimension import andesite.protocol.java.data.DimensionCodec import andesite.protocol.java.handshake.HandshakePacket import andesite.protocol.java.handshake.NextState -import andesite.protocol.resource import andesite.protocol.serialization.MinecraftCodec import andesite.protocol.serialization.extractMinecraftVersion import andesite.server.Messageable @@ -93,9 +92,9 @@ internal class JavaMinecraftServer( override val protocolVersion = codec.configuration.protocolVersion override val minecraftVersion = extractMinecraftVersion(codec.configuration.protocolVersion) - internal val dimensionCodec = nbt.decodeRootTag(resource("dimension_codec.nbt")) + internal val dimensionCodec = nbt.decodeRootTag("dimension_codec.nbt") - internal val dimension = nbt.decodeRootTag(resource("dimension.nbt")) + internal val dimension = nbt.decodeRootTag("dimension.nbt") internal suspend fun addPlayer(player: JavaPlayer) { playersMutex.withLock { playersMut.add(player) } diff --git a/andesite-server/andesite-server-java/src/jvmMain/kotlin/utils.kt b/andesite-server/andesite-server-java/src/jvmMain/kotlin/utils.kt index 4e6c1c9..791b73f 100644 --- a/andesite-server/andesite-server-java/src/jvmMain/kotlin/utils.kt +++ b/andesite-server/andesite-server-java/src/jvmMain/kotlin/utils.kt @@ -19,6 +19,7 @@ package andesite.java import andesite.protocol.java.v756.ChunkDataPacket +import andesite.protocol.readResource import andesite.protocol.types.VarInt import andesite.server.MinecraftServer import andesite.world.Chunk @@ -26,7 +27,6 @@ import andesite.world.anvil.AnvilChunk import andesite.world.anvil.HeightmapUsage import io.ktor.utils.io.core.BytePacketBuilder import io.ktor.utils.io.core.readBytes -import java.io.File import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.decodeFromByteArray import kotlinx.serialization.descriptors.serialDescriptor @@ -40,13 +40,13 @@ import org.apache.logging.log4j.kotlin.logger private val logger = logger("andesite.Utils") -inline fun Nbt.decodeRootTag(file: File): T { +inline fun Nbt.decodeRootTag(path: String): T { val descriptor = serialDescriptor() return decodeFromNbtTag( buildNbtCompound { - val root = decodeFromByteArray(file.readBytes()) - val content = root[""]?.nbtCompound ?: error("Could not find content for nbt file $file") + val root = decodeFromByteArray(readResource(path)) + val content = root[""]?.nbtCompound ?: error("Could not find content for nbt path $path") put(descriptor.serialName, content) }, diff --git a/gradle.properties b/gradle.properties index 8f0c5a2..e1dbe2a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,4 @@ kotlin.js.generate.executable.default=false kotlin.mpp.stability.nowarn=true group=me.gabrielleeg1 -version=1.0.1-SNAPSHOT +version=1.0.2-SNAPSHOT