This tutorial is set by the author to use the CC by-NC protocol.
What is TypeScript: Simply put, it is a enhanced JavaScript, which has a more complete type system, supports class and template characteristics.When writing some complex scripts, using TypeScript can make the code clearer and reduce BUG.
Kubejs only supports the use of JavaScript language to write scripts.The TypeScript code can be compiled as the JavaScript code (using TSC), so we can write the TS code and compile it into a JS file and put it in the Scripts folder to achieve magic reform.
Version: 1.20.1, Forge, Kubejs2001.6.5-Build.7, Probejs6.0.1
VSCODE must be installed.TypeScript installation can refer to the following article: How to install TypeScript and configure the development environment to start using _NPM to install TypeScript-CSDN blog.
Rice the DUMP of Probejs before using it, otherwise what does TS do?
Open VSCODE, open the terminal, run "TSC -V", and the version number proves that TS is installed.
Enter the Kubejs directory in the terminal, and run the "MKDIR Server_TSSCRIPTS" to create a directory to store the TS source file, and then "CD Server_TSSCRIPTS".Why not put it directly in the server_scripts?Because this Kubejs does not support TS, it will also read the TS file in Server_Scripts and use it as a JS to load. ...
Run "TSC -IT". At this time, you can see a tsconfig.json file and open it.
Change "target" to "ES5", "Outdir" to "../server_scripts/compiled".
It can also be changed here to "../server_scripts", and "AllowJS" can also be enabled to use how to configure personal and team needs.
"Strict" is changed to false.This can retain the comments of Priority, otherwise the first line compiled will not be a priority annotation.Whether there is a better solution waiting for me to study again.
Create a new references.ts in the server_tsscripts directory, enter the content similar to the following form
The origin of 32 12 26 and other numbers: Do not enter these rows first, and then TSC will report an error. If which symbols are wrong, go to the original server_scripts file to build a JS file, enter this symbol, and use vscode to locate the file of this symbol, and use VSCODE to locate the file where the symbol is located.Just fill in.Why do you say that if I have time, let's talk about it, anyway, that's it like that ...
//////
///
///
///
Select Terminal-> Run Task ..., select TypeScript-> TSC: watch ... Let's test it.Create a new test.ts in the server_tsSCRIPTS directory, and enter the following content:
<<<<<<] = "assh: none;">> serverersion
Let dirt: string = "minecraft: dirt";
Event.shapeless (DIRT, "Minecraft: Redstone");
});
If everything goes well, after saving, you can find the compiled test.js in Kubejs/Server_Scripts/Compiot.In addition, you can run the command "TSC" in the Server_TSSSCRIPTS directory to compile the TS file to the JS file.
Starting the game or RELOAD, it is found that there are already formulas that synthesize soil with redstone, indicating that our TS has compiled into a JS file that can be recognized by Kubejs.
The magic reform only needs to be performed in the Server_TSSCRIPTS directory.TSC is responsible for compiling it into JS and put it in Server_Scripts.Note that if you want to write the JS code, put it in the server_scripts, or enable the ALLOWJS in the server_tsScripts.In any way, the "seamless mixing" of TS and JS can be implemented, which means that the introduction of TS does not have to give up JS, and you can still write the JS code in some parts.
I hope that this tutorial will be able to attract jade, and I look forward to the Kubejs big guys to use TypeScript to create more NB scripts.If you are not in place, please criticize and correct them.In addition, if necessary, I can make video tutorials to demonstrate specific operations.