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进行编码,并需要大量的脚手架。 现在,您可以使用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是一个开放源代码JavaScript Minecraft改装库,我们已经编写了对TypeScript的支持,以及许多工具,可为来自JavaScript领域(包括Yeoman和NPM)的开发人员创建熟悉的开发人员体验。

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.

在本文中,我将指导您在不到一个小时的时间内完成设置并构建您的第一个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.

在此视频中(如果无法正常使用, 请单击此处 ),我将向您展示如何使用TypeScript编写基本的Minecraft mod,并在具有台式机和移动Minecraft服务器的本地计算机上运行它。

Below, I’ll walk you through the steps, with links to resources.

下面,我将引导您完成这些步骤,并提供指向资源的链接。

先决条件 (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:

您需要在计算机上安装一些软件,才能运行Minecraft服务器和用于编写插件的工具。 安装以下所有四个:

我的世界客户端 (Minecraft Client)

You need a Minecraft client to test your plugin.

您需要一个Minecraft 客户端来测试您的插件。

Install at least one of the following:

安装以下至少一项:

安装 (Installation)

Now that you have the prerequisites installed, it is time to install the tools for the server and for plugin development.

现在,您已经安装了先决条件,是时候安装用于服务器和插件开发的工具了。

  1. Run the following command:

    运行以下命令:
npm i -g smac yo generator-sma-plugin typescript

This will install four things on your computer:

这将在您的计算机上安装四件事:

  • smacScriptcraft Modular Architecture Controller, a program that runs Minecraft Servers for your plugins.

    smacScriptcraft模块化体系结构控制器,一个为您的插件运行Minecraft服务器的程序。

  • yoYeoman, a scaffolding tool.

    yoYeoman ,脚手架工具。

  • generator-sma-plugin — a Yeoman plugin for generating a new Minecraft plugin using the Scriptcraft Modular Architecture.

    generator-sma-plugin —一个Yeoman插件,用于使用Scriptcraft模块化体系结构生成新的Minecraft插件。

  • typescript — the TypeScript transpiler, for converting TypeScript code into ES5 JavaScript that can run in Minecraft.

    typescript -打字稿transpiler,转换打字稿代码为ES5JavaScript可以在我的世界中运行。

创建一个新的插件 (Create a new plugin)

Now that you have the toolset installed, create a new plugin by running this command:

现在您已经安装了工具集,通过运行以下命令来创建一个新插件:

yo sma-plugin

This starts the plugin wizard:

这将启动插件向导:

➜ 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.

您只需在这里回答一个问题-插件的名称。 该向导将使用插件名称创建一个新文件夹,并将新插件的文件放入其中。

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插件,该插件将在台式机/移动设备上运行。 asciinema.org

Once the wizard completes, it emits a message similar to this (I chose the name my-sma-plugin in this example):

向导完成后,它会发出类似于以下的消息(在此示例中,我选择名称my-sma-plugin ):

编辑您的新插件 (Edit your new plugin)

Start Visual Studio Code and open the directory containing your new plugin.

启动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__ —包含插件的单元测试的目录。 这些与茉莉一起运行。 开发插件时,请在此处添加更多测试。

  • .vscode — settings for Visual Studio code.

    .vscode -Visual Studio代码的设置。

  • 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服务器中启用插件后,此处的所有文件都会自动执行。 将此用于初始化任务,注册事件处理程序等。

  • 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 —一个放置不应自动加载的文件(或自动加载的文件所必需的文件)的地方。 如果您的插件提供了其他插件的功能,则可以通过lib/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.

    node_modules -npm中的模块已安装在此处。 您不能使用npm中使用V8 API的模块(例如fs或http)。 Scriptcraft API@magikcraft/core 软件包提供了您需要的许多功能

  • .editorconfig — settings for the editor.

    .editorconfig编辑器的设置。

  • .gitattributes — settings for git.

    .gitattributes - git设置。

  • .gitignore — files to ignore for git.

    .gitignore忽略git文件。

  • .prettierrc — settings for code formatting.

    .prettierrc —代码格式设置。

  • package-lock.json —versions of installed dependencies.

    package-lock.json已安装依赖项的版本。

  • package.json —configuration for this plugin, including dependencies and scripts.

    package.json此插件的配置,包括依赖项和脚本。

  • README.md — instructions for developing and testing your plugin.

    README.md有关开发和测试插件的说明。

  • smac-nukkit.json — a configuration for running a Nukkit server with your plugin loaded.

    smac-nukkit.json —用于在加载插件的情况下运行Nukkit服务器的配置。

  • smac.json — a configuration for running a Bukkit server with your plugin loaded.

    smac.json —用于在加载了插件的情况下运行Bukkit服务器的配置。

  • tsconfig.json — the TypeScript configuration for transpiling your plugin to JavaScript.

    tsconfig.json —用于将插件转换为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.

加载插件后,将自动执行此文件。 (重新)加载插件时,您在此处所做的更改将可见。

启动开发服务器 (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.

您可以将插件加载到开发服务器中。 您可以使用两台服务器-一台用于桌面Java客户端,另一台用于移动Pocket Edition客户端。

启动桌面服务器 (Start the desktop server)

Run this to start a desktop server:

运行此命令以启动桌面服务器:

npm run start:bukkit

This will:

这将:

  1. Pull the Bukkit server image from Docker Hub.

    从Docker Hub中提取Bukkit服务器映像。
  2. Start the Bukkit server with your plugin loaded.

    在加载插件的情况下启动Bukkit服务器。
  3. Start the TypeScript transpiler to transpile your code to ES5.

    启动TypeScript转译器,以将您的代码转译到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:

现在,您可以使用桌面客户​​端连接到服务器。 单击Multiplayer然后单击Direct Connect ,然后使用服务器地址127.0.0.1

启动移动服务器 (Start the mobile server)

Run this command to start a mobile server:

运行以下命令以启动移动服务器:

npm run start:nukkit

This will:

这将:

  1. Pull the Nukkit server image from Docker Hub.

    从Docker Hub中提取Nukkit服务器映像。
  2. Start the Nukkit server with your plugin loaded.

    在加载插件的情况下启动Nukkit服务器。
  3. Start the TypeScript transpiler to transpile your code to ES5.

    启动TypeScript转译器,以将您的代码转译到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:

现在,您可以使用袖珍版客户端连接到服务器。 单击“ Play ,然后单击Play Servers ,然后添加地址为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.

在更改插件并保存更改的TypeScript时,它将自动转换为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 ServerStart a Magikcraft Development Server.asciinema.org

启动Magikcraft开发服务器 启动Magikcraft开发服务器。 asciinema.org

更多资源 (Further Resources)

翻译自: https://www.freecodecamp.org/news/how-to-mod-minecraft-without-java-f076ddaec01c/

typescript 使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值