minecraft-data 3.14.0 → 3.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/doc/history.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # History
2
2
 
3
+ ## 3.14.1
4
+
5
+ * Support supportFeature on bedrock
6
+
3
7
  ## 3.14.0
4
8
 
5
9
  * update `minecraft-data`
package/index.js CHANGED
@@ -68,7 +68,7 @@ module.exports = function (mcVersion, preNetty) {
68
68
  nmcData.isOlderThan = version => nmcData.version['<'](version)
69
69
  nmcData.version = Object.assign(majorVersion, nmcData.version)
70
70
  cache[cachedName] = nmcData
71
- nmcData.supportFeature = feature => supportFeature(feature, nmcData.version)
71
+ nmcData.supportFeature = supportFeature(nmcData.version, protocolVersions[nmcData.type])
72
72
  return nmcData
73
73
  }
74
74
 
@@ -1,63 +1,51 @@
1
- const features = require('../minecraft-data/data/pc/common/features.json')
2
- const nameToFeature = Object.fromEntries(features.map(feature => [feature.name, feature]))
1
+ const features = {
2
+ pc: require('../minecraft-data/data/pc/common/features.json'),
3
+ bedrock: require('../minecraft-data/data/bedrock/common/features.json')
4
+ }
5
+
6
+ module.exports = (versionObj, allVersions) => {
7
+ // Keep a dictionary of majorVersion => oldest / newest release
8
+ // Relies on descending order in minecraft-data's protocolVersions list
9
+ const newestMajor = allVersions.reduce((acc, cur) => { acc[cur.majorVersion] = acc[cur.majorVersion] || cur; return acc }, {})
10
+ const oldestMajor = allVersions.reduce((acc, cur) => { acc[cur.majorVersion] = cur; return acc }, {})
11
+
12
+ function isVersionInRange (minVer, maxVer) {
13
+ if (minVer.endsWith('_major')) {
14
+ minVer = oldestMajor[removeMajorSuffix(minVer)].minecraftVersion
15
+ }
16
+ if (maxVer.endsWith('_major')) {
17
+ maxVer = newestMajor[removeMajorSuffix(maxVer)].minecraftVersion
18
+ } else if (maxVer === 'latest') {
19
+ return versionObj['>='](minVer)
20
+ }
3
21
 
4
- function isFeatureInRange (featureName, versionObj) {
5
- const feature = nameToFeature[featureName]
6
- if (feature === undefined) {
7
- throw new Error(`Feature ${feature} doesn't exist`)
22
+ return versionObj['>='](minVer) && versionObj['<='](maxVer)
8
23
  }
9
24
 
10
- if (feature.values) {
11
- for (const { value, versions, version } of feature.values) { // we're using feature.version
12
- if (version) {
13
- const ver = version.replace('_major', '')
14
- if (!/^\d\.\d+$/.test(ver)) {
15
- throw new Error(`Not a correct major version value, instead the version is: "${version}"`)
16
- }
17
- if (versionObj.majorVersion === ver) {
18
- return value
19
- }
20
- } else { // we're using feature.versions
21
- const [minVer, maxVer] = versions
22
- if (isVersionInRange(minVer, versionObj, maxVer)) {
23
- return value
25
+ const featureList = features[versionObj.type].map(feature => [feature.name, feature])
26
+
27
+ const map = {}
28
+ for (const [featureName, feature] of featureList) {
29
+ if (feature.values) {
30
+ for (const { value, versions, version } of feature.values) { // we're using feature.version
31
+ if (version) {
32
+ if (isVersionInRange(version, version)) map[featureName] = value
33
+ } else {
34
+ if (isVersionInRange(...versions)) map[featureName] = value
24
35
  }
25
36
  }
37
+ } else {
38
+ const [minVer, maxVer] = feature.versions
39
+ map[featureName] = isVersionInRange(minVer, maxVer)
26
40
  }
27
- return null // if we didn't match anything, return null
28
- } else {
29
- const [minVer, maxVer] = feature.versions
30
- return isVersionInRange(minVer, versionObj, maxVer)
31
41
  }
32
- }
33
42
 
34
- function isVersionInRange (minVer, versionObj, maxVer) {
35
- let inRange = true
36
- const { majorVersion } = versionObj
37
- if (minVer.endsWith('_major')) {
38
- const ver = removeMajorSuffix(minVer)
39
- inRange = inRange && getVersionObj(majorVersion)['>='](ver)
40
- } else {
41
- inRange = inRange && versionObj['>='](minVer)
42
- }
43
- if (maxVer === 'latest') { // no need to check upper bound if upperbound is latest
44
- return inRange
45
- }
46
- if (maxVer.endsWith('_major')) {
47
- const ver = removeMajorSuffix(maxVer)
48
- inRange = inRange && getVersionObj(majorVersion)['<='](ver)
49
- } else {
50
- inRange = inRange && versionObj['<='](maxVer)
51
- }
52
- return inRange
43
+ return featureName => map[featureName] || false
53
44
  }
54
45
 
55
46
  function removeMajorSuffix (verStr) {
47
+ if (!/^\d\.\d+_major$/.test(verStr)) {
48
+ throw new Error(`Not a correct major version value: "${verStr}"`)
49
+ }
56
50
  return verStr.replace('_major', '')
57
51
  }
58
-
59
- function getVersionObj (ver) {
60
- return require('minecraft-data')(ver).version
61
- }
62
-
63
- module.exports = isFeatureInRange
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minecraft-data",
3
- "version": "3.14.0",
3
+ "version": "3.14.1",
4
4
  "description": "Provide easy access to minecraft data in node.js",
5
5
  "main": "index.js",
6
6
  "tonicExampleFilename": "example.js",
package/test/load.js CHANGED
@@ -81,4 +81,17 @@ describe('supportFeature', () => {
81
81
  assert.equal(newVal, v, `Failed on mc version ${k} | Expected: ${v}, Got: ${newVal}`)
82
82
  }
83
83
  })
84
+
85
+ it('handles "_major" correctly on itemSerializationUsesBlockId', function () {
86
+ const mcData1Dot9 = require('minecraft-data')('1.9')
87
+ const mcData1Dot17 = require('minecraft-data')('1.12.2')
88
+ assert.equal(mcData1Dot9.supportFeature('itemSerializationUsesBlockId'), true)
89
+ assert.equal(mcData1Dot17.supportFeature('itemSerializationUsesBlockId'), true)
90
+ })
91
+
92
+ it('works on bedrock', function () {
93
+ const mcData = require('minecraft-data')('bedrock_1.18.0')
94
+ assert.equal(mcData.supportFeature('newRecipeSchema'), true)
95
+ assert.equal(mcData.supportFeature('fakeRecipeSchema'), false)
96
+ })
84
97
  })