From f1596c53ff419f3b9b3b725f0834aa76e2bfb8d5 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Thu, 6 Feb 2025 22:11:43 +0100 Subject: [PATCH] block entity receiving: don't process empty nbt --- .../minosoft/data/world/chunk/chunk/ChunkPrototype.kt | 7 +++++-- .../protocol/packets/s2c/play/block/chunk/ChunkS2CP.kt | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/data/world/chunk/chunk/ChunkPrototype.kt b/src/main/java/de/bixilon/minosoft/data/world/chunk/chunk/ChunkPrototype.kt index 572d45948..4ebb68ff9 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/chunk/chunk/ChunkPrototype.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/chunk/chunk/ChunkPrototype.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -101,6 +101,7 @@ class ChunkPrototype( } private fun Map?.update(minSection: Int, chunk: Chunk, affected: IntOpenHashSet?, session: PlaySession) { + val empty = isNullOrEmpty() val position = Vec3i() for ((index, section) in chunk.sections.withIndex()) { if (section == null || section.blocks.isEmpty) continue @@ -123,7 +124,9 @@ class ChunkPrototype( entity = block.createBlockEntity(session) ?: continue section.blockEntities[index] = entity } - this?.get(position)?.let { entity.updateNBT(it) } + if (!empty) { + this!![position]?.let { entity.updateNBT(it) } + } affected?.add(sectionHeight) } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/block/chunk/ChunkS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/block/chunk/ChunkS2CP.kt index 2dbfa16b3..0433707ec 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/block/chunk/ChunkS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/block/chunk/ChunkS2CP.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -118,7 +118,7 @@ class ChunkS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket { if (versionId < V_1_9_4) return null val count = readVarInt() if (count <= 0) return null - val entities: MutableMap = hashMapOf() + val entities: MutableMap = HashMap(count) when { versionId < V_21W37A -> { @@ -127,6 +127,7 @@ class ChunkS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket { val nbt = readNBT()?.asJsonObject() ?: continue val position = Vec3i(nbt["x"]?.toInt() ?: continue, nbt["y"]?.toInt() ?: continue, nbt["z"]?.toInt() ?: continue) - positionOffset val id = (nbt["id"]?.toResourceLocation() ?: continue).fixBlockEntity() + if (nbt.size <= 4) continue // no additional data val type = session.registries.blockEntityType[id] ?: continue entities[position] = nbt @@ -139,6 +140,7 @@ class ChunkS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket { val y = readShort() val type = session.registries.blockEntityType.getOrNull(readVarInt()) val nbt = readNBT()?.asJsonObject() ?: continue + if (nbt.isEmpty()) continue if (type == null) continue entities[Vec3i(xz shr 4, y, xz and 0x0F)] = nbt