Általában a Minecraft módosításához Java-kódolásra van szükség, és sok állványra. Most írhat és megoszthat Minecraft modokat a TypeScript / Javascript segítségével.
A ScriptCraft egy nyílt forráskódú JavaScript Minecraft módosító könyvtár, és írtunk támogatást a TypeScript-hez, valamint egy csomó eszközt, hogy ismerős fejlesztői élményt teremtsünk a JavaScript-földről érkezők számára (beleértve a Yeoman-t és az NPM-et is).
Ebben a cikkben végigvezetem Önt az első TypeScript Minecraft mod telepítésén és felépítésén kevesebb, mint egy óra alatt - mindössze 20 perc alatt, az internetkapcsolattól függően.
Ebben a videóban (kattintson ide, ha a beágyazás nem működik fent) megmutatom, hogyan kell írni egy alapvető Minecraft modot a TypeScript segítségével, és futtatni a helyi számítógépen mind asztali, mind mobil Minecraft szerverrel.
Az alábbiakban bemutatom a lépéseket, az erőforrásokra mutató linkekkel.
Előfeltételek
Szüksége lesz néhány számítógépre telepített szoftverre a Minecraft szerver futtatásához, valamint a plugin írásához szükséges eszközökre. Telepítse mind a négy elemet:
- Docker - tároló oldat.
- Node.js - egy JavaScript végrehajtó motor és könyvtár.
- Portainer - webalapú grafikus felhasználói felület a Docker konténerek kezeléséhez.
- Visual Studio Code - kódszerkesztő.
Minecraft kliens
A plugin teszteléséhez szüksége van egy Minecraft kliensre .
Telepítse az alábbiak legalább egyikét:
- Minecraft Java Edition - asztali kliens, ha tesztelni akar egy Bukkit szerverrel.
- Minecraft Pocket Edition - mobil kliens, ha tesztelni akar egy Nukkit szerverrel (telefon / tablet / Xbox). Ha ezt használja, a Minecraft Pocket Edition Bedrock Launcher segítségével futtathatja a mobil klienst a számítógépén.
Telepítés
Miután telepítette az előfeltételeket, itt az ideje telepíteni az eszközöket a kiszolgálóhoz és a bővítmények fejlesztéséhez.
- Futtassa a következő parancsot:
npm i -g smac yo generator-sma-plugin typescript
Ez négy dolgot telepít a számítógépére:
smac
- Scriptcraft Modular Architecture Controller, egy program, amely a Minecraft szervereket futtatja a beépülő modulokhoz .yo
- Yeoman , állványos eszköz.generator-sma-plugin
- Yeoman plugin egy új Minecraft plugin előállításához a Scriptcraft Modular Architecture segítségével.typescript
- a TypeScript transzpiler, a TypeScript kód konvertálásához a Minecraft-ban futtatható ES5 JavaScript-be.
Hozzon létre egy új plugint
Miután telepítette az eszközkészletet, hozzon létre egy új plugint a parancs futtatásával:
yo sma-plugin
Ez elindítja a plugin varázslót:
➜ yo sma-plugin
_-----_ ╭──────────────────────────╮ | | │ Welcome to the │ |--(o)--| │ Scriptcraft SMA Plugin │ `---------´ │ generator by │ ( _´U`_ ) │ Magikcraft.io! │ /___A___\ /╰──────────────────────────╯ | ~ | __'.___.'__ ´ ` |° ´ Y `
? Your package name (workspace)
Itt csak egy kérdésre kell válaszolnia - a bővítmény neve. A varázsló létrehoz egy új mappát a plugin nevével, és elhelyezi benne az új plugin fájljait.

Ez a képernyõ mutatja a folyamatot:
Állítson egy Minecraft plugint a Magikcraft segítségével
A Magikcraft.io lehetővé teszi a Minecraft beépülő modulok írását TypeScript / JavaScript-ben, amelyek asztali / mobilon futnak. asciinema.org
Miután a varázsló befejezte, ehhez hasonló üzenetet ad ki ( my-sma-plugin
ebben a példában választottam a nevet ):

Szerkessze az új plugint
Indítsa el a Visual Studio Code programot, és nyissa meg az új bővítményt tartalmazó könyvtárat.

Itt található az új plugin fájljainak leírása:
__tests__
- a bővítmény egységtesztjeit tartalmazó könyvtár. Ezeket Jázminnal futtatják. Add hozzá további teszteket ide, amikor fejleszted a bővítményedet..vscode
- a Visual Studio kód beállításai.autoload
— any files in here are automatically executed when your plugin is enabled in the Minecraft server. Use this for initialisation tasks, registering event handlers, and so forth.lib
— A place for you to put files that should not be automatically loaded (or that are required from your autoloaded files). If your plugin provides functionality to other plugins, then you export that vialib/index.ts
.node_modules
— modules from npm are installed here. You cannot use modules from npm that use V8 APIs (like fs or http). Many of the features that you need are provided by the Scriptcraft API and by the@magikcraft/core
package..editorconfig
— settings for the editor..gitattributes
— settings forgit
..gitignore
— files to ignore forgit
..prettierrc
— settings for code formatting.package-lock.json
—versions of installed dependencies.package.json
—configuration for this plugin, including dependencies and scripts.README.md
— instructions for developing and testing your plugin.smac-nukkit.json
— a configuration for running a Nukkit server with your plugin loaded.smac.json
— a configuration for running a Bukkit server with your plugin loaded.tsconfig.json
— the TypeScript configuration for transpiling your plugin to JavaScript.
Open autoload/index.ts
:

This file is automatically executed when the plugin is loaded. Changes that you make here will be visible when you (re)load the plugin.
Start a development server
You can load your plugin in a development server. There are two servers that you can use — one for the desktop Java client, and the other for the mobile Pocket Edition client.
Start the desktop server
Run this to start a desktop server:
npm run start:bukkit
This will:
- Pull the Bukkit server image from Docker Hub.
- Start the Bukkit server with your plugin loaded.
- Start the TypeScript transpiler to transpile your code to ES5.
You can now connect to the server with your desktop client. Click on Multiplayer
then Direct Connect
, then use the server address 127.0.0.1
:

Start the mobile server
Run this command to start a mobile server:
npm run start:nukkit
This will:
- Pull the Nukkit server image from Docker Hub.
- Start the Nukkit server with your plugin loaded.
- Start the TypeScript transpiler to transpile your code to ES5.
You can now connect to the server with your pocket edition client. Click on Play
then Servers
, then add a server with the address 127.0.0.1
:

Reload changes to your plugin
As you change your plugin and save the changed TypeScript, it will automatically be transpiled to JavaScript.
To reload the changes in the development server, type the following in the server console:
ts onrefresh()
See the screencast below to see what this looks like.
Stop the server
To stop the server, type this command at the server console:
smac stop
See the screencast below to see what it looks like when you run this command.
Screencast: Start, Reload, and Stop
This screencast shows you starting the desktop server, reloading the plugin code, and also stopping the development server.
Start a Magikcraft Development Server
Start a Magikcraft Development Server.asciinema.org
Further Resources
- Magikcraft on GitHub
- Magikcraft on YouTube
- MCT1 Source Code (Example Plugin)
- ScriptCraft on GitHub
- Bukkit API Docs