Skip to content

Commit 72058f1

Browse files
authored
feat: reimplement auto version - fix bugs, +config, make faster!! (#262)
1 parent 4a77ba1 commit 72058f1

14 files changed

+217
-268
lines changed

patches/[email protected]

-188
This file was deleted.

patches/[email protected]

-42
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js
2-
index 3fe1552672e4c0dd1b14b3b56950c3d7eaf3537b..6eb615e5827279c328d5547b5911626693252da4 100644
3-
--- a/src/client/autoVersion.js
4-
+++ b/src/client/autoVersion.js
5-
@@ -9,7 +9,7 @@ module.exports = function (client, options) {
6-
client.wait_connect = true // don't let src/client/setProtocol proceed on socket 'connect' until 'connect_allowed'
7-
debug('pinging', options.host)
8-
// TODO: use 0xfe ping instead for better compatibility/performance? https://github.com/deathcap/node-minecraft-ping
9-
- ping(options, function (err, response) {
10-
+ ping(options, async function (err, response) {
11-
if (err) { return client.emit('error', err) }
12-
debug('ping response', response)
13-
// TODO: could also use ping pre-connect to save description, type, max players, etc.
14-
@@ -40,6 +40,7 @@ module.exports = function (client, options) {
15-
16-
// Reinitialize client object with new version TODO: move out of its constructor?
17-
client.version = minecraftVersion
18-
+ await options.versionSelectedHook?.(client)
19-
client.state = states.HANDSHAKING
20-
21-
// Let other plugins such as Forge/FML (modinfo) respond to the ping response
221
diff --git a/src/client/chat.js b/src/client/chat.js
232
index f14269bea055d4329cd729271e7406ec4b344de7..00f5482eb6e3c911381ca9a728b1b4aae0d1d337 100644
243
--- a/src/client/chat.js
@@ -165,24 +144,3 @@ index 74749698f8cee05b5dc749c271544f78d06645b0..e77e0a3f41c1ee780c3abbd54b0801d2
165144
this.serializer.write({ name, params })
166145
}
167146

168-
diff --git a/src/index.d.ts b/src/index.d.ts
169-
index e61d5403bab46251d35b22a2ea30eb09b2746a26..84f597427893671eeac231b11e6e42aa815601df 100644
170-
--- a/src/index.d.ts
171-
+++ b/src/index.d.ts
172-
@@ -135,6 +135,7 @@ declare module 'minecraft-protocol' {
173-
sessionServer?: string
174-
keepAlive?: boolean
175-
closeTimeout?: number
176-
+ closeTimeout?: number
177-
noPongTimeout?: number
178-
checkTimeoutInterval?: number
179-
version?: string
180-
@@ -155,6 +156,8 @@ declare module 'minecraft-protocol' {
181-
disableChatSigning?: boolean
182-
/** Pass custom client implementation if needed. */
183-
Client?: Client
184-
+ /** Can be used to prepare mc data on autoVersion (client.version has selected version) */
185-
+ versionSelectedHook?: (client: Client) => Promise<void> | void
186-
}
187-
188-
export class Server extends EventEmitter {

pnpm-lock.yaml

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/makeOptimizedMcData.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,4 @@ const initialMcData = {
242242
}
243243
}
244244

245-
fs.writeFileSync('./generated/minecraft-initial-data.json', JSON.stringify(initialMcData), 'utf8')
245+
// fs.writeFileSync('./generated/minecraft-initial-data.json', JSON.stringify(initialMcData), 'utf8')

src/appParams.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const qsParams = new URLSearchParams(window.location.search)
1+
const qsParams = new URLSearchParams(window.location?.search ?? '')
22

33
export type AppQsParams = {
44
// AddServerOrConnect.tsx params
@@ -37,7 +37,7 @@ export type AppQsParams = {
3737
command?: string
3838
// Misc params
3939
suggest_save?: string
40-
scene?: string
40+
noPacketsValidation?: string
4141
}
4242

4343
export type AppQsParamsArray = {

src/connect.ts

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { versionsByMinecraftVersion } from 'minecraft-data'
2-
import minecraftInitialDataJson from '../generated/minecraft-initial-data.json'
1+
// import { versionsByMinecraftVersion } from 'minecraft-data'
2+
// import minecraftInitialDataJson from '../generated/minecraft-initial-data.json'
33
import { AuthenticatedAccount } from './react/ServersListProvider'
44
import { setLoadingScreenStatus } from './utils'
55
import { downloadSoundsIfNeeded } from './sounds/botSoundSystem'
66
import { miscUiState } from './globalState'
7+
import { options } from './optionsStorage'
8+
import supportedVersions from './supportedVersions.mjs'
79

810
export type ConnectOptions = {
911
server?: string
@@ -24,21 +26,39 @@ export type ConnectOptions = {
2426
viewerWsConnect?: string
2527
}
2628

27-
export const downloadNeededDataOnConnect = async (version: string) => {
28-
// todo expose cache
29-
const initialDataVersion = Object.keys(minecraftInitialDataJson)[0]!
30-
if (version === initialDataVersion) {
31-
// ignore cache hit
32-
versionsByMinecraftVersion.pc[initialDataVersion]!.dataVersion!++
29+
export const getVersionAutoSelect = (autoVersionSelect = options.serversAutoVersionSelect) => {
30+
if (autoVersionSelect === 'auto') {
31+
return '1.20.4'
3332
}
34-
setLoadingScreenStatus(`Loading data for ${version}`)
35-
if (!document.fonts.check('1em mojangles')) {
33+
if (autoVersionSelect === 'latest') {
34+
return supportedVersions.at(-1)!
35+
}
36+
return autoVersionSelect
37+
}
38+
39+
export const downloadMcDataOnConnect = async (version: string) => {
40+
// setLoadingScreenStatus(`Loading data for ${version}`)
41+
// // todo expose cache
42+
// // const initialDataVersion = Object.keys(minecraftInitialDataJson)[0]!
43+
// // if (version === initialDataVersion) {
44+
// // // ignore cache hit
45+
// // versionsByMinecraftVersion.pc[initialDataVersion]!.dataVersion!++
46+
// // }
47+
48+
// await window._MC_DATA_RESOLVER.promise // ensure data is loaded
49+
// miscUiState.loadedDataVersion = version
50+
}
51+
52+
const loadFonts = async () => {
53+
const FONT_FAMILY = 'mojangles'
54+
if (!document.fonts.check(`1em ${FONT_FAMILY}`)) {
3655
// todo instead re-render signs on load
37-
await document.fonts.load('1em mojangles').catch(() => {
56+
await document.fonts.load(`1em ${FONT_FAMILY}`).catch(() => {
3857
console.error('Failed to load font, signs wont be rendered correctly')
3958
})
4059
}
41-
await window._MC_DATA_RESOLVER.promise // ensure data is loaded
42-
await downloadSoundsIfNeeded()
43-
miscUiState.loadedDataVersion = version
60+
}
61+
62+
export const downloadOtherGameData = async () => {
63+
await Promise.all([loadFonts(), downloadSoundsIfNeeded()])
4464
}

src/importsWorkaround.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// workaround for mineflayer
2+
globalThis.window ??= globalThis
3+
globalThis.localStorage ??= {}
24
process.versions.node = '18.0.0'
35

46
if (!navigator.getGamepads) {

0 commit comments

Comments
 (0)