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服务器和用于编写插件的工具。 安装以下所有四个:

  • Docker — a containerisation solution.

    Docker-一种容器化解决方案。

  • Node.js — a JavaScript execution engine and library.

    Node.js — JavaScript执行引擎和库。

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

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

Install at least one of the following:

安装以下至少一项:

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

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

  • 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-移动客户端,如果要在Nukkit服务器(电话/平板电脑/ Xbox)上进行测试。 如果使用此功能,则可以使用Minecraft Pocket Edition Bedrock Launcher在计算机上运行移动客户端。

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

  • 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 使用

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/391613.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Python:在Pandas数据框中查找缺失值

How to find Missing values in a data frame using Python/Pandas如何使用Python / Pandas查找数据框中的缺失值 介绍: (Introduction:) When you start working on any data science project the data you are provided is never clean. One of the most common …

监督学习-回归分析

一、数学建模概述 监督学习:通过已有的训练样本进行训练得到一个最优模型,再利用这个模型将所有的输入映射为相应的输出。监督学习根据输出数据又分为回归问题(regression)和分类问题(classfication)&#…

leetcode 54. 螺旋矩阵(递归)

给你一个 m 行 n 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。 示例 1: 输入:matrix [[1,2,3],[4,5,6],[7,8,9]] 输出:[1,2,3,6,9,8,7,4,5] 示例 2: 输入:matrix [[1,…

微服务架构技能

2019独角兽企业重金招聘Python工程师标准>>> 微服务架构技能 博客分类: 架构 (StuQ 微服务技能图谱) 2课程简介 本课程分为基础篇和高级篇两部分,旨在通过完整的案例,呈现微服务的开发、测试、构建、部署、…

phpstorm 调试_PhpStorm中的多用户调试

phpstorm 调试by Ray Naldo雷纳尔多(Ray Naldo) PhpStorm中的多用户调试 (Multi-User Debugging in PhpStorm) 使用Xdebug和DBGp代理 (Using Xdebug and DBGp Proxy) “Er, wait a minute… Don’t you just use xdebug.remote_connect_back which has been introduced since …

Tableau Desktop认证:为什么要关心以及如何通过

Woah, Tableau!哇,Tableau! By now, almost everyone’s heard of the data visualization software that brought visual analytics to the public. Its intuitive drag and drop interface makes connecting to data, creating graphs, and sharing d…

约束布局constraint-layout导入失败的解决方案 - 转

今天有同事用到了约束布局,但是导入我的工程出现错误 **提示错误: Could not find com.Android.support.constraint:constraint-layout:1.0.0-alpha3** 我网上查了一下资料,都说是因为我的androidStudio版本是最新的稳定版导入这个包就会报这…

算法复习:冒泡排序

思想:对于一个列表,每个数都是一个"气泡 ",数字越大表示"越重 ",最重的气泡移动到列表最后一位,冒泡排序后的结果就是“气泡”按照它们的重量依次移动到列表中它们相应的位置。 算法:搜索整个列表…

leetcode 59. 螺旋矩阵 II(递归)

给你一个正整数 n ,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的 n x n 正方形矩阵 matrix 。 示例 1: 输入:n 3 输出:[[1,2,3],[8,9,4],[7,6,5]] 解题思路 按层进行数字的填充,每一层…

前端基础进阶(七):函数与函数式编程

纵观JavaScript中所有必须需要掌握的重点知识中,函数是我们在初学的时候最容易忽视的一个知识点。在学习的过程中,可能会有很多人、很多文章告诉你面向对象很重要,原型很重要,可是却很少有人告诉你,面向对象中所有的重…

期权数据 获取_我如何免费获得期权数据

期权数据 获取by Harry Sauers哈里绍尔斯(Harry Sauers) 我如何免费获得期权数据 (How I get options data for free) 网页抓取金融简介 (An introduction to web scraping for finance) Ever wished you could access historical options data, but got blocked by a paywall…

显示与删除使用工具

右击工具菜单栏中的空白处选择自定义 在弹出的自定义菜单中选择命令选项在选择想要往里面添加工具的菜单,之后在选择要添加的工具 若想要删除工具栏中的某个工具,在打开自定义菜单后,按住鼠标左键拖动要删除工具到空白处 例如 转载于:https:/…

js值的拷贝和值的引用_到达P值的底部:直观的解释

js值的拷贝和值的引用介绍 (Introduction) Welcome to this lesson on calculating p-values.欢迎参加有关计算p值的课程。 Before we jump into how to calculate a p-value, it’s important to think about what the p-value is really for.在我们开始计算p值之前&#xff…

leetcode 115. 不同的子序列(dp)

给定一个字符串 s 和一个字符串 t ,计算在 s 的子序列中 t 出现的个数。 字符串的一个 子序列 是指,通过删除一些(也可以不删除)字符且不干扰剩余字符相对位置所组成的新字符串。(例如,“ACE” 是 “ABCDE…

监督学习-KNN最邻近分类算法

分类(Classification)指的是从数据中选出已经分好类的训练集,在该训练集上运用数据挖掘分类的技术建立分类模型,从而对没有分类的数据进行分类的分析方法。 分类问题的应用场景:用于将事物打上一个标签,通常…

istio 和 kong_如何启动和运行Istio

istio 和 kongby Chris Cooney克里斯库尼(Chris Cooney) 如何启动和运行Istio (How to get Istio up and running) 而一旦完成,您就可以做的疯狂的事情。 (And the crazy stuff you can do once it is.) The moment you get Istio working on your cluster, it fee…

js练习--贪吃蛇(转)

最近一直在看javascript,但是发现不了动力。就开始想找动力,于是在网上找到了一个用js写的贪吃蛇游戏。奈何还不会用git,就只能先这样保存着。哈哈哈,这也算第一篇博客了,以后会坚持用自己的代码写博客的,下…

bzoj千题计划169:bzoj2463: [中山市选2009]谁能赢呢?

http://www.lydsy.com/JudgeOnline/problem.php?id2463 n为偶数时,一定可以被若干个1*2 矩形覆盖 先手每次从矩形的一端走向另一端,后手每次走向一个新的矩形 所以先手必胜 n为奇数时,先手走完一步后,剩下同n为偶数 所以先手必败…

无监督学习-主成分分析和聚类分析

聚类分析(cluster analysis)是将一组研究对象分为相对同质的群组(clusters)的统计分析技术,即将观测对象的群体按照相似性和相异性进行不同群组的划分,划分后每个群组内部各对象相似度很高,而不…

struts实现分页_在TensorFlow中实现点Struts

struts实现分页If you want to get started on 3D Object Detection and more specifically on Point Pillars, I have a series of posts written on it just for that purpose. Here’s the link. Also, going through the Point Pillars paper directly will be really help…