Skip to content

Commit 69f3b75

Browse files
committed
Send client settings to reduce view distance.
1 parent 0fc08ef commit 69f3b75

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

src/screens/chat/packetHandler.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import React from 'react'
22
import { Status } from './ChatScreen'
33
import { MinecraftChat, parseValidJson } from '../../minecraft/chatToJsx'
44
import { ServerConnection } from '../../minecraft/connection'
5-
import { Packet } from '../../minecraft/packet'
5+
import {
6+
concatPacketData,
7+
Packet,
8+
PacketDataTypes
9+
} from '../../minecraft/packet'
610
import { protocolMap, readVarInt, writeVarInt } from '../../minecraft/utils'
711
import { makeChatMessagePacket } from '../../minecraft/packets/chat'
812

913
export const enderChatPrefix = '\u00A74[\u00A7cEnderChat\u00A74] \u00A7c'
1014
export const parseMessageError = 'An error occurred when parsing chat.'
15+
export const clientSettingsError =
16+
'An error occurred when sending client settings.'
1117
export const inventoryCloseError =
1218
'An error occurred when closing an inventory window.'
1319
export const respawnError =
@@ -108,9 +114,37 @@ export const packetHandler =
108114
}
109115

110116
const is117 = protocolVersion >= protocolMap[1.17]
117+
const is118 = protocolVersion >= protocolMap[1.18]
111118
const is119 = protocolVersion >= protocolMap[1.19]
112119
const is1191 = protocolVersion >= protocolMap['1.19.1']
113120
if (
121+
/* Login (play) */
122+
(packet.id === 0x24 && !is117) ||
123+
(packet.id === 0x26 && is117 && !is119) ||
124+
(packet.id === 0x23 && is119 && !is1191) ||
125+
(packet.id === 0x25 && is1191)
126+
) {
127+
// Send Client Settings packet.
128+
const clientSettingsId = is119 ? (is1191 ? 0x08 : 0x07) : 0x05
129+
const viewDistance = Buffer.alloc(1)
130+
viewDistance.writeInt8(2)
131+
const skinParts = Buffer.alloc(1)
132+
skinParts.writeUInt8(0b11111111)
133+
// TODO: Intl in future? And other setting changes too.
134+
const packetData: PacketDataTypes[] = [
135+
'en_US',
136+
viewDistance,
137+
writeVarInt(0),
138+
true,
139+
skinParts,
140+
writeVarInt(1)
141+
]
142+
if (is117) packetData.push(!is118)
143+
if (is118) packetData.push(true)
144+
connection
145+
.writePacket(clientSettingsId, concatPacketData(packetData))
146+
.catch(handleError(addMessage, clientSettingsError))
147+
} else if (
114148
/* Respawn */
115149
(packet.id === 0x39 && !is117) ||
116150
(packet.id === 0x3d && is117 && !is119) ||

0 commit comments

Comments
 (0)