ts-minecraft
Provide several useful functions for Minecraft.
This package is targeting the Electron environment. Feel free to report issues related to it.
This package is now MAINTAINING only! The bug might not be fixed on time. I did a refactor on this package and split it into multiple small packages. The alternative of this @xmcl/minecraft-launcher-core
Usage
import { NBT, ServerInfo, ...so on...} from 'ts-minecraft'
Getting Started
NBT
; ; ; .register'server', ; ; ;
Serialize/deserialize NBT.
// First create NBT tag like this. ; rootTag.set'TheEnd', NBT.TagScalar.newString"That's all"; rootTag.set'key1', NBT.TagScalar.newString'value1'; // Checks if key exists. Then cast it to string tag. ; console.logkey1Tag.value; // print value1 // If list contains list. list those inside forget there element type. ; rootTag.set'testList', listTag; ; stringListTag.pushNBT.TagScalar.newString'hello', NBT.TagScalar.newString'world'; ; // This gives you a way to add different list in. listTag.pushstringListTag, doubleListTag; // And still prevent you add other things in it. // listTag.push(NBT.TagCompound.newCompound()); // Illegal // You can cast list to whatever list you want after you got a list without element type. console.loglistTag.asTagListString.asTagString.value; // print hello // You can iterate values in list. for of stringListTag // And also entries in compound. for of rootTag // Finally you can write root tags to buffer and read root tags from buffer. ; ; console.logcheckExistsourTag.get'TheEnd'.asTagString.value; // print That's all
Typed NBT API for structured NBT manipulation.
WorldInfo
; ;
Read a WorldInfo from buffer.
Server
; ; // fetch the server status ; // or you want the raw json ;
Read sever info and fetch its status.
Minecraft Install
; .thenmetas.list.versions // i just pick the first version in list here .thenVersion.install'client', meta, minecraft
Fully install vanilla minecraft client including assets and libs.
GameSetting
; ; ;
Serialize/Deserialize the minecraft game setting string.
Language
; ;
Read language info from version
ResourcePack
; Promise<ResourcePack> packPromise = ResourcePack.readfileFullPath; // or you want read from folder, same function call Promise<ResourcePack> fromFolder = ResourcePack.readfileFullPath; // if you have already read the file, don't want to reopen the file // the file path will be only used for resource pack name ; Promise<ResourcePack> packPromise = ResourcePack.readfileFullPath, fileContentBuffer;
Read ResourcePack from filePath
Game Profile
; ;
Or lookup profile by name.
; ;
Fetch the user game profile by uuid. This could also be used for get skin.
; ;
Mojang Account Info
; ;
Forge
; Promise<Forge.MetaData> metasPromise = Forge.metaforgeModJarBuff;
Read the forge mod metadata, including @Mod annotation and mcmod json data
; ; ;
Read the forge mod config
; ; pagePromise.then;
Get the forge version info and install forge from it.
Notice that this installation doesn't ensure full libraries installation.
Please run Version.checkDependencies
afther that.
The new 1.13 forge installation process requires java to run.
Either you have java
executable in your environment variable PATH,
or you can assign java location by Forge.install(forgeVersionMeta, minecraftLocation, { java: yourJavaExecutablePath });
.
If you use this auto installation process to install forge, please checkout Lex's Patreon. Consider support him to maintains forge.
Fabric
; ; // yarn version is combined by mcversion+yarn build number ;
Fetch the new fabric version list.
; ; // e.g. "1.14.1+build.10" ; // e.g. "0.4.7+build.147"
Install fabric to the client. This installation process doesn't ensure the minecraft libraries.
Please run Version.checkDependencies
after that to install fully.
TextComponent
; ; ;
Create TextComponent from string OR Minecraft's formatted string, like '§cThis is red'
Auth
; ; ; ;
Using AuthService to online/offline auth
Version
; ; ;
Parse existed version.
Launch
; ; ; ;
Launch minecraft from a version
Experiental Features
They might be not stable.
Monitor download progress
; ; ; ; ;
Caching Request
The functions that request minecraft version manifest, forge version webpage, or liteload version manifest can have cache option.
You should save the old result from those functions and pass it as the fallback option. These function will check if your old manifest is outdated or not, and it will only request a new one when your fallback option is outdated.
For Minecraft:
; ; // this should not request the manifest url again, since the forceGetTheVersionMeta is not outdated.
Normally you will load the last version manifest from file:
; ; // the result should up-to-date.
For Forge, it's the same:
; // force get ; ; // this should be up-to-date
Issue
- Really need runtime check for parsed Forge/LiteMod data(Hopefully, more people write this correctly)
Credit
Yu Xuanchi, co-worker, quality control of this project.
Haowei Wen, the author of JMCCC, Authlib Injector, and Indexyz, help me a lot on Minecraft launching, authing.