minecraft-data 2.117.0 → 2.119.0

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,3 +1,12 @@
1
+ ## 2.119.0
2
+ * update mcdata
3
+
4
+ ## 2.118.0
5
+ * update mcdata
6
+
7
+ ## 2.117.1
8
+ * Add support for custom supportFeature return type
9
+
1
10
  ## 2.117.0
2
11
  * update mcdata
3
12
 
package/index.js CHANGED
@@ -14,8 +14,8 @@ const types = ['pc', 'bedrock']
14
14
  types.forEach(function (type) {
15
15
  for (let i = 0; i < protocolVersions[type].length; i++) {
16
16
  if (!protocolVersions[type][i].dataVersion) {
17
- // We start top to bottom, so the ones at the bottom should be greater
18
- protocolVersions[type][i].dataVersion = -protocolVersions[type].length + i
17
+ // We start top to bottom, so the ones at the bottom should be lower
18
+ protocolVersions[type][i].dataVersion = -i
19
19
  }
20
20
  }
21
21
  versionsByMinecraftVersion[type] = indexer.buildIndexFromArray(protocolVersions[type], 'minecraftVersion')
@@ -55,7 +55,8 @@ module.exports = function (mcVersion, preNetty) {
55
55
 
56
56
  const majorVersion = toMajor(mcVersion, preNetty)
57
57
  if (majorVersion == null) { return null }
58
- if (cache[majorVersion.type + '_' + majorVersion.majorVersion]) { return cache[majorVersion.type + '_' + majorVersion.majorVersion] }
58
+ const cachedName = `${majorVersion.type}_${majorVersion.majorVersion}_${majorVersion.dataVersion}`
59
+ if (cache[cachedName]) { return cache[cachedName] }
59
60
  const mcData = data[majorVersion.type][majorVersion.majorVersion]
60
61
  if (mcData == null) { return null }
61
62
  const nmcData = mcDataToNode(mcData)
@@ -63,8 +64,8 @@ module.exports = function (mcVersion, preNetty) {
63
64
  nmcData.isNewerOrEqualTo = version => nmcData.version['>='](version)
64
65
  nmcData.isOlderThan = version => nmcData.version['<'](version)
65
66
  nmcData.version = Object.assign(majorVersion, nmcData.version)
66
- cache[majorVersion.type + '_' + majorVersion.majorVersion] = nmcData
67
- nmcData.supportFeature = feature => supportFeature(feature, nmcData.version.minecraftVersion)
67
+ cache[cachedName] = nmcData
68
+ nmcData.supportFeature = feature => supportFeature(feature, nmcData.version)
68
69
  return nmcData
69
70
  }
70
71
 
@@ -1,31 +1,63 @@
1
1
  const features = require('../minecraft-data/data/pc/common/features.json')
2
-
3
- const versions = {
4
- pc: require('../minecraft-data/data/pc/common/protocolVersions.json'),
5
- bedrock: require('../minecraft-data/data/bedrock/common/protocolVersions.json')
6
- }
7
- const versionList = versions.pc
8
- const versionToIndex = Object.fromEntries(versionList.map((version, i) => [version.minecraftVersion, versionList.length - i]))
9
2
  const nameToFeature = Object.fromEntries(features.map(feature => [feature.name, feature]))
10
3
 
11
- module.exports = (featureName, minecraftVersion) => {
4
+ function isFeatureInRange (featureName, versionObj) {
12
5
  const feature = nameToFeature[featureName]
13
6
  if (feature === undefined) {
14
7
  throw new Error(`Feature ${feature} doesn't exist`)
15
8
  }
16
9
 
17
- const currentVer = versionToIndex[minecraftVersion]
18
- const minVer = versionToIndex[feature.versions[0]]
19
- const maxVer = versionToIndex[feature.versions[1]]
20
- if (currentVer === undefined) {
21
- throw new Error(`Version ${minecraftVersion} doesn't exist`)
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
24
+ }
25
+ }
26
+ }
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
+ }
32
+ }
33
+
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)
22
42
  }
23
- if (minVer === undefined) {
24
- throw new Error(`Version ${feature.versions[0]} doesn't exist`)
43
+ if (maxVer === 'latest') { // no need to check upper bound if upperbound is latest
44
+ return inRange
25
45
  }
26
- if (maxVer === undefined) {
27
- throw new Error(`Version ${feature.versions[1]} doesn't exist`)
46
+ if (maxVer.endsWith('_major')) {
47
+ const ver = removeMajorSuffix(maxVer)
48
+ inRange = inRange && getVersionObj(majorVersion)['<='](ver)
49
+ } else {
50
+ inRange = inRange && versionObj['<='](maxVer)
28
51
  }
52
+ return inRange
53
+ }
54
+
55
+ function removeMajorSuffix (verStr) {
56
+ return verStr.replace('_major', '')
57
+ }
29
58
 
30
- return minVer <= currentVer && currentVer <= maxVer
59
+ function getVersionObj (ver) {
60
+ return require('minecraft-data')(ver).version
31
61
  }
62
+
63
+ module.exports = isFeatureInRange
@@ -1,40 +1,25 @@
1
1
  [
2
2
  {
3
- "version": 100,
4
- "minecraftVersion": "1.0.0",
5
- "majorVersion": "1.0"
6
- },
7
- {
8
- "version": 82,
9
- "minecraftVersion": "0.15.6",
10
- "majorVersion": "0.15"
11
- },
12
- {
13
- "version": 70,
14
- "minecraftVersion": "0.14.3",
15
- "majorVersion": "0.14"
16
- },
17
- {
18
- "version": 422,
19
- "minecraftVersion": "1.16.201",
20
- "majorVersion": "1.16",
3
+ "version": 486,
4
+ "minecraftVersion": "1.18.11",
5
+ "majorVersion": "1.18",
21
6
  "releaseType": "release"
22
7
  },
23
8
  {
24
- "version": 428,
25
- "minecraftVersion": "1.16.210",
26
- "majorVersion": "1.16",
9
+ "version": 475,
10
+ "minecraftVersion": "1.18.0",
11
+ "majorVersion": "1.18",
27
12
  "releaseType": "release"
28
13
  },
29
14
  {
30
- "version": 431,
31
- "minecraftVersion": "1.16.220",
32
- "majorVersion": "1.16",
15
+ "version": 471,
16
+ "minecraftVersion": "1.17.40",
17
+ "majorVersion": "1.17",
33
18
  "releaseType": "release"
34
19
  },
35
20
  {
36
- "version": 440,
37
- "minecraftVersion": "1.17.0",
21
+ "version": 465,
22
+ "minecraftVersion": "1.17.30",
38
23
  "majorVersion": "1.17",
39
24
  "releaseType": "release"
40
25
  },
@@ -45,27 +30,42 @@
45
30
  "releaseType": "release"
46
31
  },
47
32
  {
48
- "version": 465,
49
- "minecraftVersion": "1.17.30",
33
+ "version": 440,
34
+ "minecraftVersion": "1.17.0",
50
35
  "majorVersion": "1.17",
51
36
  "releaseType": "release"
52
37
  },
53
38
  {
54
- "version": 471,
55
- "minecraftVersion": "1.17.40",
56
- "majorVersion": "1.17",
39
+ "version": 431,
40
+ "minecraftVersion": "1.16.220",
41
+ "majorVersion": "1.16",
57
42
  "releaseType": "release"
58
43
  },
59
44
  {
60
- "version": 475,
61
- "minecraftVersion": "1.18.0",
62
- "majorVersion": "1.18",
45
+ "version": 428,
46
+ "minecraftVersion": "1.16.210",
47
+ "majorVersion": "1.16",
63
48
  "releaseType": "release"
64
49
  },
65
50
  {
66
- "version": 486,
67
- "minecraftVersion": "1.18.11",
68
- "majorVersion": "1.18",
51
+ "version": 422,
52
+ "minecraftVersion": "1.16.201",
53
+ "majorVersion": "1.16",
69
54
  "releaseType": "release"
55
+ },
56
+ {
57
+ "version": 100,
58
+ "minecraftVersion": "1.0.0",
59
+ "majorVersion": "1.0"
60
+ },
61
+ {
62
+ "version": 82,
63
+ "minecraftVersion": "0.15.6",
64
+ "majorVersion": "0.15"
65
+ },
66
+ {
67
+ "version": 70,
68
+ "minecraftVersion": "0.14.3",
69
+ "majorVersion": "0.14"
70
70
  }
71
- ]
71
+ ]
@@ -359,5 +359,82 @@
359
359
  "version": "1.8_major"
360
360
  }
361
361
  ]
362
+ },
363
+ {
364
+ "name": "itemSerializationWillOnlyUsePresent",
365
+ "description": "item serialization in [even] newer versions uses present field [exclusively] to show nullability rather than sending blockId as -1",
366
+ "versions": ["1.14_major", "latest"]
367
+ },
368
+ {
369
+ "name": "itemSerializationAllowsPresent",
370
+ "description": "item serialization in newer versions uses present field to show nullability rather or sending blockId as -1 can be used",
371
+ "versions": ["1.13_major", "latest"]
372
+ },
373
+ {
374
+ "name": "itemSerializationUsesBlockId",
375
+ "description": "item serialization in older versions uses blockId field to show nullability by setting blockId to -1",
376
+ "versions": ["1.8_major", "1.12_major"]
377
+ },
378
+ {
379
+ "name": "saveDurabilityAsDamage",
380
+ "description": "in newer versions, an nbt key called 'Damage' is used to store durability",
381
+ "versions": ["1.13_major", "latest"]
382
+ },
383
+ {
384
+ "name": "nbtNameForEnchant",
385
+ "description": "what the nbt key for enchants is",
386
+ "values": [
387
+ {
388
+ "value": "Enchantments",
389
+ "versions": ["1.13_major", "latest"]
390
+ },
391
+ {
392
+ "value": "ench",
393
+ "versions": ["1.8_major", "1.12_major"]
394
+ }
395
+ ]
396
+ },
397
+ {
398
+ "name": "typeOfValueForEnchantLevel",
399
+ "description": "type of value that stores enchant lvl in the nbt",
400
+ "values": [
401
+ {
402
+ "value": "string",
403
+ "versions": ["1.13_major", "latest"]
404
+ },
405
+ {
406
+ "value": "short",
407
+ "versions": ["1.8_major", "1.12_major"]
408
+ }
409
+ ]
410
+ },
411
+ {
412
+ "name": "whereDurabilityIsSerialized",
413
+ "description": "where the durability is saved in nbt",
414
+ "values": [
415
+ {
416
+ "value": "Damage",
417
+ "versions": ["1.13_major", "latest"]
418
+ },
419
+ {
420
+ "value": "metadata",
421
+ "versions": ["1.8_major", "1.12_major"]
422
+ }
423
+ ]
424
+ },
425
+ {
426
+ "name": "spawnEggsUseInternalIdInNbt",
427
+ "description": "in older versions, spawn eggs have a field in their nbt called 'internalId' which tells what entity they will spawn",
428
+ "versions": ["1.8_major", "1.8_major"]
429
+ },
430
+ {
431
+ "name": "spawnEggsUseEntityTagInNbt",
432
+ "description": "in older versions, spawn eggs have a key in their nbt called EntityTag which is an object with a field called id, which is an identifier like 'minecraft:cow' that tells the client what mob this egg will spawn",
433
+ "versions": ["1.9_major", "1.12_major"]
434
+ },
435
+ {
436
+ "name": "spawnEggsHaveSpawnedEntityInName",
437
+ "description": "in newer versions, spawn eggs have the entity they spawn in their name, ex: 'squid_spawn_egg'",
438
+ "versions": ["1.13_major", "latest"]
362
439
  }
363
440
  ]
@@ -1,3 +1,9 @@
1
+ ## 2.119.0
2
+ * reverse bedrock version list
3
+
4
+ ## 2.118.0
5
+ * Add prismarine-item features
6
+
1
7
  ## 2.117.0
2
8
  * Add "metadataIxOfItem" feature
3
9
 
@@ -19,7 +19,6 @@
19
19
  "versions": {
20
20
  "description": "A tuple that describes the range of versions in the range",
21
21
  "type": "array",
22
- "uniqueItems": true,
23
22
  "items": {
24
23
  "title": "versionForFeatureIdentification",
25
24
  "type": "string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minecraft-data",
3
- "version": "2.117.0",
3
+ "version": "2.119.0",
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
@@ -19,6 +19,9 @@ describe('load', () => {
19
19
 
20
20
  const firstDataVersion = require('minecraft-data')('15w32a') // dataVersion = 100
21
21
  assert.strictEqual(firstDataVersion.isNewerOrEqualTo('15w31c'), true) // no dataVersion
22
+
23
+ const mcData188 = require('minecraft-data')('1.8.8')
24
+ assert.strictEqual(mcData188.isNewerOrEqualTo('1.8'), true, '1.8.8>1.8')
22
25
  })
23
26
  })
24
27
 
@@ -44,3 +47,32 @@ describe('versions with block data have block state IDs', () => {
44
47
  assert(oks > 0)
45
48
  })
46
49
  })
50
+
51
+ describe('supportFeature', () => {
52
+ it('dimensionIsAnInt is only accessible in 1.8 - 1.15.2', () => {
53
+ const mcData1Dot9 = require('minecraft-data')('1.9')
54
+ const mcData1Dot17 = require('minecraft-data')('1.17')
55
+ assert.equal(mcData1Dot9.supportFeature('dimensionIsAnInt'), true)
56
+ assert.equal(mcData1Dot17.supportFeature('dimensionIsAnInt'), false)
57
+ })
58
+
59
+ it('metadataIxOfItem works right', () => {
60
+ const assertions = {
61
+ 1.18: 8,
62
+ 1.17: 8,
63
+ '1.16.1': 7,
64
+ 1.16: 7,
65
+ 1.15: 7,
66
+ '1.13.2': 6,
67
+ '1.10': 6,
68
+ '1.9.1': 5,
69
+ 1.9: 5,
70
+ 1.8: 8
71
+ }
72
+ for (const [k, v] of Object.entries(assertions)) {
73
+ const mcData = require('minecraft-data')(k)
74
+ const newVal = mcData.supportFeature('metadataIxOfItem')
75
+ assert.equal(newVal, v, `Failed on mc version ${k} | Expected: ${v}, Got: ${newVal}`)
76
+ }
77
+ })
78
+ })