-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpatch_states.js
67 lines (59 loc) · 1.86 KB
/
patch_states.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const fs = require('fs')
const path = require('path')
const extractDataFromMC = require('./extract_data_from_minecraft')
/**
* Adds/fixes state information to blocks.json
* @param {string} inFile path to the blocks.json
*/
async function handle (version, outPath) {
const blockFile = path.resolve(outPath)
const blocks = require(blockFile)
await extractDataFromMC(version)
const data = require('./minecraft_extracted_data/minecraft_generated_blocks.json')
if (!data) {
console.log('No api for ' + version)
return
}
for (const block of blocks) {
const apiblock = data['minecraft:' + block.name]
if (!apiblock) {
console.log('Missing block in api: ' + block.name)
continue
}
// Update states
block.states = []
if (apiblock.properties) {
for (const [prop, values] of Object.entries(apiblock.properties)) {
let type = 'enum'
if (values[0] === 'true') type = 'bool'
if (values[0] === '0') type = 'int'
const state = {
name: prop,
type,
num_values: values.length
}
if (type === 'enum') {
state.values = values
}
block.states.push(state)
}
}
block.minStateId = apiblock.states[0].id
block.maxStateId = apiblock.states[apiblock.states.length - 1].id
block.defaultState = block.minStateId
for (const state of apiblock.states) {
if (state.default) {
block.defaultState = state.id
break
}
}
block.drops = block.drops.filter(x => x !== null)
}
fs.writeFileSync(blockFile, JSON.stringify(blocks, null, 2))
await fs.promises.rm(path.join('minecraft_extracted_data', 'minecraft_generated_blocks.json'))
}
if (!process.argv[2] || !process.argv[3]) {
console.log('Usage: patch_states.js <version> <inFile>')
process.exit(1)
}
handle(process.argv[2], process.argv[3])