minecraft-data 2.115.1 → 2.115.2

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.
@@ -25,3 +25,8 @@ jobs:
25
25
  node-version: ${{ matrix.node-version }}
26
26
  - run: npm install
27
27
  - run: npm test
28
+ - name: Upload index.d.ts
29
+ if: always()
30
+ uses: actions/upload-artifact@v3.0.0
31
+ with:
32
+ path: index.d.ts
package/doc/api.md CHANGED
@@ -337,6 +337,10 @@ Mapping from 1.12 block:metadata to 1.13 block names
337
337
 
338
338
  examples 0:0 -> minecraft:air
339
339
 
340
+ ### minecraft-data.supportFeature(featureName) : Boolean
341
+
342
+ This can be used to check is a specific feature is available in the current Minecraft version. This is usually only required for handling version-specific functionality.
343
+
340
344
  ## Schemas
341
345
 
342
346
  ### minecraft-data.schemas.biomes
package/doc/history.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.115.2
2
+ * Add supportFeature support
3
+
1
4
  ## 2.115.1
2
5
  * update mcdata
3
6
 
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const mcDataToNode = require('./lib/loader')
2
+ const supportFeature = require('./lib/supportsFeature')
2
3
  const indexer = require('./lib/indexer.js')
3
4
  const protocolVersions = {
4
5
  pc: require('./minecraft-data/data/pc/common/protocolVersions.json'),
@@ -63,7 +64,7 @@ module.exports = function (mcVersion, preNetty) {
63
64
  nmcData.isOlderThan = version => nmcData.version['<'](version)
64
65
  nmcData.version = Object.assign(majorVersion, nmcData.version)
65
66
  cache[majorVersion.type + '_' + majorVersion.majorVersion] = nmcData
66
-
67
+ nmcData.supportFeature = feature => supportFeature(feature, nmcData.version.minecraftVersion)
67
68
  return nmcData
68
69
  }
69
70
 
@@ -0,0 +1,31 @@
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
+ const nameToFeature = Object.fromEntries(features.map(feature => [feature.name, feature]))
10
+
11
+ module.exports = (featureName, minecraftVersion) => {
12
+ const feature = nameToFeature[featureName]
13
+ if (feature === undefined) {
14
+ throw new Error(`Feature ${feature} doesn't exist`)
15
+ }
16
+
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`)
22
+ }
23
+ if (minVer === undefined) {
24
+ throw new Error(`Version ${feature.versions[0]} doesn't exist`)
25
+ }
26
+ if (maxVer === undefined) {
27
+ throw new Error(`Version ${feature.versions[1]} doesn't exist`)
28
+ }
29
+
30
+ return minVer <= currentVer && currentVer <= maxVer
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minecraft-data",
3
- "version": "2.115.1",
3
+ "version": "2.115.2",
4
4
  "description": "Provide easy access to minecraft data in node.js",
5
5
  "main": "index.js",
6
6
  "tonicExampleFilename": "example.js",