博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
typescript 使用_如何使用TypeScript轻松修改Minecraft
阅读量:2520 次
发布时间:2019-05-11

本文共 8952 字,大约阅读时间需要 29 分钟。

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。

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

是一个开放源代码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 ( 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服务器和用于编写插件的工具。 安装以下所有四个:

  • — a containerisation solution.

    一种容器化解决方案。

  • — a JavaScript execution engine and library.

    — JavaScript执行引擎和库。

  • — a web-based GUI for managing Docker containers.

    用于管理Docker容器的基于Web的GUI。

  • — a code editor.

    -代码编辑器。

我的世界客户端 (Minecraft Client)

You need a Minecraft client to test your plugin.

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

Install at least one of the following:

安装以下至少一项:

  • Java Edition — a desktop client, if you want to test against a Bukkit server.

    Java Edition-如果要针对Bukkit服务器进行测试,则为桌面客户端。

  • — a mobile client, if you want to test against a Nukkit server (phone/tablet/Xbox). If you use this, you can use to run the mobile client on your computer.

    移动客户端,如果要在Nukkit服务器(电话/平板电脑/ Xbox)上进行测试。 如果使用此功能,则可以使用在计算机上运行移动客户端。

安装 (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:

该截屏视频向您显示了该过程:

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 and by the

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

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

该截屏视频显示启动桌面服务器,重新加载插件代码以及停止开发服务器。

更多资源 (Further Resources)

翻译自:

typescript 使用

转载地址:http://bhrwd.baihongyu.com/

你可能感兴趣的文章
request和response的知识
查看>>
Python hashlib模块
查看>>
bootstrap 表单类
查看>>
20165332第四周学习总结
查看>>
Codeforces Round #200 (Div. 1)D. Water Tree dfs序
查看>>
linux安全设置
查看>>
Myflight航班查询系统
查看>>
Chapter 4
查看>>
推荐10款左右切换的焦点图源码下载
查看>>
团队-团队编程项目爬取豆瓣电影top250-代码设计规范
查看>>
表头固定内容可滚动表格的3种实现方法
查看>>
想对你说
查看>>
day5 面向对象
查看>>
{算法}Young司机带你轻松KMP
查看>>
不同方法获得视差图比较
查看>>
发现的一个好的socket网页抓取源码
查看>>
jquery解析json
查看>>
实现自动发邮件功能
查看>>
jQuery笔记(二)
查看>>
GJM : Socket TCP 通信连接(四)
查看>>