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.pswp.cn/news/391613.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391613.shtml
英文地址,請注明出處:http://en.pswp.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…