network: fix some null in pre-flattening versions

This commit is contained in:
Bixilon 2023-03-21 20:44:53 +01:00
parent a0736183aa
commit 823cd21a07
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 12 additions and 7 deletions

View File

@ -52,7 +52,7 @@ class EntityPlayerS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val rotation = buffer.readEntityRotation()
if (buffer.versionId < ProtocolVersions.V_15W31A) {
buffer.connection.registries.item[buffer.readUnsignedShort()] // current item
buffer.connection.registries.item.getOrNull(buffer.readUnsignedShort()) // current item
}
var data: Int2ObjectOpenHashMap<Any?>? = null

View File

@ -141,20 +141,21 @@ class PlayInByteBuffer : InByteBuffer {
fun readItemStack(): ItemStack? {
if (versionId < V_1_13_2_PRE1) {
val id = readShort().toInt()
if (id == -1) {
if (id <= 0) {
return null
}
val count = readUnsignedByte()
var metaData = 0
var meta = 0
if (!connection.version.flattened) {
metaData = readUnsignedShort()
meta = readUnsignedShort()
}
val nbt = readNBT()?.toMutableJsonObject()
val nbt = readNBTTag()?.toMutableJsonObject()
val item = connection.registries.item.getOrNull(id shl 16 or meta) ?: return null
return ItemStackUtil.of(
item = connection.registries.item[id shl 16 or metaData],
item = item,
connection = connection,
count = count,
durability = metaData,
durability = meta,
nbt = nbt ?: mutableMapOf(),
)
}

View File

@ -59,6 +59,10 @@ class Version(
PacketDirections.SERVER_TO_CLIENT -> s2c
}
operator fun compareTo(version: Version): Int {
return this.versionId.compareTo(version.versionId)
}
val flattened: Boolean get() = versionId >= V_17W47A
val hasOffhand: Boolean get() = versionId >= V_15W31A
val maxPacketLength get() = if (versionId < V_1_17_1_RC2) 1 shl 21 else 1 shl 23