minecraft-data 2.116.0 → 2.118.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.118.0
2
+ * update mcdata
3
+
4
+ ## 2.117.1
5
+ * Add support for custom supportFeature return type
6
+
7
+ ## 2.117.0
8
+ * update mcdata
9
+
1
10
  ## 2.116.0
2
11
  * update mcdata
3
12
 
package/index.d.ts CHANGED
@@ -876,6 +876,58 @@ declare namespace MinecraftData {
876
876
  entityLoot: any;
877
877
  }
878
878
 
879
+ export interface LoginPacket {
880
+ entityId: number;
881
+
882
+ /**
883
+ * introduced in Minecraft 1.16.2
884
+ */
885
+ isHardcore?: boolean;
886
+
887
+ gameMode: number;
888
+
889
+ /**
890
+ * Introduced in Minecraft 1.17
891
+ */
892
+ previousGameMode?: number;
893
+ /**
894
+ * Introduced in Minecraft 1.17
895
+ */
896
+ worldNames?: string[];
897
+ /**
898
+ * Introduced in Minecraft 1.17
899
+ */
900
+ dimensionCodec?: any;
901
+
902
+ dimension: any;
903
+
904
+ /**
905
+ * Introduced in Minecraft 1.17
906
+ */
907
+ worldName?: string;
908
+
909
+ hashedSeed: number;
910
+ maxPlayers: number;
911
+ viewDistance: number;
912
+
913
+ /**
914
+ * Introduced in Minecraft 1.18
915
+ */
916
+ simulationDistance?: number;
917
+
918
+ reducedDebugInfo: boolean;
919
+ enableRespawnScreen: boolean;
920
+
921
+ /**
922
+ * Introduced in Minecraft 1.17
923
+ */
924
+ isDebug?: boolean;
925
+ /**
926
+ * Introduced in Minecraft 1.17
927
+ */
928
+ isFlat?: boolean;
929
+ }
930
+
879
931
  export interface IndexedData {
880
932
  isNewerOrEqualTo(version: string): boolean;
881
933
  isOlderThan(version: string): boolean;
@@ -883,6 +935,8 @@ declare namespace MinecraftData {
883
935
  blocksByName: { [name: string]: Block; };
884
936
  blocksArray: Block[];
885
937
 
938
+ loginPacket: LoginPacket;
939
+
886
940
  items: { [id: number]: Item; };
887
941
  itemsByName: { [name: string]: Item; };
888
942
  itemsArray: Item[];
package/index.js CHANGED
@@ -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
@@ -333,5 +333,108 @@
333
333
  "name": "sendStringifiedSignText",
334
334
  "description": "sign text send when updating signs is send as stringified strings",
335
335
  "versions": ["1.8", "1.8.9"]
336
+ },
337
+ {
338
+ "name": "metadataIxOfItem",
339
+ "description": "item.metadata[this_ix] will be the item that was dropped on the ground",
340
+ "values": [
341
+ {
342
+ "value": 8,
343
+ "versions": ["1.17_major", "latest"]
344
+ },
345
+ {
346
+ "value": 7,
347
+ "versions": ["1.14_major", "1.16_major"]
348
+ },
349
+ {
350
+ "value": 6,
351
+ "versions": ["1.10_major", "1.13_major"]
352
+ },
353
+ {
354
+ "value": 5,
355
+ "version": "1.9_major"
356
+ },
357
+ {
358
+ "value": 8,
359
+ "version": "1.8_major"
360
+ }
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"]
336
439
  }
337
440
  ]
@@ -1,3 +1,9 @@
1
+ ## 2.118.0
2
+ * Add prismarine-item features
3
+
4
+ ## 2.117.0
5
+ * Add "metadataIxOfItem" feature
6
+
1
7
  ## 2.116.0
2
8
  * Fix loginPacket for 1.18.2
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.116.0",
3
+ "version": "2.118.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
@@ -44,3 +44,32 @@ describe('versions with block data have block state IDs', () => {
44
44
  assert(oks > 0)
45
45
  })
46
46
  })
47
+
48
+ describe('supportFeature', () => {
49
+ it('dimensionIsAnInt is only accessible in 1.8 - 1.15.2', () => {
50
+ const mcData1Dot9 = require('minecraft-data')('1.9')
51
+ const mcData1Dot17 = require('minecraft-data')('1.17')
52
+ assert.equal(mcData1Dot9.supportFeature('dimensionIsAnInt'), true)
53
+ assert.equal(mcData1Dot17.supportFeature('dimensionIsAnInt'), false)
54
+ })
55
+
56
+ it('metadataIxOfItem works right', () => {
57
+ const assertions = {
58
+ 1.18: 8,
59
+ 1.17: 8,
60
+ '1.16.1': 7,
61
+ 1.16: 7,
62
+ 1.15: 7,
63
+ '1.13.2': 6,
64
+ '1.10': 6,
65
+ '1.9.1': 5,
66
+ 1.9: 5,
67
+ 1.8: 8
68
+ }
69
+ for (const [k, v] of Object.entries(assertions)) {
70
+ const mcData = require('minecraft-data')(k)
71
+ const newVal = mcData.supportFeature('metadataIxOfItem')
72
+ assert.equal(newVal, v, `Failed on mc version ${k} | Expected: ${v}, Got: ${newVal}`)
73
+ }
74
+ })
75
+ })
@@ -41,6 +41,58 @@ export interface Schemas {
41
41
  entityLoot: any;
42
42
  }
43
43
 
44
+ export interface LoginPacket {
45
+ entityId: number;
46
+
47
+ /**
48
+ * introduced in Minecraft 1.16.2
49
+ */
50
+ isHardcore?: boolean;
51
+
52
+ gameMode: number;
53
+
54
+ /**
55
+ * Introduced in Minecraft 1.17
56
+ */
57
+ previousGameMode?: number;
58
+ /**
59
+ * Introduced in Minecraft 1.17
60
+ */
61
+ worldNames?: string[];
62
+ /**
63
+ * Introduced in Minecraft 1.17
64
+ */
65
+ dimensionCodec?: any;
66
+
67
+ dimension: any;
68
+
69
+ /**
70
+ * Introduced in Minecraft 1.17
71
+ */
72
+ worldName?: string;
73
+
74
+ hashedSeed: number;
75
+ maxPlayers: number;
76
+ viewDistance: number;
77
+
78
+ /**
79
+ * Introduced in Minecraft 1.18
80
+ */
81
+ simulationDistance?: number;
82
+
83
+ reducedDebugInfo: boolean;
84
+ enableRespawnScreen: boolean;
85
+
86
+ /**
87
+ * Introduced in Minecraft 1.17
88
+ */
89
+ isDebug?: boolean;
90
+ /**
91
+ * Introduced in Minecraft 1.17
92
+ */
93
+ isFlat?: boolean;
94
+ }
95
+
44
96
  export interface IndexedData {
45
97
  isNewerOrEqualTo(version: string): boolean;
46
98
  isOlderThan(version: string): boolean;
@@ -48,6 +100,8 @@ export interface IndexedData {
48
100
  blocksByName: { [name: string]: Block; };
49
101
  blocksArray: Block[];
50
102
 
103
+ loginPacket: LoginPacket;
104
+
51
105
  items: { [id: number]: Item; };
52
106
  itemsByName: { [name: string]: Item; };
53
107
  itemsArray: Item[];