Skip to content

Commit 096c514

Browse files
committed
Fix 1.20.6 IDs, fix chat bug, support keybind chat
1 parent 3c47484 commit 096c514

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

android/app/src/main/java/com/enderchat/modules/connection/ConnectionModule.kt

+20-8
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,31 @@ class ConnectionModule(reactContext: ReactApplicationContext)
194194
val loginAcknowledgedId = 0x03
195195
val setCompressionId = 0x03
196196
// Configuration state packet IDs
197-
val configurationKeepAliveClientBoundId = 0x03
198-
val configurationKeepAliveServerBoundId = 0x03
199-
val finishConfigurationClientBoundId = 0x02
200-
val finishConfigurationServerBoundId = 0x02
197+
val configurationKeepAliveClientBoundId =
198+
if (protocolVersion >= PROTOCOL_VERSION_1205) 0x04
199+
else 0x03
200+
val configurationKeepAliveServerBoundId =
201+
if (protocolVersion >= PROTOCOL_VERSION_1205) 0x04
202+
else 0x03
203+
val finishConfigurationClientBoundId =
204+
if (protocolVersion >= PROTOCOL_VERSION_1205) 0x03
205+
else 0x02
206+
val finishConfigurationServerBoundId =
207+
if (protocolVersion >= PROTOCOL_VERSION_1205) 0x03
208+
else 0x02
201209
// Play state packet IDs
202210
val startConfigurationClientBoundId =
203-
if (protocolVersion >= PROTOCOL_VERSION_1203) 0x67
211+
if (protocolVersion >= PROTOCOL_VERSION_1205) 0x69
212+
else if (protocolVersion >= PROTOCOL_VERSION_1203) 0x67
204213
else if (protocolVersion >= PROTOCOL_VERSION_1202) 0x65
205214
else -1
206215
val acknowledgeConfigurationServerBoundId =
207-
if (protocolVersion >= PROTOCOL_VERSION_1202) 0x0b
216+
if (protocolVersion >= PROTOCOL_VERSION_1205) 0x0c
217+
else if (protocolVersion >= PROTOCOL_VERSION_1202) 0x0b
208218
else -1
209219
val playKeepAliveClientBoundId =
210-
if (protocolVersion >= PROTOCOL_VERSION_1202) 0x24
220+
if (protocolVersion >= PROTOCOL_VERSION_1205) 0x26
221+
else if (protocolVersion >= PROTOCOL_VERSION_1202) 0x24
211222
else if (protocolVersion >= PROTOCOL_VERSION_1194) 0x23
212223
else if (protocolVersion >= PROTOCOL_VERSION_1193) 0x1f
213224
else if (protocolVersion >= PROTOCOL_VERSION_1191) 0x20
@@ -216,7 +227,8 @@ class ConnectionModule(reactContext: ReactApplicationContext)
216227
else if (protocolVersion >= PROTOCOL_VERSION_1164) 0x1f
217228
else -1
218229
val playKeepAliveServerBoundId =
219-
if (protocolVersion >= PROTOCOL_VERSION_1203) 0x15
230+
if (protocolVersion >= PROTOCOL_VERSION_1205) 0x18
231+
else if (protocolVersion >= PROTOCOL_VERSION_1203) 0x15
220232
else if (protocolVersion >= PROTOCOL_VERSION_1202) 0x14
221233
else if (protocolVersion >= PROTOCOL_VERSION_1194) 0x12
222234
else if (protocolVersion >= PROTOCOL_VERSION_1193) 0x11

android/app/src/main/java/com/enderchat/modules/connection/Utils.kt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const val PROTOCOL_VERSION_1193 = 761
1818
const val PROTOCOL_VERSION_1194 = 762
1919
const val PROTOCOL_VERSION_1202 = 764
2020
const val PROTOCOL_VERSION_1203 = 765
21+
const val PROTOCOL_VERSION_1205 = 766
2122

2223
fun compressData(bytes: ByteArray): ByteArray {
2324
ByteArrayOutputStream(bytes.size).use {

src/minecraft/chatToJsx.tsx

+27-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type StyleProp, type TextProps, type TextStyle } from 'react-native'
33
import translationsJson from './translations.json'
44

55
const translations: Record<string, string> = translationsJson
6+
// Keybinds are not supported in EnderChat, so we'll just display the keybind as text in keybindChat
67

78
export const mojangColorMap: ColorMap = {
89
black: '#000000',
@@ -75,6 +76,10 @@ export interface TranslatedChat extends BaseChat {
7576
with: MinecraftChat[]
7677
}
7778

79+
export interface KeybindChat extends BaseChat {
80+
keybind: string
81+
}
82+
7883
export type MinecraftChat = PlainTextChat | TranslatedChat | string
7984

8085
export interface ClickEvent {
@@ -193,7 +198,8 @@ const trimComponentsByLine = (chat: PlainTextChat[]): PlainTextChat[] => {
193198
}
194199

195200
const isTranslatedChat = (chat: MinecraftChat): chat is TranslatedChat =>
196-
typeof (chat as TranslatedChat).translate === 'string'
201+
typeof (chat as TranslatedChat).translate === 'string' ||
202+
(chat as TranslatedChat).type === 'translatable'
197203

198204
const translateChat = (chat: TranslatedChat): PlainTextChat => {
199205
const { translate, with: tw, ...c } = chat
@@ -215,8 +221,28 @@ const translateChat = (chat: TranslatedChat): PlainTextChat => {
215221
}
216222
}
217223

224+
const isKeybindChat = (chat: MinecraftChat): chat is KeybindChat =>
225+
typeof (chat as KeybindChat).keybind === 'string' ||
226+
(chat as KeybindChat).type === 'keybind'
227+
228+
const keybindChat = (chat: KeybindChat): PlainTextChat => {
229+
const { keybind, ...c } = chat
230+
return { ...c, text: keybind }
231+
}
232+
218233
const flattenComponents = (chat: MinecraftChat): PlainTextChat[] => {
219234
if (typeof chat === 'string') return parseColorCodes(chat)
235+
// Fix components with empty string keys.....
236+
const looseChat = chat as any
237+
if (looseChat['']) {
238+
const key = isTranslatedChat(chat)
239+
? 'translate'
240+
: isKeybindChat(chat)
241+
? 'keybind'
242+
: 'text'
243+
looseChat[key] = looseChat['']
244+
}
245+
if (isKeybindChat(chat)) chat = keybindChat(chat)
220246
else if (isTranslatedChat(chat)) chat = translateChat(chat)
221247
const { extra, ...c } = chat
222248
const arr =

0 commit comments

Comments
 (0)