network: 23w40a

New game state: `receive_chunks`, json chat was replaced with nbt on network
This commit is contained in:
Moritz Zwerger 2023-10-08 00:25:54 +02:00
parent 6955fae49e
commit d143b98a63
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
25 changed files with 97 additions and 33 deletions

View File

@ -19,6 +19,8 @@ import de.bixilon.kutil.json.JsonObject
import de.bixilon.kutil.uuid.UUIDUtil.toUUID
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.protocol.buffers.InByteBuffer
import de.bixilon.minosoft.protocol.protocol.buffers.OutByteBuffer
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.json.Jackson
import java.util.*
@ -48,7 +50,10 @@ data class EntityHoverEvent(
type = it.toResourceLocation()
}
return EntityHoverEvent(json["id"].toString().toUUID(), type, ChatComponent.of(json["name"]))
val rawUUID = json["id"]
val uuid = if (rawUUID is IntArray) InByteBuffer(OutByteBuffer().apply { writeBareIntArray(rawUUID) }.toArray()).readUUID() else rawUUID.toString().toUUID()
return EntityHoverEvent(uuid, type, ChatComponent.of(json["name"]))
}
}
}

View File

@ -24,7 +24,7 @@ import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class KickS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val reason: ChatComponent = buffer.readChatComponent()
val reason: ChatComponent = if (buffer.connection.network.state == ProtocolStates.LOGIN) buffer.readChatComponent() else buffer.readNbtChatComponent()
override fun handle(connection: PlayConnection) {
if (!connection.network.connected) {

View File

@ -39,7 +39,7 @@ class ResourcepackS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
init {
if (buffer.versionId >= ProtocolVersions.V_21W15A) {
promptText = buffer.readOptional { buffer.readChatComponent() }
promptText = buffer.readOptional { buffer.readNbtChatComponent() }
}
}

View File

@ -21,7 +21,7 @@ import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class PlayStatusS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val motd = if (buffer.versionId >= ProtocolVersions.V_23W07A) buffer.readChatComponent() else buffer.readOptional { buffer.readChatComponent() }
val motd = if (buffer.versionId >= ProtocolVersions.V_23W07A) buffer.readNbtChatComponent() else buffer.readOptional { buffer.readNbtChatComponent() }
val favicon = if (buffer.versionId >= ProtocolVersions.V_23W07A) buffer.readOptional { buffer.readByteArray() } else buffer.readOptional { buffer.readString().toFavicon() }
val previewsChat = if (buffer.versionId < ProtocolVersions.V_22W42A) buffer.readBoolean() else false
val forcesSecureChat = if (buffer.versionId >= ProtocolVersions.V_1_19_1_RC2) buffer.readBoolean() else null

View File

@ -19,7 +19,7 @@ import de.bixilon.minosoft.data.bossbar.BossbarFlags
import de.bixilon.minosoft.data.bossbar.BossbarNotches
import de.bixilon.minosoft.modding.event.events.bossbar.BossbarAddEvent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.protocol.buffers.InByteBuffer
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
@ -27,9 +27,9 @@ import java.util.*
class AddBossbarS2CP(
val uuid: UUID,
buffer: InByteBuffer,
buffer: PlayInByteBuffer,
) : BossbarS2CP {
val title = buffer.readChatComponent()
val title = buffer.readNbtChatComponent()
val value = buffer.readFloat()
val color = BossbarColors[buffer.readVarInt()]
val notches = BossbarNotches[buffer.readVarInt()]

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.protocol.packets.s2c.play.bossbar
import de.bixilon.minosoft.modding.event.events.bossbar.BossbarTitleSetEvent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.protocol.buffers.InByteBuffer
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
@ -23,9 +23,9 @@ import java.util.*
class TitleBossbarS2CP(
val uuid: UUID,
buffer: InByteBuffer,
buffer: PlayInByteBuffer,
) : BossbarS2CP {
val title = buffer.readChatComponent()
val title = buffer.readNbtChatComponent()
override fun handle(connection: PlayConnection) {
val bossbar = connection.bossbarManager.bossbars[uuid] ?: return

View File

@ -32,7 +32,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType
import java.util.*
class ChatMessageS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val text: ChatComponent = buffer.readChatComponent()
val text: ChatComponent = buffer.readNbtChatComponent()
var type: ChatMessageType = buffer.connection.registries.messageType[DefaultMessageTypes.CHAT]!!
private set
var sender: UUID? = null

View File

@ -98,7 +98,7 @@ class SignedChatMessageS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val message = readChatComponent().message
if (versionId >= ProtocolVersions.V_1_19_1_PRE5 && versionId < ProtocolVersions.V_22W42A) {
readOptional { readChatComponent() } // formatted text
readOptional { readNbtChatComponent() } // formatted text
}
val sent = readInstant()
@ -106,7 +106,7 @@ class SignedChatMessageS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val lastSeen = readArray { if (versionId >= ProtocolVersions.V_22W42A) readIndexedLastSeenMessage() else readLastSeenMessage() }
parameters[ChatParameter.CONTENT] = TextComponent(message)
val unsigned = readOptional { readChatComponent() }
val unsigned = readOptional { readNbtChatComponent() }
var filter: Filter? = null
if (versionId >= ProtocolVersions.V_1_19_1_RC3) {
filter = ChatFilter[readVarInt()].reader.invoke(this)

View File

@ -24,7 +24,7 @@ import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class UnsignedChatMessageS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val text: ChatComponent = buffer.readChatComponent()
val text: ChatComponent = buffer.readNbtChatComponent()
val type = buffer.readRegistryItem(buffer.connection.registries.messageType)
val parameters: Map<ChatParameter, ChatComponent> = mutableMapOf<ChatParameter, ChatComponent>().apply {
buffer.readChatMessageParameters(this)

View File

@ -22,7 +22,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType
class KillCombatEventS2CP(buffer: PlayInByteBuffer) : CombatEventS2CP {
val deadEntityId = buffer.readVarInt()
val killerEntityId = if (buffer.versionId >= V_1_20_PRE3) -1 else buffer.readInt()
val message = buffer.readChatComponent()
val message = buffer.readNbtChatComponent()
override fun log(reducedLog: Boolean) {
Log.log(LogMessageType.NETWORK_IN, level = LogLevels.VERBOSE) { "Combat event kill (deadEntityId=$deadEntityId, killerEntityId=$killerEntityId, message=$message )" }

View File

@ -35,7 +35,7 @@ class OpenContainerS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
buffer.versionId < V_1_14 -> buffer.readLegacyRegistryItem(buffer.connection.registries.containerType)!! // TODO: version completely guessed
else -> buffer.readRegistryItem(buffer.connection.registries.containerType)
}
val title: ChatComponent = buffer.readChatComponent()
val title: ChatComponent = buffer.readNbtChatComponent()
val slotCount: Int = if (buffer.versionId <= V_19W02A) buffer.readUnsignedByte() else 0 // ToDo: This is completely guessed, it is not present in 1.16.5 (unchecked)
val hasTitle: Boolean = if (buffer.versionId > V_14W03B && buffer.versionId <= V_1_8_9) buffer.readBoolean() else true // TODO: upper version (1.8) is probably worng. it changed between 1.7.10..1.8
var entityId: Int? = if ((buffer.versionId >= V_19W02A && containerType.identifier == DefaultInventoryTypes.HORSE) || buffer.versionId < V_14W03B) {

View File

@ -37,7 +37,7 @@ class CreateObjectiveS2CP(
init {
if (buffer.versionId >= ProtocolVersions.V_14W04A) { // ToDo
this._displayName = buffer.readChatComponent()
this._displayName = buffer.readNbtChatComponent()
}
if (buffer.versionId >= ProtocolVersions.V_14W08A) {
when {

View File

@ -24,7 +24,7 @@ object ObjectiveS2CF : PlayPacketFactory {
override fun create(buffer: PlayInByteBuffer): ObjectiveS2CP {
val objective = buffer.readString()
val displayName = if (buffer.versionId < ProtocolVersions.V_14W04A) { // ToDo
buffer.readChatComponent()
buffer.readNbtChatComponent()
} else {
null
}

View File

@ -34,7 +34,7 @@ class UpdateObjectiveS2CP(
init {
if (buffer.versionId >= ProtocolVersions.V_14W04A) { // ToDo
this._displayName = buffer.readChatComponent()
this._displayName = buffer.readNbtChatComponent()
}
if (buffer.versionId >= ProtocolVersions.V_14W08A) {
when {

View File

@ -33,7 +33,7 @@ class CreateTeamS2CP(
val name: String,
buffer: PlayInByteBuffer,
) : TeamsS2CP {
val displayName = buffer.readChatComponent()
val displayName = buffer.readNbtChatComponent()
lateinit var prefix: ChatComponent
private set
lateinit var suffix: ChatComponent
@ -53,8 +53,8 @@ class CreateTeamS2CP(
init {
if (buffer.versionId < ProtocolVersions.V_18W01A) {
this.prefix = buffer.readChatComponent()
this.suffix = buffer.readChatComponent()
this.prefix = buffer.readNbtChatComponent()
this.suffix = buffer.readNbtChatComponent()
}
if (buffer.versionId < ProtocolVersions.V_16W06A) { // ToDo
@ -79,8 +79,8 @@ class CreateTeamS2CP(
}
if (buffer.versionId >= ProtocolVersions.V_18W20A) {
prefix = buffer.readChatComponent()
suffix = buffer.readChatComponent()
prefix = buffer.readNbtChatComponent()
suffix = buffer.readNbtChatComponent()
}
members = buffer.readArray(

View File

@ -21,8 +21,8 @@ import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class TabListTextS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val header: ChatComponent = buffer.readChatComponent()
val footer: ChatComponent = buffer.readChatComponent()
val header: ChatComponent = buffer.readNbtChatComponent()
val footer: ChatComponent = buffer.readNbtChatComponent()
override fun handle(connection: PlayConnection) {
connection.tabList.header = header

View File

@ -23,7 +23,7 @@ import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class HotbarTextS2CP(buffer: PlayInByteBuffer) : TitleS2CP {
val text = buffer.readChatComponent()
val text = buffer.readNbtChatComponent()
override fun log(reducedLog: Boolean) {
Log.log(LogMessageType.NETWORK_IN, level = LogLevels.VERBOSE) { "Hotbar text (text=$text)" }

View File

@ -21,7 +21,7 @@ import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class SubtitleS2CP(buffer: PlayInByteBuffer) : TitleS2CP {
val text = buffer.readChatComponent()
val text = buffer.readNbtChatComponent()
override fun handle(connection: PlayConnection) {
connection.events.fire(TitleSubtitleSetEvent(connection, this))

View File

@ -21,7 +21,7 @@ import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class TitleTextS2CP(buffer: PlayInByteBuffer) : TitleS2CP {
val text = buffer.readChatComponent()
val text = buffer.readNbtChatComponent()
override fun handle(connection: PlayConnection) {
connection.events.fire(TitleSetEvent(connection, this))

View File

@ -14,6 +14,7 @@ package de.bixilon.minosoft.protocol.protocol
@Suppress("UNUSED")
object ProtocolVersions {
const val V_23W40A = 916
const val V_1_20_2 = 915
const val V_1_20_2_RC2 = 914
const val V_1_20_2_RC1 = 913

View File

@ -15,9 +15,10 @@ package de.bixilon.minosoft.protocol.protocol
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_13W41B
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_20_2
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_23W40A
object VersionSupport {
const val MINIMUM_VERSION = V_13W41B
const val LATEST_VERSION = V_1_20_2
const val LATEST_VERSION = V_23W40A
const val LATEST_RELEASE = V_1_20_2
}

View File

@ -107,6 +107,14 @@ class PlayInByteBuffer : InByteBuffer {
return ChatComponent.of(string, connection.language, null, restricted = true)
}
fun readNbtChatComponent(): ChatComponent {
if (versionId < ProtocolVersions.V_23W40A) {
return readChatComponent()
}
val nbt = readNBT()
return ChatComponent.of(nbt, connection.language, null, restricted = true)
}
fun readParticleData(): ParticleData {
val type = connection.registries.particleType[readVarInt()]
return readParticleData(type)
@ -333,8 +341,8 @@ class PlayInByteBuffer : InByteBuffer {
}
fun readChatMessageParameters(parameters: MutableMap<ChatParameter, ChatComponent>) {
parameters[ChatParameter.SENDER] = readChatComponent()
readOptional { readChatComponent() }?.let { parameters[ChatParameter.TARGET] = it }
parameters[ChatParameter.SENDER] = readNbtChatComponent()
readOptional { readNbtChatComponent() }?.let { parameters[ChatParameter.TARGET] = it }
}
fun readSoundPitch(): Float {

File diff suppressed because one or more lines are too long

View File

@ -627,6 +627,50 @@
"minecraft:limited_crafting": {
"id": 12
}
},
"916": {
"minecraft:bed_break": {
"id": 0
},
"minecraft:rain_start": {
"id": 1
},
"minecraft:rain_stop": {
"id": 2
},
"minecraft:gamemode_change": {
"id": 3
},
"minecraft:win_game": {
"id": 4
},
"minecraft:hide_demo_messages": {
"id": 5
},
"minecraft:arrow_player_hit": {
"id": 6
},
"minecraft:rain_gradient_set": {
"id": 7
},
"minecraft:thunder_gradient_set": {
"id": 8
},
"minecraft:pufferfish_sting": {
"id": 9
},
"minecraft:elder_guardian_effect": {
"id": 10
},
"minecraft:immediate_respawn": {
"id": 11
},
"minecraft:limited_crafting": {
"id": 12
},
"minecraft:receive_chunks": {
"id": 13
}
}
},
"minecraft:world_events": {

View File

@ -1,4 +1,9 @@
{
"916": {
"name": "23w40a",
"protocol_id": 1073741978,
"packets": 910
},
"915": {
"name": "1.20.2",
"protocol_id": 764,