minecraft-data 3.13.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,13 @@
1
1
  # History
2
2
 
3
+ ## 3.14.1
4
+
5
+ * Support supportFeature on bedrock
6
+
7
+ ## 3.14.0
8
+
9
+ * update `minecraft-data`
10
+
3
11
  ## 3.13.0
4
12
 
5
13
  * 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
@@ -1 +1,8 @@
1
- []
1
+ [
2
+ {
3
+ "name": "newRecipeSchema",
4
+ "description": "New recipe schema",
5
+ "versions": ["1.16_major", "latest"]
6
+ }
7
+ ]
8
+
@@ -57,7 +57,12 @@
57
57
  {
58
58
  "name": "dimensionDataIsAvailable",
59
59
  "description": "dimensionData is available, providing an additional information about the current dimension",
60
- "versions": ["1.17", "1.19"]
60
+ "versions": ["1.17", "1.18.2"]
61
+ },
62
+ {
63
+ "name": "dimensionDataInCodec",
64
+ "description": "dimensionData like world height is exclusively in the codec in login packet",
65
+ "versions": ["1.19", "latest"]
61
66
  },
62
67
  {
63
68
  "name": "useItemWithBlockPlace",
@@ -446,5 +451,10 @@
446
451
  "name": "signatureEncryption",
447
452
  "description": "allows for usage of `signature` instead of verifyToken in serverbound packet_encryption_begin",
448
453
  "versions": ["1.19_major", "latest"]
454
+ },
455
+ {
456
+ "name": "clientboundChatHasSender",
457
+ "description": "clientbound chat packet contains message sender's UUID",
458
+ "versions": ["1.16_major", "latest"]
449
459
  }
450
460
  ]
@@ -1,4 +1,10 @@
1
+ ## 3.14.0
2
+
3
+ * update 1.19 features list (@extremeheat)
4
+ * Add features.json for bedrock (@extremeheat)
5
+
1
6
  ## 3.13.0
7
+
2
8
  * bedrock : add protocol data for 1.19.30 (@stevarino)
3
9
  * pc : Fix login packet structure in 1.19 (#632) @mkorman9
4
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minecraft-data",
3
- "version": "3.13.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
  })