Skip to content

Commit

Permalink
Merge pull request #4 from gabrielleeg1/3-bug-tries-to-find-a-file-fo…
Browse files Browse the repository at this point in the history
…r-dimension-codec

3 bug tries to find a file for dimension codec
  • Loading branch information
aripiprazole authored Aug 15, 2022
2 parents 84ff47f + 5ee31d2 commit 06fa6bd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<DimensionCodec>(resource("dimension_codec.nbt"))
internal val dimensionCodec = nbt.decodeRootTag<DimensionCodec>("dimension_codec.nbt")

internal val dimension = nbt.decodeRootTag<Dimension>(resource("dimension.nbt"))
internal val dimension = nbt.decodeRootTag<Dimension>("dimension.nbt")

internal suspend fun addPlayer(player: JavaPlayer) {
playersMutex.withLock { playersMut.add(player) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
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
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
Expand All @@ -40,13 +40,13 @@ import org.apache.logging.log4j.kotlin.logger

private val logger = logger("andesite.Utils")

inline fun <reified T : Any> Nbt.decodeRootTag(file: File): T {
inline fun <reified T : Any> Nbt.decodeRootTag(path: String): T {
val descriptor = serialDescriptor<T>()

return decodeFromNbtTag(
buildNbtCompound {
val root = decodeFromByteArray<NbtCompound>(file.readBytes())
val content = root[""]?.nbtCompound ?: error("Could not find content for nbt file $file")
val root = decodeFromByteArray<NbtCompound>(readResource(path))
val content = root[""]?.nbtCompound ?: error("Could not find content for nbt path $path")

put(descriptor.serialName, content)
},
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 06fa6bd

Please sign in to comment.