Repository navigation
Expand file tree
/
Copy pathaudit_recipes.js
More file actions
155 lines (140 loc) · 5.19 KB
/
Copy pathaudit_recipes.js
File metadata and controls
155 lines (140 loc) · 5.19 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* eslint-env mocha */
const fs = require('fs')
const path = require('path')
const assert = require('assert')
// counts the number of recipes with a shape, without one and with an outShape
function getIfExist (path) {
if (fs.existsSync(path)) {
return require(path)
} else {
return null
}
}
require('./version_iterator')(function (p, versionString) {
describe('audit recipes ' + versionString, function () {
it('audit recipes', function () {
let recipes
const pFile = path.join(p, 'recipes.json')
if (fs.existsSync(pFile)) {
recipes = require(pFile)
} else {
console.log('No recipes for version ' + versionString)
}
if (recipes) {
let shapeCount = 0
let shapelessCount = 0
let outShapeCount = 0
Object.keys(recipes).forEach(key => {
const list = recipes[key]
for (let i = 0; i < list.length; ++i) {
const recipe = list[i]
if (recipe.inShape != null) {
shapeCount += 1
} else if (recipe.ingredients != null) {
shapelessCount += 1
} else {
console.log('inShape or ingredients required:', key)
}
if (recipe.outShape) outShapeCount += 1
}
})
console.log('normal recipes:', shapeCount)
console.log('shapeless recipes:', shapelessCount)
console.log('how many have an outShape:', outShapeCount)
}
})
it('pickaxe not upside-down', () => {
const recipes = getIfExist(path.join(p, 'recipes.json'))
const items = getIfExist(path.join(p, 'items.json'))
if (recipes && items) {
const pickaxe = items.find(x => x.name === 'diamond_pickaxe')
const stick = items.find(x => x.name === 'stick')
const diamond = items.find(x => x.name === 'diamond')
const recipe = recipes[pickaxe.id]
// Uncomment to fix upside-down recipes
/* if (recipe[0].inShape[0][0] !== diamond.id) {
for (const item of Object.values(recipes)) {
for (const rep of item) {
if (rep.inShape) rep.inShape.reverse()
}
}
fs.writeFileSync(path.join(p, 'recipes.json'), JSON.stringify(recipes, null, 2))
} */
// pc 1.9 does not contain the diamond pickaxe recipe, to be fixed...
if (versionString === 'pc 1.9' || !recipe[0]) return
assert.deepStrictEqual(recipe[0].inShape, [
[
diamond.id,
diamond.id,
diamond.id
],
[
null,
stick.id,
null
],
[
null,
stick.id,
null
]
])
}
})
it('iron door not rotated', () => {
const recipes = getIfExist(path.join(p, 'recipes.json'))
const items = getIfExist(path.join(p, 'items.json'))
if (recipes && items) {
const ironDoor = items.find(x => x.name === 'iron_door')
const iron = items.find(x => x.name === 'iron_ingot')
const recipe = recipes[ironDoor.id]
if (!recipe[0]) return
assert.deepStrictEqual(recipe[0].inShape, [
[
iron.id,
iron.id
],
[
iron.id,
iron.id
],
[
iron.id,
iron.id
]
])
}
})
it('cake returns its buckets', () => {
const recipes = getIfExist(path.join(p, 'recipes.json'))
const items = getIfExist(path.join(p, 'items.json'))
if (recipes && items) {
// pc 1.19 and later do not contain outShape, to be fixed...
const pcVersions = require('../../../data/pc/common/versions')
if (versionString.startsWith('pc ') && pcVersions.indexOf(versionString.slice(3)) >= pcVersions.indexOf('1.19')) return
const cake = items.find(x => x.name === 'cake')
const milkBucket = items.find(x => x.name === 'milk_bucket')
const bucket = items.find(x => x.name === 'bucket')
const recipe = recipes[cake.id]
if (!recipe || !recipe[0]) return
const idOf = cell => cell === null || typeof cell === 'number' ? cell : cell.id
assert.deepStrictEqual(recipe[0].outShape, recipe[0].inShape.map(row => row.map(cell => idOf(cell) === milkBucket.id ? bucket.id : null)))
}
})
it('crafting benches has multiple recipes', () => {
const recipes = getIfExist(path.join(p, 'recipes.json'))
const items = getIfExist(path.join(p, 'items.json'))
if (recipes && items) {
const craftingTable = items.find(x => x.name === 'crafting_table')
const oakPlanks = items.find(x => x.name === 'oak_planks')
if (!oakPlanks) return // Bail if version doesn't have seperately defined planks, this prevents the test failing on versions that use metadata
const recipe = recipes[craftingTable.id]
if (!recipe[0]) return
// remove the if after fixing https://github.com/PrismarineJS/minecraft-data/issues/917
if (versionString !== 'pc 1.20.5' && versionString !== 'pc 1.20.6') {
assert.notEqual(recipe.length, 1) // Check that crafting table has multiple recipes.
}
}
})
})
})