Compare commits

..

6 Commits

6 changed files with 125 additions and 61 deletions
+73 -45
View File
@@ -1,6 +1,3 @@
// LiteLoader-AIDS automatic generated
/// <reference path="D:\LiteLoader\VSCode/dts/HelperLib-master/src/index.d.ts"/>
const GMLIB_API = {
createFloatingText: ll.import("GMLIB_API", "createFloatingText"),
deleteFloatingText: ll.import("GMLIB_API", "deleteFloatingText"),
@@ -19,6 +16,7 @@ const GMLIB_API = {
setPlayerNbt: ll.import("GMLIB_API", "setPlayerNbt"),
setPlayerNbtTags: ll.import("GMLIB_API", "setPlayerNbtTags"),
resourcePackTranslate: ll.import("GMLIB_API", "resourcePackTranslate"),
resourcePackDefaultTranslate: ll.import("GMLIB_API", "resourcePackDefaultTranslate"),
getResourcePackI18nLanguage: ll.import("GMLIB_API", "getResourcePackI18nLanguage"),
chooseResourcePackI18nLanguage: ll.import("GMLIB_API", "chooseResourcePackI18nLanguage"),
setEducationFeatureEnabled: ll.import("GMLib_ServerAPI", "setEducationFeatureEnabled"),
@@ -35,7 +33,7 @@ const GMLIB_API = {
PlayerToEntity: ll.import("GMLib_ServerAPI", "PlayerToEntity"),
setUnknownBlockCleaner: ll.import("GMLib_ModAPI", "setUnknownBlockCleaner"),
getAllExperiments: ll.import("GMLIB_API", "getAllExperiments"),
getExperimentTranslatedName: ll.import("GMLIB_API", "getExperimentTranslatedName"),
getExperimentTranslateKey: ll.import("GMLIB_API", "getExperimentTranslateKey"),
getExperimentEnabled: ll.import("GMLib_ModAPI", "getExperimentEnabled"),
setExperimentEnabled: ll.import("GMLib_ModAPI", "setExperimentEnabled"),
unregisterRecipe: ll.import("GMLIB_API", "unregisterRecipe"),
@@ -93,7 +91,12 @@ const GMLIB_API = {
getPlayerSpawnPoint: ll.import("GMLIB_API", "getPlayerSpawnPoint"),
setPlayerSpawnPoint: ll.import("GMLIB_API", "setPlayerSpawnPoint"),
clearPlayerSpawnPoint: ll.import("GMLIB_API", "clearPlayerSpawnPoint"),
setCustomPackPath: ll.import("GMLIB_API", "setCustomPackPath")
setCustomPackPath: ll.import("GMLIB_API", "setCustomPackPath"),
getSupportedLanguages: ll.import("GMLIB_API", "getSupportedLanguages"),
loadLanguage: ll.import("GMLIB_API", "loadLanguage"),
updateOrCreateLanguageFile: ll.import("GMLIB_API", "updateOrCreateLanguageFile"),
loadLanguagePath: ll.import("GMLIB_API", "loadLanguagePath"),
mergePatchJson: ll.import("GMLIB_API", "mergePatchJson")
}
const FloatingTextList = [];
@@ -360,11 +363,11 @@ class Minecraft {
}
static getServerLanguage() {
return GMLIB_API.getResourcePackI18nLanguage(language);
return I18nAPI.getCurrentLanguage();
}
static setServerLanguage(language) {
return GMLIB_API.chooseResourcePackI18nLanguage(language);
return I18nAPI.chooseLanguage(language);
}
static setCustomPackPath(path) {
@@ -372,7 +375,7 @@ class Minecraft {
}
static resourcePackTranslate(key, params = []) {
return GMLIB_API.resourcePackTranslate(key, params);
return I18nAPI.get(key, params);
}
}
@@ -429,18 +432,8 @@ class Experiments {
return GMLIB_API.getAllExperiments();
}
static getExperimentTranslatedName(id) {
return GMLIB_API.getExperimentTranslatedName(id);
}
static getExperimentsMap() {
let ids = this.getAllExperimentIds();
let result = {};
for (let id in ids) {
let name = this.getExperimentTranslatedName(id);
result[id] = name;
}
return result;
static getExperimentTranslateKey(id) {
return GMLIB_API.getExperimentTranslateKey(id);
}
static getExperimentEnabled(id) {
@@ -496,28 +489,22 @@ class Version {
if (Array.isArray(array) && array.length == 3) {
let isNumber = array.every(element => typeof element == "number");
if (isNumber) {
return new Version(array[0], array[1], array[2])
return new Version(array[0], array[1], array[2]);
}
}
return null;
}
}
class GMLIB {
constructor() {
throw new Error("Static class cannot be instantiated");
static isPluginVersionMatched(version) {
return GMLIB_API.isVersionMatched(version.mMajor, version.mMinor, version.mPatch);
}
static isVersionMatched(major, minor, patch) {
return GMLIB_API.isVersionMatched(major, minor, patch);
static getLrcaVersion() {
return Version.fromString(GMLIB_API.getVersion_LRCA());
}
static getVersion_LRCA() {
return GMLIB_API.getVersion_LRCA();
}
static getVersion_GMLIB() {
return GMLIB_API.getVersion_GMLIB();
static getGmlibVersion() {
return Version.fromString(GMLIB_API.getVersion_GMLIB());
}
}
@@ -693,7 +680,14 @@ class JsonConfig {
init() {
if (File.exists(this.mPath)) {
let existDataStr = File.readFrom(this.mPath);
this.mData = Object.assign({}, this.mData, JSON.parse(existDataStr));
existDataStr = existDataStr.replace(/\/\/.*|\/\*[^]*?\*\//g, "");
try {
let result = GMLIB_API.mergePatchJson(JSON.stringify(this.mData), existDataStr);
this.mData = JSON.parse(result);
} catch {
let newPath = this.mPath + "_old";
File.rename(this.mPath, newPath);
}
}
this.save();
}
@@ -707,9 +701,9 @@ class JsonConfig {
return this.mData;
}
get(key, defultValue = null) {
get(key, defultValue = undefined) {
let result = this.getData()[key];
if (!result && defultValue != null) {
if (!result && defultValue != undefined) {
this.set(key, defultValue);
return defultValue;
}
@@ -795,6 +789,47 @@ class JsonI18n {
}
};
class I18nAPI {
constructor() {
throw new Error("Static class cannot be instantiated");
}
static get(key, params = [], langCode = undefined) {
if (langCode) {
return GMLIB_API.resourcePackTranslate(key, params, langCode);
}
return GMLIB_API.resourcePackDefaultTranslate(key, params);
}
static translate(key, params = []) {
return I18nAPI.get(key, params);
}
static getSupportedLanguages() {
return GMLIB_API.getSupportedLanguages();
}
static getCurrentLanguage() {
return GMLIB_API.getResourcePackI18nLanguage(language);
}
static chooseLanguage(language) {
GMLIB_API.chooseResourcePackI18nLanguage(language);
}
static loadLanguage(code, language) {
GMLIB_API.loadLanguage(code, language);
}
static updateOrCreateLanguageFile(code, lang, path) {
GMLIB_API.updateOrCreateLanguageFile(code, lang, path);
}
static loadLanguageDirectory(path) {
GMLIB_API.loadLanguagePath(path);
}
};
LLSE_Player.prototype.toEntity = function () {
return GMLIB_API.PlayerToEntity(this);
}
@@ -819,23 +854,16 @@ LLSE_Entity.prototype.throwEntity = function (proj, speed = 2, offset = 3) {
return GMLIB_API.throwEntity(this, proj, speed, offset);
}
module.exports = {
StaticFloatingText,
DynamicFloatingText,
Minecraft,
Recipes,
Experiments,
GMLIB,
Scoreboard,
JsonConfig,
JsonLanguage,
JsonI18n,
Version
Version,
I18nAPI
};
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "${pluginName}",
"entry": "${pluginFile}",
"version": "0.12.4",
"version": "0.12.5",
"author": "GroupMountain",
"type": "native",
"dependencies": [
+46 -10
View File
@@ -59,7 +59,6 @@ void Export_Compatibility_API() {
});
RemoteCall::exportAs("GMLIB_API", "setPlayerNbt", [](std::string uuid, CompoundTag* nbt, bool forceCreate) -> bool {
auto uid = mce::UUID::fromString(uuid);
logger.warn(nbt->toSnbt());
return GMLIB_Player::setPlayerNbt(uid, *nbt, forceCreate);
});
RemoteCall::exportAs(
@@ -67,7 +66,6 @@ void Export_Compatibility_API() {
"setPlayerNbtTags",
[](std::string uuid, CompoundTag* nbt, std::vector<std::string> tags) -> bool {
auto uid = mce::UUID::fromString(uuid);
logger.warn(nbt->toSnbt());
return GMLIB_Player::setPlayerNbtTags(uid, *nbt, tags);
}
);
@@ -79,12 +77,12 @@ void Export_Compatibility_API() {
}
return result;
});
RemoteCall::exportAs("GMLIB_API", "getExperimentTranslatedName", [](int id) -> std::string {
auto map = GMLIB_Level::getAllExperimentsTranslateKeys();
if (map.count(id)) {
return std::string(map[id]);
}
return "";
RemoteCall::exportAs("GMLIB_API", "getExperimentTranslateKey", [](int id) -> std::string {
std::string result;
try {
result = Experiments::getExperimentTextID(AllExperiments(id));
} catch (...) {}
return result;
});
RemoteCall::exportAs(
"GMLIB_API",
@@ -155,7 +153,7 @@ void Export_Compatibility_API() {
});
RemoteCall::exportAs("GMLIB_API", "isVersionMatched", [](int a, int b, int c) -> bool {
auto version = GMLIB::Version(a, b, c, "", "");
return version >= LIB_VERSION;
return LIB_VERSION >= version;
});
RemoteCall::exportAs("GMLIB_API", "getVersion_LRCA", []() -> std::string { return LIB_VERSION.asString(); });
RemoteCall::exportAs("GMLIB_API", "getVersion_GMLIB", []() -> std::string {
@@ -163,9 +161,16 @@ void Export_Compatibility_API() {
});
RemoteCall::exportAs(
"GMLIB_API",
"resourcePackTranslate",
"resourcePackDefaultTranslate",
[](std::string key, std::vector<std::string> params) -> std::string { return I18nAPI::get(key, params); }
);
RemoteCall::exportAs(
"GMLIB_API",
"resourcePackTranslate",
[](std::string key, std::vector<std::string> params, std::string code) -> std::string {
return I18nAPI::get(key, params, code);
}
);
RemoteCall::exportAs("GMLIB_API", "chooseResourcePackI18nLanguage", [](std::string code) -> void {
if (GMLIB_Level::getInstance()) {
I18nAPI::chooseLanguage(code);
@@ -177,6 +182,31 @@ void Export_Compatibility_API() {
}
return "unknown";
});
RemoteCall::exportAs("GMLIB_API", "getSupportedLanguages", []() -> std::vector<std::string> {
if (GMLIB_Level::getInstance()) {
return I18nAPI::getSupportedLanguageCodes();
}
return {};
});
RemoteCall::exportAs("GMLIB_API", "loadLanguage", [](std::string code, std::string lang) -> void {
if (GMLIB_Level::getInstance()) {
I18nAPI::loadLanguage(code, lang);
}
});
RemoteCall::exportAs(
"GMLIB_API",
"updateOrCreateLanguageFile",
[](std::string code, std::string lang, std::string path) -> void {
if (GMLIB_Level::getInstance()) {
I18nAPI::updateOrCreateLanguageFile(path, code, lang);
}
}
);
RemoteCall::exportAs("GMLIB_API", "loadLanguagePath", [](std::string path) -> void {
if (GMLIB_Level::getInstance()) {
I18nAPI::loadLanguagesFromDirectory(path);
}
});
RemoteCall::exportAs("GMLIB_API", "getPlayerPosition", [](std::string uuid) -> std::pair<BlockPos, int> {
auto uid = mce::UUID::fromString(uuid);
auto pos = GMLIB_Player::getPlayerPosition(uid);
@@ -429,4 +459,10 @@ void Export_Compatibility_API() {
auto player = (GMLIB_Player*)pl;
player->clearSpawnPoint();
});
RemoteCall::exportAs("GMLIB_API", "mergePatchJson", [](std::string oldJson, std::string patchJson) -> std::string {
auto oldData = nlohmann::ordered_json::parse(oldJson);
auto newData = nlohmann::ordered_json::parse(patchJson);
oldData.merge_patch(newData);
return oldData.dump();
});
}
+1 -1
View File
@@ -5,7 +5,7 @@
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
#define LIB_VERSION GMLIB::Version(0, 12, 2)
#define LIB_VERSION GMLIB::Version(0, 12, 5)
extern ll::Logger logger;
+2 -2
View File
@@ -1,7 +1,7 @@
{
"format_version": 2,
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
"version": "0.12.2",
"version": "0.12.5",
"info": {
"name": "GMLIB-LegacyRemoteCallApi",
"description": "Legacy RemoteCall API for GMLIB",
@@ -14,7 +14,7 @@
"library"
]
},
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.12.2/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.12.5/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
"dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.12.4"
},