|
| 1 | +# Minecraft Node.js package loader |
| 2 | + |
| 3 | +Load JavaScript packages from books in chests on a Minecraft server. |
| 4 | + |
| 5 | +This will create a headless Minecraft client, join the configured server, and open |
| 6 | +a chest to look for signed books. |
| 7 | + |
| 8 | +Huge shoutout to the authors of `minecraft-protocol` and Prismarine. Their work |
| 9 | +lets this simply stitch together some packages and patch a resolution quirk. 💙 |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +1. **in-game:** Login to an offline mode Minecraft server (any version supported by [`minecraft-data`](https://npmjs.com/package/minecraft-data)) |
| 14 | + |
| 15 | +2. **in-game:** Write your code in a book and quill |
| 16 | + |
| 17 | + > **Note** |
| 18 | + > The first line of the first page should be a semver string |
| 19 | +
|
| 20 | + > **Note** > `import`ed packages will be loaded relative to the last on-disk module |
| 21 | + > |
| 22 | + > e.g. if `example.mjs` imports `minecraft:helloer`, any `import` in `helloer` will be |
| 23 | + > loaded as if you were in `example.mjs`. |
| 24 | +
|
| 25 | + This could look something like: |
| 26 | + |
| 27 | +  |
| 28 | + |
| 29 | +  |
| 30 | + |
| 31 | +3. **in-game:** Sign your book and quill with the package name as the title |
| 32 | + |
| 33 | +  |
| 34 | + |
| 35 | +4. **in-game:** Place your book, with any others, in a chest |
| 36 | + |
| 37 | + - This chest must be close enough to the configured player that it can open the chest |
| 38 | + without moving. This is 5 blocks away on an unmodified server. Keep in mind spawn |
| 39 | + protection prevents non OP-ed players from opening a chest (I forgot this and spent hours trying |
| 40 | + to fix the code 😅). |
| 41 | + |
| 42 | +  |
| 43 | + |
| 44 | +5. Configure your shell's environment with the correct variables following [`.env.example`](./.env.example). |
| 45 | + |
| 46 | +6. Put together a consuming script locally (see `example.mjs`) |
| 47 | + |
| 48 | + ```js |
| 49 | + // example.mjs |
| 50 | + import * as helloer from 'minecraft:helloer'; |
| 51 | + console.log(helloer); |
| 52 | + console.log(helloer.getWelcome('Cooper')); |
| 53 | + console.log(helloer.getDatedWelcome('Cooper')); |
| 54 | + ``` |
| 55 | + |
| 56 | +7. Run script with the `--loader` flag |
| 57 | + |
| 58 | + ```console |
| 59 | + $ node --loader ./dist/loader.mjs example.mjs |
| 60 | + [Module: null prototype] { |
| 61 | + getDatedWelcome: [Function: getDatedWelcome], |
| 62 | + getWelcome: [Function: getWelcome] |
| 63 | + } |
| 64 | + Hi, Cooper |
| 65 | + Welcome to 2023, Cooper! |
| 66 | + ``` |
| 67 | + |
| 68 | +## Wishlist |
| 69 | + |
| 70 | +- npm compatible registry so the consumer doesn't need any non-standard dependencies |
| 71 | +- Support teleporting the player (issue server command) so spawn location isn't a big deal |
0 commit comments