typescript 使用_如何使用TypeScript轻松修改Minecraft
typescript 使用
by Josh Wulf
通過喬什·沃爾夫(Josh Wulf)
如何使用TypeScript輕松修改Minecraft (How to modify Minecraft the easy way with TypeScript)
Usually, modifying Minecraft requires coding in Java, and a lot of scaffolding. Now you can write and share Minecraft mods using TypeScript/Javascript.
通常,修改Minecraft需要使用Java進(jìn)行編碼,并需要大量的腳手架。 現(xiàn)在,您可以使用TypeScript / Javascript編寫和共享Minecraft mod。
ScriptCraft is an open source JavaScript Minecraft modding library, and we’ve written support for TypeScript, and a bunch of tooling to create a familiar developer experience for those coming from JavaScript land (including Yeoman and NPM).
ScriptCraft是一個(gè)開放源代碼JavaScript Minecraft改裝庫,我們已經(jīng)編寫了對(duì)TypeScript的支持,以及許多工具,可為來自JavaScript領(lǐng)域(包括Yeoman和NPM)的開發(fā)人員創(chuàng)建熟悉的開發(fā)人員體驗(yàn)。
In this article I’ll walk you through getting set up and building your first TypeScript Minecraft mod in under an hour — as little as 20 minutes, depending on your internet connection.
在本文中,我將指導(dǎo)您在不到一個(gè)小時(shí)的時(shí)間內(nèi)完成設(shè)置并構(gòu)建您的第一個(gè)TypeScript Minecraft mod(取決于您的Internet連接,只需20分鐘)。
In this video (click here if the embed doesn’t work above) I show you how to write a basic Minecraft mod using TypeScript, and run it on your local computer with both a desktop and a mobile Minecraft server.
在此視頻中(如果無法正常使用, 請(qǐng)單擊此處 ),我將向您展示如何使用TypeScript編寫基本的Minecraft mod,并在具有臺(tái)式機(jī)和移動(dòng)Minecraft服務(wù)器的本地計(jì)算機(jī)上運(yùn)行它。
Below, I’ll walk you through the steps, with links to resources.
下面,我將引導(dǎo)您完成這些步驟,并提供指向資源的鏈接。
先決條件 (Prerequisites)
You’ll need some software installed on your computer, to run the Minecraft server and the tools for writing your plugin. Install all of the four following:
您需要在計(jì)算機(jī)上安裝一些軟件,才能運(yùn)行Minecraft服務(wù)器和用于編寫插件的工具。 安裝以下所有四個(gè):
Docker — a containerisation solution.
Docker-一種容器化解決方案。
Node.js — a JavaScript execution engine and library.
Node.js — JavaScript執(zhí)行引擎和庫。
Portainer — a web-based GUI for managing Docker containers.
Portainer-用于管理Docker容器的基于Web的GUI。
Visual Studio Code — a code editor.
Visual Studio代碼 -代碼編輯器。
我的世界客戶端 (Minecraft Client)
You need a Minecraft client to test your plugin.
您需要一個(gè)Minecraft 客戶端來測(cè)試您的插件。
Install at least one of the following:
安裝以下至少一項(xiàng):
Minecraft Java Edition — a desktop client, if you want to test against a Bukkit server.
Minecraft Java Edition-如果要針對(duì)Bukkit服務(wù)器進(jìn)行測(cè)試,則為桌面客戶端。
Minecraft Pocket Edition — a mobile client, if you want to test against a Nukkit server (phone/tablet/Xbox). If you use this, you can use Minecraft Pocket Edition Bedrock Launcher to run the mobile client on your computer.
Minecraft Pocket Edition-移動(dòng)客戶端,如果要在Nukkit服務(wù)器(電話/平板電腦/ Xbox)上進(jìn)行測(cè)試。 如果使用此功能,則可以使用Minecraft Pocket Edition Bedrock Launcher在計(jì)算機(jī)上運(yùn)行移動(dòng)客戶端。
安裝 (Installation)
Now that you have the prerequisites installed, it is time to install the tools for the server and for plugin development.
現(xiàn)在,您已經(jīng)安裝了先決條件,是時(shí)候安裝用于服務(wù)器和插件開發(fā)的工具了。
This will install four things on your computer:
這將在您的計(jì)算機(jī)上安裝四件事:
smac— Scriptcraft Modular Architecture Controller, a program that runs Minecraft Servers for your plugins.
smac — Scriptcraft模塊化體系結(jié)構(gòu)控制器,一個(gè)為您的插件運(yùn)行Minecraft服務(wù)器的程序。
yo — Yeoman, a scaffolding tool.
yo — Yeoman ,腳手架工具。
generator-sma-plugin — a Yeoman plugin for generating a new Minecraft plugin using the Scriptcraft Modular Architecture.
generator-sma-plugin —一個(gè)Yeoman插件,用于使用Scriptcraft模塊化體系結(jié)構(gòu)生成新的Minecraft插件。
typescript — the TypeScript transpiler, for converting TypeScript code into ES5 JavaScript that can run in Minecraft.
typescript -打字稿transpiler,轉(zhuǎn)換打字稿代碼為ES5JavaScript可以在我的世界中運(yùn)行。
創(chuàng)建一個(gè)新的插件 (Create a new plugin)
Now that you have the toolset installed, create a new plugin by running this command:
現(xiàn)在您已經(jīng)安裝了工具集,通過運(yùn)行以下命令來創(chuàng)建一個(gè)新插件:
yo sma-pluginThis starts the plugin wizard:
這將啟動(dòng)插件向?qū)?#xff1a;
? yo sma-plugin_-----_ ╭──────────────────────────╮ | | │ Welcome to the │ |--(o)--| │ Scriptcraft SMA Plugin │ `---------′ │ generator by │ ( _′U`_ ) │ Magikcraft.io! │ /___A___\ /╰──────────────────────────╯ | ~ | __'.___.'__ ′ ` |° ′ Y `? Your package name (workspace)There is only one question you need to answer here — the name of your plugin. The wizard will create a new folder with the name of the plugin, and place the files for the new plugin in it.
您只需在這里回答一個(gè)問題-插件的名稱。 該向?qū)⑹褂貌寮Q創(chuàng)建一個(gè)新文件夾,并將新插件的文件放入其中。
This screencast shows you the process:
該截屏視頻向您顯示了該過程:
Scaffold a Minecraft plugin using MagikcraftMagikcraft.io allows you to write Minecraft plugins in TypeScript/JavaScript that will run on Desktop / Mobile.asciinema.org
使用Magikcraft 搭建 Minecraft插件的腳手架 Magikcraft.io允許您以TypeScript / JavaScript編寫Minecraft插件,該插件將在臺(tái)式機(jī)/移動(dòng)設(shè)備上運(yùn)行。 asciinema.org
Once the wizard completes, it emits a message similar to this (I chose the name my-sma-plugin in this example):
向?qū)瓿珊?#xff0c;它會(huì)發(fā)出類似于以下的消息(在此示例中,我選擇名稱my-sma-plugin ):
編輯您的新插件 (Edit your new plugin)
Start Visual Studio Code and open the directory containing your new plugin.
啟動(dòng)Visual Studio代碼,然后打開包含新插件的目錄。
Here is a description of the files in your new plugin:
這是新插件中文件的描述:
__tests__ — a directory containing unit tests for your plugin. These are run with Jasmine. Add more tests in here as you develop your plugin.
__tests__ —包含插件的單元測(cè)試的目錄。 這些與茉莉一起運(yùn)行。 開發(fā)插件時(shí),請(qǐng)?jiān)诖颂幪砑痈鄿y(cè)試。
.vscode — settings for Visual Studio code.
.vscode -Visual Studio代碼的設(shè)置。
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.
autoload -在Minecraft服務(wù)器中啟用插件后,此處的所有文件都會(huì)自動(dòng)執(zhí)行。 將此用于初始化任務(wù),注冊(cè)事件處理程序等。
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 via lib/index.ts.
lib —一個(gè)放置不應(yīng)自動(dòng)加載的文件(或自動(dòng)加載的文件所必需的文件)的地方。 如果您的插件提供了其他插件的功能,則可以通過lib/index.ts導(dǎo)出該插件。
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.
node_modules -npm中的模塊已安裝在此處。 您不能使用npm中使用V8 API的模塊(例如fs或http)。 Scriptcraft API和@magikcraft/core 軟件包提供了您需要的許多功能。
.editorconfig — settings for the editor.
.editorconfig編輯器的設(shè)置。
.gitattributes — settings for git.
.gitattributes - git設(shè)置。
.gitignore — files to ignore for git.
.gitignore忽略git文件。
.prettierrc — settings for code formatting.
.prettierrc —代碼格式設(shè)置。
package-lock.json —versions of installed dependencies.
package-lock.json已安裝依賴項(xiàng)的版本。
package.json —configuration for this plugin, including dependencies and scripts.
package.json此插件的配置,包括依賴項(xiàng)和腳本。
README.md — instructions for developing and testing your plugin.
README.md有關(guān)開發(fā)和測(cè)試插件的說明。
smac-nukkit.json — a configuration for running a Nukkit server with your plugin loaded.
smac-nukkit.json —用于在加載插件的情況下運(yùn)行Nukkit服務(wù)器的配置。
smac.json — a configuration for running a Bukkit server with your plugin loaded.
smac.json —用于在加載了插件的情況下運(yùn)行Bukkit服務(wù)器的配置。
tsconfig.json — the TypeScript configuration for transpiling your plugin to JavaScript.
tsconfig.json —用于將插件轉(zhuǎn)換為JavaScript的TypeScript配置。
Open autoload/index.ts:
打開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.
加載插件后,將自動(dòng)執(zhí)行此文件。 (重新)加載插件時(shí),您在此處所做的更改將可見。
啟動(dòng)開發(fā)服務(wù)器 (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.
您可以將插件加載到開發(fā)服務(wù)器中。 您可以使用兩臺(tái)服務(wù)器-一臺(tái)用于桌面Java客戶端,另一臺(tái)用于移動(dòng)Pocket Edition客戶端。
啟動(dòng)桌面服務(wù)器 (Start the desktop server)
Run this to start a desktop server:
運(yùn)行此命令以啟動(dòng)桌面服務(wù)器:
npm run start:bukkitThis will:
這將:
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:
現(xiàn)在,您可以使用桌面客戶??端連接到服務(wù)器。 單擊Multiplayer然后單擊Direct Connect ,然后使用服務(wù)器地址127.0.0.1 :
啟動(dòng)移動(dòng)服務(wù)器 (Start the mobile server)
Run this command to start a mobile server:
運(yùn)行以下命令以啟動(dòng)移動(dòng)服務(wù)器:
npm run start:nukkitThis will:
這將:
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:
現(xiàn)在,您可以使用袖珍版客戶端連接到服務(wù)器。 單擊“ Play ,然后單擊Play Servers ,然后添加地址為127.0.0.1的服務(wù)器:
重新加載對(duì)插件的更改 (Reload changes to your plugin)
As you change your plugin and save the changed TypeScript, it will automatically be transpiled to JavaScript.
在更改插件并保存更改的TypeScript時(shí),它將自動(dòng)轉(zhuǎn)換為JavaScript。
To reload the changes in the development server, type the following in the server console:
要在開發(fā)服務(wù)器中重新加載更改,請(qǐng)?jiān)诜?wù)器控制臺(tái)中鍵入以下內(nèi)容:
ts onrefresh()See the screencast below to see what this looks like.
請(qǐng)參見下面的截屏視頻,以了解其外觀。
停止服務(wù)器 (Stop the server)
To stop the server, type this command at the server console:
要停止服務(wù)器,請(qǐng)?jiān)诜?wù)器控制臺(tái)上鍵入以下命令:
smac stopSee the screencast below to see what it looks like when you run this command.
請(qǐng)參閱以下截屏視頻,以查看運(yùn)行此命令時(shí)的外觀。
截屏視頻:開始,重新加載和停止 (Screencast: Start, Reload, and Stop)
This screencast shows you starting the desktop server, reloading the plugin code, and also stopping the development server.
該截屏視頻顯示啟動(dòng)桌面服務(wù)器,重新加載插件代碼以及停止開發(fā)服務(wù)器。
Start a Magikcraft Development ServerStart a Magikcraft Development Server.asciinema.org
啟動(dòng)Magikcraft開發(fā)服務(wù)器 啟動(dòng)Magikcraft開發(fā)服務(wù)器。 asciinema.org
更多資源 (Further Resources)
Magikcraft on GitHub
GitHub上的Magikcraft
Magikcraft on YouTube
YouTube上的Magikcraft
MCT1 Source Code (Example Plugin)
MCT1源代碼(示例插件)
ScriptCraft on GitHub
GitHub上的ScriptCraft
Bukkit API Docs
Bukkit API文件
翻譯自: https://www.freecodecamp.org/news/how-to-mod-minecraft-without-java-f076ddaec01c/
typescript 使用
總結(jié)
以上是生活随笔為你收集整理的typescript 使用_如何使用TypeScript轻松修改Minecraft的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到乌龟长翅膀什么意思
- 下一篇: 女人梦到婴儿是什么意思