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

typescript 使用_如何使用TypeScript轻松修改Minecraft相关推荐

  1. typescript项目_如何设置TypeScript项目

    typescript项目 by David Piepgrass 由David Piepgrass 如何设置TypeScript项目 (How to set up a TypeScript projec ...

  2. 系统学习 TypeScript(一)——认识 TypeScript

    前言 TypeScript 很流行,这是前端从业者众所周知的事. TypeScript 很好用,仁者见仁智者见智.但是,很多大型前端框架都使用 TypeScript 进行了重构. 为了不落伍,我也需要 ...

  3. [ Typescript 手册] JavaScript `Array` 在 Typescript 中的接口

    [ Typescript 手册] JavaScript `Array` 在 Typescript 中的接口 本文地址:https://blog.csdn.net/qq_28550263/article ...

  4. 教你用ERD轻松修改系统登录密码

    赛迪网--中国电脑教育报4月12日报道 在机房管理过程中,我们经常会碰到因一时疏忽而忘记了系统超级管理员密码的情况.由于事前没有制作密码重设盘,等发现遗忘密码无法登录时,便后悔莫及.计算机系统分区中没 ...

  5. formdata多文件上传_如何使用FormData轻松上传单个或多个文件

    formdata多文件上传 In this post, we'll learn about the FormData interface available in modern web browser ...

  6. 【TypeScript】HTML直接引入TypeScript脚本

    大家都知道,HTML可以直接引入JavaScript脚本文件.有一天,博主就想到:博主学习TypeScript的时候,都是使用命令行编译器tsc或其他工具手动执行,那HTML能不能直接引入TypeSc ...

  7. FANUC机器人_程序轨迹编写和修改的具体方法步骤(图文)

    FANUC机器人_程序轨迹编写和修改的具体方法步骤 一. 修改标准动作指令 基本步骤可参考如下: 首先,点击"教点资料",如下图所示,

  8. typescript官方中文文档,typescript是什么意思

    typescript是什么意思 TypeScript是一种由微软开发的自由和开源的编程语言.它是JavaScript的一个超集,而且本质上向这个语言添加了可选的静态类型和基于类的面向对象编程. 安德斯 ...

  9. 轻松修改PPT中剪贴画颜色

    在制作演示文稿时,为了达到满意的效果我们经常会插入漂亮的剪贴画.但 有时起到的效果会相反,因为剪贴画是程序自带的组件,其颜色都是固定的 ,这样就可能与页面整体的效果不协调. 其实大家不必为其担心,借助 ...

最新文章

  1. 吴裕雄 10-MySQL插入数据
  2. 生物技术行业十年回顾:微生物组发展未达预期?
  3. 【Linux】Centos7 解压zip文件
  4. canvas requestAnimationFrame 动画
  5. 蛮力算法百元百鸡java_每日一算法:百元百鸡
  6. Request load debugging - CRM side
  7. python 图片转视频ffmpeg_python图片转视频(opencv),ffmpeg压缩视频
  8. css3自适应布局单位vw,vh你知道多少?
  9. python 中内置函数
  10. You have provided a value for the LANGUAGE_CODE setting that is not in the LANGUAGES setting
  11. WINDOWS10经常莫名其妙的卡死一会
  12. android .9横向拉伸,神奇的问题!android .9图片拉伸不是不会变形吗?但是这里变形了...
  13. AOF -- Redis 设计与实现
  14. 刷魔趣系统与安装google相机
  15. ENVI监督分类图像分割
  16. 大学十年(一个程序员的路程)(林锐博士)《1----9》【林锐的大学10年】
  17. DevOps亚马逊AWS相关介绍
  18. 序列的自相关和互相关计算
  19. 计算机网络技术店面取名,适合电脑店的名字大全 霸气的电脑店铺起名
  20. 金蝶软件校园招聘Java开发工程师笔试面试情况分享

热门文章

  1. 23. 合并K个排序链表
  2. java将字节数组转换成字符串,面试心得体会
  3. HDU 3966 树链剖分后线段树维护
  4. UIView封装动画--iOS利用系统提供方法来做关键帧动画
  5. [转载]UEditor报错TypeError: me.body is undefined
  6. Struts1和Struts2的区别和对比(完整版)(转)
  7. jquery调用asp.net 页面后台的实现代码
  8. 数据结构05数组和广义表
  9. Spring Cloud构建微服务架构-Hystrix监控面板
  10. 让自己的头脑极度开放