From b7df1ae387187aa12b897aaf1c9ac1c02d1a5134 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 Date: Fri, 29 Mar 2024 17:38:06 +0800 Subject: [PATCH] refactor: refactoring some api --- SDK-GMLIB | 2 +- lib/GMLIB_API-JS.js | 52 +++++++++++++++++++++++++++------------- src/CompatibilityApi.cpp | 9 +++++-- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/SDK-GMLIB b/SDK-GMLIB index 37d9220..ae86cc4 160000 --- a/SDK-GMLIB +++ b/SDK-GMLIB @@ -1 +1 @@ -Subproject commit 37d92200bd9a534ec6f86d8c27abf3a0af0b40f4 +Subproject commit ae86cc4327234e269b9be480148d9d6fe495b6fe diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index 535a701..ea5db01 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -1,3 +1,6 @@ +// LiteLoader-AIDS automatic generated +/// + const GMLIB_API = { createFloatingText: ll.import("GMLIB_API", "createFloatingText"), deleteFloatingText: ll.import("GMLIB_API", "deleteFloatingText"), @@ -319,18 +322,6 @@ class Minecraft { return GMLIB_API.setWorldSpawn(pos); } - static getPlayerSpawnPoint() { - return GMLIB_API.getPlayerSpawnPoint(); - } - - static setPlayerSpawnPoint(pos) { - GMLIB_API.setPlayerSpawnPoint(pos); - } - - static clearPlayerSpawnPoint() { - GMLIB_API.clearPlayerSpawnPoint(); - } - static setEducationFeatureEnabled() { return GMLIB_API.setEducationFeatureEnabled(); } @@ -367,10 +358,6 @@ class Minecraft { return GMLIB_API.setUnknownBlockCleaner(); } - static playerToEntity(player) { - return GMLIB_API.PlayerToEntity(player); - } - static spawnEntity(pos, name) { return GMLIB_API.spawnEntity(pos, name); } @@ -819,6 +806,31 @@ class JsonI18n { } }; +LLSE_Player.prototype.toEntity = function () { + return GMLIB_API.PlayerToEntity(this); +} + +LLSE_Player.prototype.getSpawnPoint = function () { + return GMLIB_API.getPlayerSpawnPoint(this); +} + +LLSE_Player.prototype.setSpawnPoint = function (pos) { + return GMLIB_API.setPlayerSpawnPoint(this, pos); +} + +LLSE_Player.prototype.clearSpawnPoint = function () { + return GMLIB_API.clearPlayerSpawnPoint(this); +} + +LLSE_Entity.prototype.shootProjectile = function (proj, speed = 2, offset = 3) { + return GMLIB_API.shootProjectile(this, proj, speed, offset); +} + +LLSE_Entity.prototype.throwEntity = function (proj, speed = 2, offset = 3) { + return GMLIB_API.throwEntity(this, proj, speed, offset); +} + + module.exports = { StaticFloatingText, DynamicFloatingText, @@ -831,4 +843,10 @@ module.exports = { JsonLanguage, JsonI18n, Version -}; \ No newline at end of file +}; + + + + + + diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index da9350a..c93ba4c 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -171,10 +171,15 @@ void Export_Compatibility_API() { [](std::string key, std::vector params) -> std::string { return I18n::get(key, params); } ); RemoteCall::exportAs("GMLIB_API", "chooseResourcePackI18nLanguage", [](std::string code) -> void { - I18n::chooseLanguage(code); + if (GMLIB_Level::getInstance()) { + I18n::chooseLanguage(code); + } }); RemoteCall::exportAs("GMLIB_API", "getResourcePackI18nLanguage", []() -> std::string { - return I18n::getCurrentLanguage()->getFullLanguageCode(); + if (GMLIB_Level::getInstance()) { + return I18n::getCurrentLanguage()->getFullLanguageCode(); + } + return "unknown"; }); RemoteCall::exportAs("GMLIB_API", "getPlayerPosition", [](std::string uuid) -> std::pair { auto uid = mce::UUID::fromString(uuid);