diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/FriendlyStreams.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/FriendlyStreams.kt index d13b20bb5..c4e5ffbc5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/FriendlyStreams.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/FriendlyStreams.kt @@ -149,18 +149,6 @@ private const val TYPE_STRING = 0x05 private const val TYPE_ARRAY = 0x06 private const val TYPE_OBJECT = 0x07 -private fun fixSignedInt(read: Long): Long { - val sign = read and 0x1L - @Suppress("name_shadowing") - val read = read ushr 1 - - if (sign == 1L) { - return -read - 1L - } else { - return read - } -} - /** * Writes binary json to stream in Starbound Object Notation format * @@ -186,17 +174,9 @@ fun OutputStream.writeJson(element: JsonElement) { if (element.isNumber) { val num = element.asNumber - if (num is Int || num is Long) { + if (num is Int || num is Long || num is Short || num is Byte) { write(TYPE_INT) - var int = num.toLong() - - if (int < 0) { - int = int.absoluteValue.shl(1).or(1) - } else { - int.shl(1) - } - - writeVarLongLE(int) + writeVarLongLE(num.toLong()) } else if (num is Float || num is Double) { write(TYPE_DOUBLE) writeDouble(num.toDouble()) @@ -237,7 +217,7 @@ fun InputStream.readJson(sizeLimit: NbtAccounter = NbtAccounter(1L shl 18 /* 256 sizeLimit.accountBytes(1L) JsonPrimitive(read() > 1) } - TYPE_INT -> JsonPrimitive(fixSignedInt(readVarLongLE(sizeLimit))) + TYPE_INT -> JsonPrimitive(readVarLongLE(sizeLimit)) TYPE_STRING -> JsonPrimitive(readBinaryString(sizeLimit)) TYPE_ARRAY -> { val values = readVarIntLE(sizeLimit)