minecraft-data 2.115.2 → 2.117.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/data.js CHANGED
@@ -1102,7 +1102,7 @@ module.exports =
1102
1102
  get particles () { return require("./minecraft-data/data/pc/1.18/particles.json") },
1103
1103
  get blockLoot () { return require("./minecraft-data/data/pc/1.18/blockLoot.json") },
1104
1104
  get entityLoot () { return require("./minecraft-data/data/pc/1.18/entityLoot.json") },
1105
- get loginPacket () { return require("./minecraft-data/data/pc/1.18/loginPacket.json") },
1105
+ get loginPacket () { return require("./minecraft-data/data/pc/1.18.2/loginPacket.json") },
1106
1106
  get tints () { return require("./minecraft-data/data/pc/1.17/tints.json") },
1107
1107
  get mapIcons () { return require("./minecraft-data/data/pc/1.16/mapIcons.json") }
1108
1108
  }
package/doc/history.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 2.117.1
2
+ * Add support for custom supportFeature return type
3
+
4
+ ## 2.117.0
5
+ * update mcdata
6
+
7
+ ## 2.116.0
8
+ * update mcdata
9
+
1
10
  ## 2.115.2
2
11
  * Add supportFeature support
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
@@ -1101,7 +1101,7 @@
1101
1101
  "particles": "pc/1.18",
1102
1102
  "blockLoot": "pc/1.18",
1103
1103
  "entityLoot": "pc/1.18",
1104
- "loginPacket": "pc/1.18",
1104
+ "loginPacket": "pc/1.18.2",
1105
1105
  "tints": "pc/1.17",
1106
1106
  "mapIcons": "pc/1.16"
1107
1107
  }