prismarine-registry 0.1.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.
@@ -0,0 +1,32 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: possible bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ - [ ] The [readme](https://github.com/PrismarineJS/prismarine-template/README.md) doesn't contain a resolution to my issue
11
+ - [ ] The [example](https://github.com/PrismarineJS/prismarine-template/example.js) doesn't contain a resolution to my issue
12
+
13
+ <!-- To mark the checkbox, insert `x` into it: [x] -->
14
+
15
+ ## Versions
16
+ - node: #.#.#
17
+ - prismarine-template: #.#.#
18
+
19
+ ## Detailed description of a problem
20
+ A clear and concise description of what the problem is.
21
+
22
+ ## Your current code
23
+ ```js
24
+ console.log("Hello world.")
25
+ ```
26
+
27
+ ## Expected behavior
28
+ A clear and concise description of what you expected to happen.
29
+
30
+ ## Additional context
31
+ Add any other context about the problem here.
32
+ ---
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: new feature
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ ## Is your feature request related to a problem? Please describe.
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ ## Describe the solution you'd like
14
+ A clear and concise description of what you want to happen.
15
+
16
+ ## Describe alternatives you've considered
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ ## Additional context
20
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,46 @@
1
+ ---
2
+ name: Question
3
+ about: Ask a question
4
+ title: ''
5
+ labels: question
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ - [ ] The [readme](https://github.com/PrismarineJS/prismarine-template/README.md) doesn't contain a resolution to my issue
11
+ - [ ] The [example](https://github.com/PrismarineJS/prismarine-template/example.js) doesn't contain a resolution to my issue
12
+
13
+
14
+ <!-- To mark the checkbox, insert `x` into it: [x] -->
15
+
16
+ ## Versions
17
+
18
+ - mineflayer: #.#.#
19
+ - server: vanilla/spigot/paper #.#.#
20
+ - node: #.#.#
21
+
22
+ ## Clear question
23
+
24
+ A clear question, with as much context as possible.
25
+ What are you building? What problem are you trying to solve?
26
+
27
+ ## What did you try yet?
28
+
29
+ Did you try any method from the API?
30
+ Did you try any example? Any error from those?
31
+
32
+ ## Your current code
33
+
34
+ Please put here any custom code you tried yet.
35
+
36
+ ```js
37
+
38
+ /*
39
+ Some code here, replace this
40
+ */
41
+
42
+ ```
43
+
44
+ ## Additional context
45
+
46
+ Add any other context about the problem here.
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: npm
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ node-version: [14.x]
17
+
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Use Node.js ${{ matrix.node-version }}
21
+ uses: actions/setup-node@v1
22
+ with:
23
+ node-version: ${{ matrix.node-version }}
24
+ - run: npm install
25
+ - run: npm test
@@ -0,0 +1,32 @@
1
+ name: npm-publish
2
+ on:
3
+ push:
4
+ branches:
5
+ - master # Change this to your default branch
6
+ jobs:
7
+ npm-publish:
8
+ name: npm-publish
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Checkout repository
12
+ uses: actions/checkout@master
13
+ - name: Set up Node.js
14
+ uses: actions/setup-node@master
15
+ with:
16
+ node-version: 14.0.0
17
+ - id: publish
18
+ uses: JS-DevTools/npm-publish@v1
19
+ with:
20
+ token: ${{ secrets.NPM_AUTH_TOKEN }}
21
+ - name: Create Release
22
+ if: steps.publish.outputs.type != 'none'
23
+ id: create_release
24
+ uses: actions/create-release@v1
25
+ env:
26
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27
+ with:
28
+ tag_name: ${{ steps.publish.outputs.version }}
29
+ release_name: Release ${{ steps.publish.outputs.version }}
30
+ body: ${{ steps.publish.outputs.version }}
31
+ draft: false
32
+ prerelease: false
package/.gitpod ADDED
@@ -0,0 +1,4 @@
1
+ image:
2
+ file: .gitpod.DockerFile
3
+ tasks:
4
+ - command: npm install
@@ -0,0 +1,8 @@
1
+ FROM gitpod/workspace-full:latest
2
+
3
+ RUN bash -c ". .nvm/nvm.sh \
4
+ && nvm install 14 \
5
+ && nvm use 14 \
6
+ && nvm alias default 14"
7
+
8
+ RUN echo "nvm use default &>/dev/null" >> ~/.bashrc.d/51-nvm-fix
package/HISTORY.md ADDED
@@ -0,0 +1,5 @@
1
+ ## History
2
+
3
+ ### 1.0.0
4
+
5
+ * initial implementation
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 PrismarineJS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # prismarine-registry
2
+ [![NPM version](https://img.shields.io/npm/v/prismarine-registry.svg)](http://npmjs.com/package/prismarine-registry)
3
+ [![Build Status](https://github.com/PrismarineJS/prismarine-registry/workflows/CI/badge.svg)](https://github.com/PrismarineJS/prismarine-registry/actions?query=workflow%3A%22CI%22)
4
+ [![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/GsEFRM8)
5
+ [![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/PrismarineJS/prismarine-registry)
6
+
7
+ Registry for storing indexed data
8
+
9
+ ## Usage
10
+
11
+ ```js
12
+ const registry = require('prismarine-registry')('1.18')
13
+
14
+ registry.biomes.set(2, 'minecraft:ocean', { data: 'about an ocean biome' })
15
+ console.assert(registry.biomes.getIndex('minecraft:ocean') === 2)
16
+ console.log(registry.biomes.get('minecraft:ocean')) // Should get { data: 'about an ocean biome' }
17
+ ```
18
+
19
+ ## API
20
+
21
+ Calling the default default export for `prismarine-registry` with a minecraft version will create a new set of registries.
22
+
23
+ to create a registry for version 1.18,
24
+
25
+ ```js
26
+ const registry = require('prismarine-registry')('1.18')
27
+ ```
28
+
29
+ and to add something to the registry,
30
+ ```js
31
+ registry.biomes.set(2, 'minecraft:ocean', { data: 'about an ocean biome' })
32
+ ```
33
+
34
+ or to push with an auto-incrementing ID,
35
+
36
+ ```js
37
+ registry.biomes.add('minecraft:ocean', { data: 'about an ocean biome' })
38
+ ```
39
+
40
+ to get something from registry with an index,
41
+
42
+ ```js
43
+ registry.biomes.getValueAt(index) => value
44
+ registry.biomes.getName(index) => string name
45
+
46
+ ```
47
+
48
+ A individual registry looks like this:
49
+
50
+ ```ts
51
+ interface Registry {
52
+ // Sets a value at a string key and numerical index
53
+ set(index: number, key: string, value): void
54
+ // Returns at what index the key was set
55
+ add(key: string, value): number
56
+
57
+ // Gets the value at a string key or numerical index
58
+ get(keyOrIndex: number | string)
59
+ // Get the value for the string key
60
+ getValue(key: string)
61
+ // Get value for the number index
62
+ getValueAt(index: number)
63
+
64
+ getName(index: number): string
65
+ getIndex(key: string): number
66
+ }
67
+ ```
@@ -0,0 +1,5 @@
1
+ const registry = require('prismarine-registry')('1.18')
2
+
3
+ registry.biomes.set(2, 'minecraft:ocean', { data: 'about an ocean biome' })
4
+ console.assert(registry.biomes.getIndex('minecraft:ocean') === 2)
5
+ console.log(registry.biomes.get('minecraft:ocean')) // Should get { data: 'about an ocean biome' }
package/example.js ADDED
@@ -0,0 +1,3 @@
1
+ const template = require('prismarine-template')
2
+
3
+ template.helloWorld()
package/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ declare module "prismarine-registry" {
2
+ interface Registry {
3
+ // Sets a value at a string key and numerical index
4
+ set(index: number, key: string, value): void
5
+ // Returns at what index the key was set
6
+ add(key: string, value): number
7
+
8
+ // Gets the value at a string key or numerical index
9
+ get(keyOrIndex: number | string)
10
+ // Get the value for the string key
11
+ getValue(key: string)
12
+ // Get value for the number index
13
+ getValueAt(index: number)
14
+
15
+ getName(index: number): string
16
+ getIndex(key: string): number
17
+ }
18
+
19
+ interface BedrockRegistry {
20
+ biomes: Registry
21
+ items: Registry
22
+ recipes: Registry
23
+ commands: Registry
24
+ }
25
+
26
+ interface JavaRegistry {
27
+ biomes: Registry
28
+ recipes: Registry
29
+ }
30
+
31
+ export default function(mcVersion: string): JavaRegistry & BedrockRegistry
32
+ }
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ if (typeof process !== 'undefined' && parseInt(process.versions.node.split('.')[0]) < 14) {
2
+ console.error('Your node version is currently', process.versions.node)
3
+ console.error('Please update it to a version >= 14.x.x from https://nodejs.org/')
4
+ process.exit(1)
5
+ }
6
+
7
+ module.exports.helloWorld = function () {
8
+ console.log('Hello world !')
9
+ }
@@ -0,0 +1,6 @@
1
+ const Registry = require('../registry')
2
+
3
+ module.exports = (version) => ({
4
+ biomes: new Registry(),
5
+ items: new Registry()
6
+ })
package/lib/index.js ADDED
@@ -0,0 +1,7 @@
1
+ module.exports = (version) => {
2
+ if (version.startsWith('bedrock_')) {
3
+ return require('./bedrock')(version)
4
+ } else {
5
+ return require('./pc')(version)
6
+ }
7
+ }
@@ -0,0 +1,6 @@
1
+ const Registry = require('../registry')
2
+
3
+ module.exports = (version) => ({
4
+ biomes: new Registry(),
5
+ recipes: new Registry()
6
+ })
@@ -0,0 +1,39 @@
1
+ class Registry {
2
+ constructor () {
3
+ this.data = {}
4
+ this.palette = []
5
+ }
6
+
7
+ set (index, key, value) {
8
+ this.palette[index] = key
9
+ this.data[key] = value
10
+ }
11
+
12
+ add (key, value) {
13
+ this.palette.push(key)
14
+ this.data[key] = value
15
+ return this.palette.length - 1
16
+ }
17
+
18
+ get (keyOrIndex) {
19
+ return typeof keyOrIndex === 'number' ? this.getValueAt(keyOrIndex) : this.getValue(keyOrIndex)
20
+ }
21
+
22
+ getValue (key) {
23
+ return this.data[key]
24
+ }
25
+
26
+ getValueAt (index) {
27
+ return this.data[this.palette[index]]
28
+ }
29
+
30
+ getName (index) {
31
+ return this.palette[index]
32
+ }
33
+
34
+ getIndex (key) {
35
+ return this.palette.indexOf(key)
36
+ }
37
+ }
38
+
39
+ module.exports = Registry
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "prismarine-registry",
3
+ "version": "0.1.0",
4
+ "description": "Prismarine Registry",
5
+ "main": "lib/index.js",
6
+ "scripts": {
7
+ "test": "mocha --reporter spec --exit",
8
+ "pretest": "npm run lint",
9
+ "lint": "standard",
10
+ "fix": "standard --fix"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/PrismarineJS/prismarine-registry.git"
15
+ },
16
+ "keywords": [
17
+ "prismarine",
18
+ "template"
19
+ ],
20
+ "author": "Romain Beaumont",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/PrismarineJS/prismarine-registry/issues"
24
+ },
25
+ "homepage": "https://github.com/PrismarineJS/prismarine-registry#readme",
26
+ "devDependencies": {
27
+ "debug": "^4.3.3",
28
+ "minecraft-protocol": "^1.30.0",
29
+ "minecraft-wrap": "^1.4.0",
30
+ "mocha": "^9.1.3",
31
+ "prismarine-registry": "file:.",
32
+ "standard": "^16.0.1"
33
+ }
34
+ }
package/test/basic.js ADDED
@@ -0,0 +1,39 @@
1
+ /* eslint-env mocha */
2
+
3
+ const Registry = require('prismarine-registry')
4
+ const assert = require('assert')
5
+
6
+ describe('basic registry works', () => {
7
+ const registry = Registry('1.18')
8
+
9
+ const oceanIndex = 1
10
+ const oceanStringKey = 'ocean'
11
+ const oceanData = 'Some data about Ocean'
12
+
13
+ registry.biomes.set(oceanIndex, oceanStringKey, oceanData)
14
+
15
+ const gotValueFromKey = registry.biomes.getValue(oceanStringKey)
16
+ const gotValueFromIndex = registry.biomes.getValueAt(oceanIndex)
17
+
18
+ const gotNameFromIndex = registry.biomes.getName(oceanIndex)
19
+ const gotIndexFromName = registry.biomes.getIndex('ocean')
20
+
21
+ assert(gotValueFromIndex === oceanData)
22
+ assert(gotValueFromKey === oceanData)
23
+
24
+ assert(gotNameFromIndex === 'ocean')
25
+ assert(gotIndexFromName === 1)
26
+
27
+ // console.log('Registry', registry)
28
+ // console.log('Got value from key', gotValueFromKey)
29
+ // console.log('Got value from index', gotValueFromIndex)
30
+ // console.log('Got name from index', gotNameFromIndex)
31
+ // console.log('Got index from name', gotIndexFromName)
32
+
33
+ const exampleRecipe = { type: 'minecraft:crafting_shaped', recipeId: 'minecraft:smooth_stone_slab', data: { width: 3, height: 1, group: '', ingredients: [[[{ present: true, itemId: 165, itemCount: 1 }]], [[{ present: true, itemId: 165, itemCount: 1 }]], [[{ present: true, itemId: 165, itemCount: 1 }]]], result: { present: true, itemId: 147, itemCount: 6 } } }
34
+ registry.recipes.add(exampleRecipe.recipeId, exampleRecipe)
35
+ const x = registry.recipes.get(exampleRecipe.recipeId)
36
+ assert.deepStrictEqual(x, exampleRecipe)
37
+
38
+ console.log(registry)
39
+ })
package/test/mcpc.js ADDED
@@ -0,0 +1,27 @@
1
+ const collectPackets = require('./util/collectMcpcPackets')
2
+ const nbt = require('prismarine-nbt')
3
+ const Registry = require('prismarine-registry')
4
+
5
+ async function main (version = '1.18') {
6
+ const registries = Registry(version)
7
+ const handlers = {
8
+ login (version, body) {
9
+ const dimensionCodec = nbt.simplify(body.dimensionCodec)
10
+ const biomes = dimensionCodec['minecraft:worldgen/biome'].value
11
+ for (const { name, id, element } of biomes) {
12
+ registries.biomes.set(id, name, element)
13
+ }
14
+ },
15
+
16
+ declare_recipes (version, body) {
17
+ for (const recipe of body.recipes) {
18
+ registries.recipes.add(recipe.recipeId, recipe)
19
+ }
20
+ }
21
+ }
22
+
23
+ collectPackets(version, Object.keys(handlers), (name, body) => handlers[name](version, body))
24
+ }
25
+
26
+ main()
27
+ module.exports = main
@@ -0,0 +1,10 @@
1
+ /* eslint-env mocha */
2
+
3
+ const SUPPORTED_VERSIONS = ['1.18']
4
+ const test = require('./mcpc')
5
+
6
+ describe('mcpc', () => {
7
+ for (const version of SUPPORTED_VERSIONS) {
8
+ it('works on ' + version, () => test(version))
9
+ }
10
+ })
@@ -0,0 +1,43 @@
1
+ const nmp = require('minecraft-protocol')
2
+ const { startServer } = require('./downloadMcpcServer')
3
+ const debug = require('debug')('prismarine-registry')
4
+
5
+ async function collectPackets (version, names = ['login'], cb) {
6
+ const collected = []
7
+ const server = await startServer(version, 25569)
8
+ console.log('Started server')
9
+
10
+ const client = nmp.createClient({
11
+ version: version,
12
+ host: 'localhost',
13
+ port: 25569,
14
+ username: 'test'
15
+ })
16
+
17
+ let clientConnected = false
18
+
19
+ client.on('connect', () => {
20
+ console.log('[client] Client connected')
21
+ clientConnected = true
22
+ })
23
+
24
+ for (const name of names) {
25
+ client.on(name, (packet) => {
26
+ cb(name, packet)
27
+ collected.push(packet)
28
+ })
29
+ }
30
+
31
+ client.on('packet', (data, { name }) => debug('[client] -> ', name))
32
+
33
+ setTimeout(() => {
34
+ console.log('Stopping server')
35
+ server.stop()
36
+ client.end()
37
+ if (!clientConnected) {
38
+ throw new Error('Client never connected')
39
+ }
40
+ }, 9000)
41
+ }
42
+
43
+ module.exports = collectPackets
@@ -0,0 +1,28 @@
1
+ const promisify = require('util').promisify
2
+ const wrap = require('minecraft-wrap')
3
+ const downloadServer = promisify(wrap.downloadServer)
4
+ const path = require('path')
5
+ const debug = require('debug')('prismarine-registry')
6
+
7
+ async function startServer (version, port = 25569) {
8
+ const MC_SERVER_PATH = path.join(__dirname, `server_${version}`)
9
+ const MC_SERVER_JAR = path.join(__dirname, `server_${version}.jar`)
10
+
11
+ console.log('🔻 Downloading server', version)
12
+ await downloadServer(version, MC_SERVER_JAR)
13
+
14
+ const vServer = new wrap.WrapServer(MC_SERVER_JAR, MC_SERVER_PATH)
15
+
16
+ vServer.on('line', function (line) {
17
+ debug(line)
18
+ })
19
+
20
+ console.log('â–¶ Starting server', port)
21
+ await new Promise(resolve => vServer.startServer({ 'online-mode': 'false', 'server-port': port }, resolve))
22
+
23
+ vServer.stop = async () => new Promise((resolve, reject) => vServer.stopServer(reject, resolve))
24
+
25
+ return vServer
26
+ }
27
+
28
+ module.exports = { startServer }