|
1 | | -const { Microsoft, Launch } = require('../build/Index'); |
2 | | -const launch = new Launch(); |
3 | | -const fs = require('fs'); |
| 1 | +const { Launch, Microsoft } = require('minecraft-java-core'); |
| 2 | +const launcher = new Launch(); |
4 | 3 |
|
5 | | -let client_id = '13f589e1-e2fc-443e-a68a-63b0092b8eeb' |
| 4 | +const fs = require('fs'); |
6 | 5 | let mc |
7 | 6 |
|
8 | 7 | (async () => { |
9 | 8 | if (!fs.existsSync('./account.json')) { |
10 | | - mc = await new Microsoft(client_id).getAuth(); |
| 9 | + mc = await new Microsoft().getAuth(); |
11 | 10 | fs.writeFileSync('./account.json', JSON.stringify(mc, null, 4)); |
12 | 11 | } else { |
13 | 12 | mc = JSON.parse(fs.readFileSync('./account.json')); |
14 | 13 | if (!mc.refresh_token) { |
15 | | - mc = await new Microsoft(client_id).getAuth(); |
| 14 | + mc = await new Microsoft().getAuth(); |
16 | 15 | fs.writeFileSync('./account.json', JSON.stringify(mc, null, 4)); |
17 | 16 | } else { |
18 | | - mc = await new Microsoft(client_id).refresh(mc); |
19 | | - if (mc.error) mc = await new Microsoft(client_id).getAuth(); |
| 17 | + mc = await new Microsoft().refresh(mc); |
| 18 | + if (mc.error) mc = await new Microsoft().getAuth(); |
20 | 19 | fs.writeFileSync('./account.json', JSON.stringify(mc, null, 4)); |
21 | 20 | } |
22 | 21 | } |
23 | 22 |
|
24 | | - let opt = { |
| 23 | + await launcher.Launch({ |
| 24 | + path: './minecraft', |
25 | 25 | authenticator: mc, |
26 | | - timeout: 1000, |
27 | | - path: './Minecraft', |
28 | | - instance: 'test', |
29 | | - version: '1.1', |
30 | | - detached: false, |
| 26 | + version: '1.8.9', |
31 | 27 | intelEnabledMac: true, |
32 | | - downloadFileMultiple: 5, |
33 | | - |
34 | 28 | loader: { |
35 | 29 | type: 'forge', |
36 | 30 | build: 'latest', |
37 | 31 | enable: true |
38 | 32 | }, |
39 | | - |
40 | | - verify: false, |
41 | | - ignored: [ |
42 | | - 'config', |
43 | | - 'essential', |
44 | | - 'logs', |
45 | | - 'resourcepacks', |
46 | | - 'saves', |
47 | | - 'screenshots', |
48 | | - 'shaderpacks', |
49 | | - 'W-OVERFLOW', |
50 | | - 'options.txt', |
51 | | - 'optionsof.txt' |
52 | | - ], |
53 | | - JVM_ARGS: [], |
54 | | - GAME_ARGS: [], |
55 | | - |
56 | | - java: { |
57 | | - path: null, |
58 | | - version: null, |
59 | | - type: 'jre', |
60 | | - }, |
61 | | - |
62 | | - // screen: { |
63 | | - // width: 1500, |
64 | | - // height: 900 |
65 | | - // }, |
66 | | - |
67 | 33 | memory: { |
68 | | - min: '4G', |
69 | | - max: '6G' |
| 34 | + min: '2G', |
| 35 | + max: '4G' |
70 | 36 | } |
71 | | - } |
72 | | - |
73 | | - await launch.Launch(opt); |
74 | | - |
75 | | - launch.on('extract', extract => { |
76 | | - console.log(extract); |
77 | 37 | }); |
78 | 38 |
|
79 | | - launch.on('progress', (progress, size, element) => { |
80 | | - console.log(`Downloading ${element} ${Math.round((progress / size) * 100)}%`); |
81 | | - }); |
82 | | - |
83 | | - launch.on('check', (progress, size, element) => { |
84 | | - console.log(`Checking ${element} ${Math.round((progress / size) * 100)}%`); |
85 | | - }); |
86 | | - |
87 | | - launch.on('estimated', (time) => { |
88 | | - let hours = Math.floor(time / 3600); |
89 | | - let minutes = Math.floor((time - hours * 3600) / 60); |
90 | | - let seconds = Math.floor(time - hours * 3600 - minutes * 60); |
91 | | - console.log(`${hours}h ${minutes}m ${seconds}s`); |
92 | | - }) |
93 | | - |
94 | | - launch.on('speed', (speed) => { |
95 | | - console.log(`${(speed / 1067008).toFixed(2)} Mb/s`) |
96 | | - }) |
97 | | - |
98 | | - launch.on('patch', patch => { |
99 | | - console.log(patch); |
100 | | - }); |
101 | | - |
102 | | - launch.on('data', (e) => { |
103 | | - console.log(e); |
104 | | - }) |
105 | | - |
106 | | - launch.on('close', code => { |
107 | | - console.log(code); |
108 | | - }); |
109 | | - |
110 | | - launch.on('error', err => { |
111 | | - console.log(err); |
112 | | - }); |
| 39 | + launcher.on('progress', (progress, size) => console.log(`[DL] ${((progress / size) * 100).toFixed(2)}%`)) |
| 40 | + .on('patch', pacth => process.stdout.write(pacth)) |
| 41 | + .on('data', line => process.stdout.write(line)) |
| 42 | + .on('close', () => console.log('Game exited.')); |
113 | 43 | })(); |
0 commit comments