fix autoversion (download data on demand)
This commit is contained in:
parent
e54ab51309
commit
bbb3c13a27
2 changed files with 28 additions and 6 deletions
|
|
@ -26,15 +26,29 @@ const plugins = [
|
|||
if (!resolveDir.endsWith('minecraft-data')) return
|
||||
return {
|
||||
namespace: 'load-global-minecraft-data',
|
||||
path
|
||||
path,
|
||||
pluginData: {
|
||||
resolveDir
|
||||
},
|
||||
}
|
||||
})
|
||||
build.onLoad({
|
||||
filter: /.+/,
|
||||
namespace: 'load-global-minecraft-data',
|
||||
}, () => {
|
||||
}, ({ pluginData: { resolveDir } }) => {
|
||||
const defaultVersionsObj = {
|
||||
// default protocol data, needed for auto-select
|
||||
"1.20.1": {
|
||||
version: {
|
||||
"minecraftVersion": "1.20.1",
|
||||
"version": 763,
|
||||
"majorVersion": "1.20"
|
||||
},
|
||||
protocol: JSON.parse(fs.readFileSync(join(resolveDir, 'minecraft-data/data/pc/1.20/protocol.json'), 'utf8')),
|
||||
}
|
||||
}
|
||||
return {
|
||||
contents: 'window.mcData ??= {};module.exports = { pc: window.mcData }',
|
||||
contents: `window.mcData ??= ${JSON.stringify(defaultVersionsObj)};module.exports = { pc: window.mcData }`,
|
||||
loader: 'js',
|
||||
}
|
||||
})
|
||||
|
|
@ -230,6 +244,7 @@ const plugins = [
|
|||
polyfillNode({
|
||||
polyfills: {
|
||||
fs: false,
|
||||
dns: false,
|
||||
crypto: false,
|
||||
events: false,
|
||||
http: false,
|
||||
|
|
|
|||
13
src/index.js
13
src/index.js
|
|
@ -364,12 +364,16 @@ async function connect (connectOptions) {
|
|||
let localServer
|
||||
try {
|
||||
Object.assign(serverOptions, _.defaultsDeep({}, connectOptions.serverOverrides ?? {}, options.localServerOptions, serverOptions))
|
||||
let version = connectOptions.botVersion ?? serverOptions.version
|
||||
if (version) {
|
||||
const downloadMcData = async (version) => {
|
||||
setLoadingScreenStatus(`Downloading data for ${version}`)
|
||||
await loadScript(`./mc-data/${toMajorVersion(version)}.js`)
|
||||
}
|
||||
|
||||
const version = connectOptions.botVersion ?? serverOptions.version
|
||||
if (version) {
|
||||
downloadMcData(version)
|
||||
}
|
||||
|
||||
if (singeplayer) {
|
||||
// SINGLEPLAYER EXPLAINER:
|
||||
// Note 1: here we have custom sync communication between server Client (flying-squid) and game client (mineflayer)
|
||||
|
|
@ -411,7 +415,10 @@ async function connect (connectOptions) {
|
|||
viewDistance: 'tiny',
|
||||
checkTimeoutInterval: 240 * 1000,
|
||||
noPongTimeout: 240 * 1000,
|
||||
closeTimeout: 240 * 1000
|
||||
closeTimeout: 240 * 1000,
|
||||
async versionSelectedHook (client) {
|
||||
await downloadMcData(client.version)
|
||||
}
|
||||
})
|
||||
if (singeplayer) {
|
||||
const _supportFeature = bot.supportFeature
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue