From 5cc610a830cae8321f6f99ed8c1d8e8604726c0e Mon Sep 17 00:00:00 2001 From: KobeBryant114514 <116721335+KobeBryant114514@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:59:48 +0800 Subject: [PATCH 1/2] feat: add NpcDialogueForm --- lib/FormAPI-JS.js | 57 +++++++++++++++++++++++++++++++-- src/FormAPI.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 130 insertions(+), 7 deletions(-) diff --git a/lib/FormAPI-JS.js b/lib/FormAPI-JS.js index d51bfbe..eeb8a69 100644 --- a/lib/FormAPI-JS.js +++ b/lib/FormAPI-JS.js @@ -1,6 +1,10 @@ const getNextCallbackId = ll.import("GMLIB_FormAPI", "getNextFormCallbackId"); class ServerSettingForm { + constructor() { + throw new Error("Static class cannot be instantiated"); + } + static getDefaultPriority() { return ll.import("GMLIB_ServerSettingForm", "getDefaultPriority")(); } @@ -123,7 +127,56 @@ class ServerSettingForm { static removeElement(id) { return ll.import("GMLIB_ServerSettingForm", "removeElement")(id); } - } -module.exports = { ServerSettingForm }; \ No newline at end of file +class NpcDialogueForm { + constructor(npcName, sceneName, dialogue) { + this.mFormId = ll.import("GMLIB_NpcDialogueForm", "createForm")(npcName, sceneName, dialogue); + } + + addButton(button) { + return ll.import("GMLIB_NpcDialogueForm", "addButton")(this.mFormId, button); + } + + sendTo(pl, callback = (pl, index, type) => { }, free = true) { + let callbackId = getNextCallbackId(); + ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId); + ll.import("GMLIB_NpcDialogueForm", "sendTo")(this.mFormId, pl, callbackId); + if (free) { + this.destroy(); + } + } + + destroy() { + ll.import("GMLIB_NpcDialogueForm", "destroyForm")(this.mFormId); + } +} + +class ChestForm { + constructor(npcName, sceneName, dialogue) { + this.mFormId = ll.import("GMLIB_NpcDialogueForm", "createForm")(npcName, sceneName, dialogue); + } + + addButton(button) { + return ll.import("GMLIB_NpcDialogueForm", "addButton")(this.mFormId, button); + } + + sendTo(pl, free = true) { + //let callbackId = getNextCallbackId(); + //ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId); + //ll.import("GMLIB_NpcDialogueForm", "sendTo")(this.mFormId, pl, callbackId); + //if (free) { + // this.destroy(); + //} + } + + destroy() { + //ll.import("GMLIB_NpcDialogueForm", "destroyForm")(this.mFormId); + } +} + +module.exports = { + ServerSettingForm, + NpcDialogueForm, + ChestForm +}; \ No newline at end of file diff --git a/src/FormAPI.cpp b/src/FormAPI.cpp index 90da1c3..474516d 100644 --- a/src/FormAPI.cpp +++ b/src/FormAPI.cpp @@ -1,12 +1,16 @@ #include "Global.h" +#include + using namespace GMLIB::Server::Form; using namespace ll::hash_utils; class LegacyScriptFormManager { private: - int64 mNextFormCallbackId = 0; - // std::unordered_map mEventListeners; + int64 mNextFormCallbackId = 0; + int64 mNextFormId = 0; + std::unordered_map> mNpcDialogueForms; + std::unordered_map> mChestForms; public: std::string getNextFormCallbackId() { @@ -14,6 +18,33 @@ public: return "GMLIB_EVENT_" + std::to_string(mNextFormCallbackId); } + int64 getNextFormId() { + mNextFormId++; + return mNextFormId; + } + + int64 createNpcDialogueForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) { + auto formId = LegacyScriptFormManager::getInstance().getNextFormId(); + auto formPtr = std::make_unique(npcName, sceneName, dialogue); + mNpcDialogueForms[formId] = std::move(formPtr); + return formId; + } + + bool destroyNpcDialogueForm(int64 formId) { + if (mNpcDialogueForms.contains(formId)) { + mNpcDialogueForms.erase(formId); + return true; + } + return false; + } + + optional_ref getNpcDialogueForm(int64 formId) { + if (mNpcDialogueForms.contains(formId)) { + return mNpcDialogueForms[formId].get(); + } + return {}; + } + public: static LegacyScriptFormManager& getInstance() { static std::unique_ptr instance; @@ -89,12 +120,14 @@ public: void Export_Form_API() { - RemoteCall::exportAs("GMLIB_ServerSettingForm", "getDefaultPriority", []() -> int { - return ServerSettingForm::getDefaultPriority(); - }); + //////////////////////////////// Form Manager ///////////////////////////////// RemoteCall::exportAs("GMLIB_FormAPI", "getNextFormCallbackId", []() -> std::string { return LegacyScriptFormManager::getInstance().getNextFormCallbackId(); }); + ////////////////////////////// ServerSettingForm ////////////////////////////// + RemoteCall::exportAs("GMLIB_ServerSettingForm", "getDefaultPriority", []() -> int { + return ServerSettingForm::getDefaultPriority(); + }); RemoteCall::exportAs("GMLIB_ServerSettingForm", "hasTitle", []() -> bool { return ServerSettingForm::hasTitle(); }); RemoteCall::exportAs("GMLIB_ServerSettingForm", "getTitle", []() -> std::string { return ServerSettingForm::getTitle(); @@ -229,4 +262,41 @@ void Export_Form_API() { RemoteCall::exportAs("GMLIB_ServerSettingForm", "removeElement", [](uint id) -> bool { return ServerSettingForm::removeElement(id); }); + ////////////////////////////// NpcDialogueForm ////////////////////////////// + RemoteCall::exportAs( + "GMLIB_NpcDialogueForm", + "createForm", + [](std::string const& npcName, std::string const& sceneName, std::string const& dialogue) -> int64 { + return LegacyScriptFormManager::getInstance().createNpcDialogueForm(npcName, sceneName, dialogue); + } + ); + RemoteCall::exportAs("GMLIB_NpcDialogueForm", "destroyForm", [](int64 formId) -> bool { + return LegacyScriptFormManager::getInstance().destroyNpcDialogueForm(formId); + }); + RemoteCall::exportAs("GMLIB_NpcDialogueForm", "addButton", [](int64 formId, std::string const& button) -> int { + if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) { + return formPtr->addButton(button); + } + return -1; + }); + RemoteCall::exportAs( + "GMLIB_NpcDialogueForm", + "sendTo", + [](int64 formId, Player* pl, std::string const& callbackId) -> void { + if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) { + formPtr->sendTo(*pl, [callbackId](Player& pl, int index, NpcRequestPacket::RequestType type) -> void { + try { + if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { + auto const& callback = RemoteCall::importAs( + "GMLIB_FORM_CALLBACK", + callbackId + ); + callback(&pl, index, (int)type); + } + } catch (...) {} + }); + } + } + ); + ////////////////////////////// ChestForm ////////////////////////////// } \ No newline at end of file From 2a4a884d7a077076d3dcfc3d7b76eb3f7175ca4b Mon Sep 17 00:00:00 2001 From: KobeBryant114514 <116721335+KobeBryant114514@users.noreply.github.com> Date: Sun, 20 Oct 2024 16:00:57 +0800 Subject: [PATCH 2/2] feat: adapt --- src/CompatibilityApi.cpp | 343 ++++++++++++++++++++------------------- src/Entry.cpp | 4 +- src/Entry.h | 4 +- src/EventAPI.cpp | 70 ++++---- src/FormAPI.cpp | 99 +++++++---- src/Global.h | 12 +- src/LegacyModApi.cpp | 48 +++--- src/LegacyServerApi.cpp | 36 ++-- src/PlaceholderApi.cpp | 12 +- 9 files changed, 340 insertions(+), 288 deletions(-) diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 7e213c1..7f46029 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -1,4 +1,7 @@ #include "Global.h" +#include "mc/world/item/Item.h" +#include "mc/world/item/enchanting/EnchantUtils.h" +#include "mc/world/level/block/Block.h" #include #include @@ -16,31 +19,31 @@ ActorUniqueID parseScriptUniqueID(std::string const& uniqueId) { void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "unregisterRecipe", [](std::string const& id) -> bool { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return false; } - return CustomRecipe::unregisterRecipe(id); + return recipe::RecipeRegistry::unregisterRecipe(id); }); RemoteCall::exportAs("GMLIB_API", "setCustomPackPath", [](std::string const& path) -> void { - CustomPacks::addCustomPackPath(path); + AddonsLoader::addCustomPackPath(path); }); RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return 0.0f; } return level->getServerMspt(); }); RemoteCall::exportAs("GMLIB_API", "getServerCurrentTps", []() -> float { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return 0.0f; } return level->getServerCurrentTps(); }); RemoteCall::exportAs("GMLIB_API", "getServerAverageTps", []() -> float { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return 0.0f; } @@ -48,38 +51,40 @@ void Export_Compatibility_API() { }); RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector { std::vector result; - std::vector uuids = GMLIB_Player::getAllUuids(); + std::vector uuids = world::Player::getAllUuids(); for (auto& uuid : uuids) { result.push_back(uuid.asString()); } return result; }); - RemoteCall::exportAs("GMLIB_API", "getPlayerNbt", [](std::string const& uuid) -> std::unique_ptr { + RemoteCall::exportAs("GMLIB_API", "getPlayerNbt", [](std::string const& uuid) -> std::unique_ptr<::CompoundTag> { auto uid = mce::UUID::fromString(uuid); - return std::move(GMLIB_Player::getPlayerNbt(uid)); + return std::move(world::Player::getPlayerNbt(uid)); }); RemoteCall::exportAs( "GMLIB_API", "setPlayerNbt", - [](std::string const& uuid, CompoundTag* nbt, bool forceCreate) -> bool { - auto uid = mce::UUID::fromString(uuid); - return GMLIB_Player::setPlayerNbt(uid, *nbt, forceCreate); + [](std::string const& uuid, ::CompoundTag* nbt, bool forceCreate) -> bool { + auto uid = mce::UUID::fromString(uuid); + auto nbtt = world::CompoundTag(*nbt); + return world::Player::setPlayerNbt(uid, nbtt, forceCreate); } ); RemoteCall::exportAs( "GMLIB_API", "setPlayerNbtTags", - [](std::string const& uuid, CompoundTag* nbt, std::vector tags) -> bool { - auto uid = mce::UUID::fromString(uuid); - return GMLIB_Player::setPlayerNbtTags(uid, *nbt, tags); + [](std::string const& uuid, ::CompoundTag* nbt, std::vector tags) -> bool { + auto uid = mce::UUID::fromString(uuid); + auto nbtt = world::CompoundTag(*nbt); + return world::Player::setPlayerNbtTags(uid, nbtt, tags); } ); RemoteCall::exportAs("GMLIB_API", "deletePlayerNbt", [](std::string const& uuid) -> bool { auto uid = mce::UUID::fromString(uuid); - return GMLIB_Player::deletePlayerNbt(uid); + return world::Player::deletePlayerNbt(uid); }); RemoteCall::exportAs("GMLIB_API", "getAllExperiments", []() -> std::vector { - auto list = GMLIB_Level::getAllExperiments(); + auto list = world::Level::getAllExperiments(); std::vector result; for (auto& key : list) { result.push_back((int)key); @@ -113,7 +118,7 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "deleteFloatingText", [](int id) -> bool { return FloatingTextManager::getInstance().remove(id); }); - RemoteCall::exportAs("GMLIB_API", "sendFloatingTextToPlayer", [](int id, Player* pl) -> bool { + RemoteCall::exportAs("GMLIB_API", "sendFloatingTextToPlayer", [](int id, ::Player* pl) -> bool { if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) { ft->sendTo(*pl); return true; @@ -127,7 +132,7 @@ void Export_Compatibility_API() { } return false; }); - RemoteCall::exportAs("GMLIB_API", "removeFloatingTextFromPlayer", [](int id, Player* pl) -> bool { + RemoteCall::exportAs("GMLIB_API", "removeFloatingTextFromPlayer", [](int id, ::Player* pl) -> bool { if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) { ft->removeFrom(*pl); return true; @@ -141,7 +146,7 @@ void Export_Compatibility_API() { } return false; }); - RemoteCall::exportAs("GMLIB_API", "updateClientFloatingTextData", [](int id, Player* pl) -> bool { + RemoteCall::exportAs("GMLIB_API", "updateClientFloatingTextData", [](int id, ::Player* pl) -> bool { if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) { ft->update(*pl); return true; @@ -176,24 +181,24 @@ void Export_Compatibility_API() { } ); RemoteCall::exportAs("GMLIB_API", "chooseResourcePackI18nLanguage", [](std::string const& code) -> void { - if (GMLIB_Level::getInstance()) { + if (world::Level::getInstance()) { I18nAPI::chooseLanguage(code); } }); RemoteCall::exportAs("GMLIB_API", "getResourcePackI18nLanguage", []() -> std::string { - if (GMLIB_Level::getInstance()) { + if (world::Level::getInstance()) { return I18nAPI::getCurrentLanguageCode(); } return "unknown"; }); RemoteCall::exportAs("GMLIB_API", "getSupportedLanguages", []() -> std::vector { - if (GMLIB_Level::getInstance()) { + if (world::Level::getInstance()) { return I18nAPI::getSupportedLanguageCodes(); } return {}; }); RemoteCall::exportAs("GMLIB_API", "loadLanguage", [](std::string const& code, std::string const& lang) -> void { - if (GMLIB_Level::getInstance()) { + if (world::Level::getInstance()) { I18nAPI::loadLanguage(code, lang); } }); @@ -202,19 +207,19 @@ void Export_Compatibility_API() { "updateOrCreateLanguageFile", [](std::string const& code, std::unordered_map lang, std::string const& path ) -> void { - if (GMLIB_Level::getInstance()) { + if (world::Level::getInstance()) { I18nAPI::updateOrCreateLanguageFile(path, code, lang); } } ); RemoteCall::exportAs("GMLIB_API", "loadLanguagePath", [](std::string const& path) -> void { - if (GMLIB_Level::getInstance()) { + if (world::Level::getInstance()) { I18nAPI::loadLanguagesFromDirectory(path); } }); RemoteCall::exportAs("GMLIB_API", "getPlayerPosition", [](std::string const& uuid) -> std::pair { auto uid = mce::UUID::fromString(uuid); - auto pos = GMLIB_Player::getPlayerPosition(uid); + auto pos = world::Player::getPlayerPosition(uid); if (pos.has_value()) { return pos.value(); } @@ -228,19 +233,19 @@ void Export_Compatibility_API() { "setPlayerPosition", [](std::string const& uuid, std::pair pos) -> bool { auto uid = mce::UUID::fromString(uuid); - return GMLIB_Player::setPlayerPosition(uid, pos.first, pos.second); + return world::Player::setPlayerPosition(uid, pos.first, pos.second); } ); RemoteCall::exportAs("GMLIB_API", "playerHasScore", [](std::string const& uuid, std::string const& obj) -> bool { auto uid = mce::UUID::fromString(uuid); - if (auto result = GMLIB_Player::getPlayerScore(uid, obj)) { + if (auto result = world::Player::getPlayerScore(uid, obj)) { return true; } return false; }); RemoteCall::exportAs("GMLIB_API", "getPlayerScore", [](std::string const& uuid, std::string const& obj) -> int { auto uid = mce::UUID::fromString(uuid); - if (auto result = GMLIB_Player::getPlayerScore(uid, obj)) { + if (auto result = world::Player::getPlayerScore(uid, obj)) { return result.value(); } return 0; @@ -250,7 +255,7 @@ void Export_Compatibility_API() { "addPlayerScore", [](std::string const& uuid, std::string const& obj, int value) -> bool { auto uid = mce::UUID::fromString(uuid); - if (auto res = GMLIB_Player::setPlayerScore(uid, obj, value, PlayerScoreSetFunction::Add)) { + if (auto res = world::Player::setPlayerScore(uid, obj, value, PlayerScoreSetFunction::Add)) { return true; } return false; @@ -261,7 +266,7 @@ void Export_Compatibility_API() { "reducePlayerScore", [](std::string const& uuid, std::string const& obj, int value) -> bool { auto uid = mce::UUID::fromString(uuid); - if (auto res = GMLIB_Player::setPlayerScore(uid, obj, value, PlayerScoreSetFunction::Subtract)) { + if (auto res = world::Player::setPlayerScore(uid, obj, value, PlayerScoreSetFunction::Subtract)) { return true; } return false; @@ -272,7 +277,7 @@ void Export_Compatibility_API() { "setPlayerScore", [](std::string const& uuid, std::string const& obj, int value) -> bool { auto uid = mce::UUID::fromString(uuid); - if (auto res = GMLIB_Player::setPlayerScore(uid, obj, value)) { + if (auto res = world::Player::setPlayerScore(uid, obj, value)) { return true; } return false; @@ -280,18 +285,18 @@ void Export_Compatibility_API() { ); RemoteCall::exportAs("GMLIB_API", "resetPlayerScore", [](std::string const& uuid, std::string const& obj) -> bool { auto uid = mce::UUID::fromString(uuid); - return GMLIB_Player::resetPlayerScore(uid, obj); + return world::Player::resetPlayerScore(uid, obj); }); RemoteCall::exportAs("GMLIB_API", "resetPlayerScores", [](std::string const& uuid) -> bool { auto uid = mce::UUID::fromString(uuid); - return GMLIB_Player::resetPlayerScore(uid); + return world::Player::resetPlayerScore(uid); }); RemoteCall::exportAs( "GMLIB_API", "entityHasScore", [](std::string const& uniqueId, std::string const& obj) -> bool { auto auid = parseScriptUniqueID(uniqueId); - if (auto result = GMLIB_Scoreboard::getInstance()->getScore(obj, auid)) { + if (auto result = world::Scoreboard::getInstance()->getScore(obj, auid)) { return true; } return false; @@ -299,7 +304,7 @@ void Export_Compatibility_API() { ); RemoteCall::exportAs("GMLIB_API", "getEntityScore", [](std::string const& uniqueId, std::string const& obj) -> int { auto auid = parseScriptUniqueID(uniqueId); - if (auto result = GMLIB_Scoreboard::getInstance()->getScore(obj, auid)) { + if (auto result = world::Scoreboard::getInstance()->getScore(obj, auid)) { return result.value(); } return 0; @@ -309,7 +314,7 @@ void Export_Compatibility_API() { "addEntityScore", [](std::string const& uniqueId, std::string const& obj, int value) -> bool { auto auid = parseScriptUniqueID(uniqueId); - if (auto res = GMLIB_Scoreboard::getInstance()->setScore(obj, auid, value, PlayerScoreSetFunction::Add)) { + if (auto res = world::Scoreboard::getInstance()->setScore(obj, auid, value, PlayerScoreSetFunction::Add)) { return true; } return false; @@ -321,7 +326,7 @@ void Export_Compatibility_API() { [](std::string const& uniqueId, std::string const& obj, int value) -> bool { auto auid = parseScriptUniqueID(uniqueId); if (auto res = - GMLIB_Scoreboard::getInstance()->setScore(obj, auid, value, PlayerScoreSetFunction::Subtract)) { + world::Scoreboard::getInstance()->setScore(obj, auid, value, PlayerScoreSetFunction::Subtract)) { return true; } return false; @@ -332,7 +337,7 @@ void Export_Compatibility_API() { "setEntityScore", [](std::string const& uniqueId, std::string const& obj, int value) -> bool { auto auid = parseScriptUniqueID(uniqueId); - if (auto res = GMLIB_Scoreboard::getInstance()->setScore(obj, auid, value)) { + if (auto res = world::Scoreboard::getInstance()->setScore(obj, auid, value)) { return true; } return false; @@ -343,25 +348,25 @@ void Export_Compatibility_API() { "resetEntityScore", [](std::string const& uniqueId, std::string const& obj) -> bool { auto auid = parseScriptUniqueID(uniqueId); - return GMLIB_Scoreboard::getInstance()->resetScore(obj, auid); + return world::Scoreboard::getInstance()->resetScore(obj, auid); } ); RemoteCall::exportAs("GMLIB_API", "resetEntityScores", [](std::string const& uniqueId) -> bool { auto auid = parseScriptUniqueID(uniqueId); - return GMLIB_Scoreboard::getInstance()->resetScore(auid); + return world::Scoreboard::getInstance()->resetScore(auid); }); RemoteCall::exportAs( "GMLIB_API", "fakePlayerHasScore", [](std::string const& name, std::string const& obj) -> bool { - if (auto result = GMLIB_Scoreboard::getInstance()->getScore(obj, name)) { + if (auto result = world::Scoreboard::getInstance()->getScore(obj, name)) { return true; } return false; } ); RemoteCall::exportAs("GMLIB_API", "getFakePlayerScore", [](std::string const& name, std::string const& obj) -> int { - if (auto result = GMLIB_Scoreboard::getInstance()->getScore(obj, name)) { + if (auto result = world::Scoreboard::getInstance()->getScore(obj, name)) { return result.value(); } return 0; @@ -370,7 +375,7 @@ void Export_Compatibility_API() { "GMLIB_API", "addFakePlayerScore", [](std::string const& name, std::string const& obj, int value) -> bool { - if (auto res = GMLIB_Scoreboard::getInstance()->setScore(obj, name, value, PlayerScoreSetFunction::Add)) { + if (auto res = world::Scoreboard::getInstance()->setScore(obj, name, value, PlayerScoreSetFunction::Add)) { return true; } return false; @@ -381,7 +386,7 @@ void Export_Compatibility_API() { "reduceFakePlayerScore", [](std::string const& name, std::string const& obj, int value) -> bool { if (auto res = - GMLIB_Scoreboard::getInstance()->setScore(obj, name, value, PlayerScoreSetFunction::Subtract)) { + world::Scoreboard::getInstance()->setScore(obj, name, value, PlayerScoreSetFunction::Subtract)) { return true; } return false; @@ -391,7 +396,7 @@ void Export_Compatibility_API() { "GMLIB_API", "setFakePlayerScore", [](std::string const& name, std::string const& obj, int value) -> bool { - if (auto res = GMLIB_Scoreboard::getInstance()->setScore(obj, name, value)) { + if (auto res = world::Scoreboard::getInstance()->setScore(obj, name, value)) { return true; } return false; @@ -401,14 +406,14 @@ void Export_Compatibility_API() { "GMLIB_API", "resetFakePlayerScore", [](std::string const& name, std::string const& obj) -> bool { - return GMLIB_Scoreboard::getInstance()->resetScore(obj, name); + return world::Scoreboard::getInstance()->resetScore(obj, name); } ); RemoteCall::exportAs("GMLIB_API", "resetFakePlayerScores", [](std::string const& name) -> bool { - return GMLIB_Scoreboard::getInstance()->resetScore(name); + return world::Scoreboard::getInstance()->resetScore(name); }); RemoteCall::exportAs("GMLIB_API", "addObjective", [](std::string const& obj) -> bool { - if (auto res = GMLIB_Scoreboard::getInstance()->addObjective(obj)) { + if (auto res = world::Scoreboard::getInstance()->addObjective(obj)) { return true; } return false; @@ -417,14 +422,14 @@ void Export_Compatibility_API() { "GMLIB_API", "addObjectiveWithDisplayName", [](std::string const& obj, std::string const& displayName) -> bool { - if (auto res = GMLIB_Scoreboard::getInstance()->addObjective(obj, displayName)) { + if (auto res = world::Scoreboard::getInstance()->addObjective(obj, displayName)) { return true; } return false; } ); RemoteCall::exportAs("GMLIB_API", "getDisplayName", [](std::string const& obj) -> std::string { - if (auto result = GMLIB_Scoreboard::getInstance()->getObjectiveDisplayName(obj)) { + if (auto result = world::Scoreboard::getInstance()->getObjectiveDisplayName(obj)) { return result.value(); } return ""; @@ -433,24 +438,24 @@ void Export_Compatibility_API() { "GMLIB_API", "setDisplayName", [](std::string const& obj, std::string const& displayName) -> bool { - return GMLIB_Scoreboard::getInstance()->setObjectiveDisplayName(obj, displayName); + return world::Scoreboard::getInstance()->setObjectiveDisplayName(obj, displayName); } ); RemoteCall::exportAs("GMLIB_API", "removeObjective", [](std::string const& obj) -> bool { - return GMLIB_Scoreboard::getInstance()->removeObjective(obj); + return world::Scoreboard::getInstance()->removeObjective(obj); }); RemoteCall::exportAs( "GMLIB_API", "setDisplayObjective", [](std::string const& obj, std::string const& slot, int order) -> void { - return GMLIB_Scoreboard::getInstance()->setObjectiveDisplay(obj, slot, (ObjectiveSortOrder)order); + return world::Scoreboard::getInstance()->setObjectiveDisplay(obj, slot, (ObjectiveSortOrder)order); } ); RemoteCall::exportAs("GMLIB_API", "clearDisplayObjective", [](std::string const& slot) -> void { - return GMLIB_Scoreboard::getInstance()->clearObjectiveDisplay(slot); + return world::Scoreboard::getInstance()->clearObjectiveDisplay(slot); }); RemoteCall::exportAs("GMLIB_API", "getAllObjectives", []() -> std::vector { - auto objs = GMLIB_Scoreboard::getInstance()->getObjectives(); + auto objs = world::Scoreboard::getInstance()->getObjectives(); std::vector result; for (auto& obj : objs) { result.push_back(obj->getName()); @@ -458,7 +463,7 @@ void Export_Compatibility_API() { return result; }); RemoteCall::exportAs("GMLIB_API", "getAllScoreboardPlayers", []() -> std::vector { - auto uuids = GMLIB_Scoreboard::getInstance()->getAllPlayerUuids(); + auto uuids = world::Scoreboard::getInstance()->getAllPlayerUuids(); std::vector result; for (auto& uuid : uuids) { result.push_back(uuid.asString()); @@ -466,7 +471,7 @@ void Export_Compatibility_API() { return result; }); RemoteCall::exportAs("GMLIB_API", "getAllScoreboardFakePlayers", []() -> std::vector { - auto names = GMLIB_Scoreboard::getInstance()->getAllFakePlayers(); + auto names = world::Scoreboard::getInstance()->getAllFakePlayers(); std::vector result; for (auto& name : names) { result.push_back(name); @@ -474,7 +479,7 @@ void Export_Compatibility_API() { return result; }); RemoteCall::exportAs("GMLIB_API", "getAllScoreboardEntities", []() -> std::vector { - auto uniqueIds = GMLIB_Scoreboard::getInstance()->getAllEntities(); + auto uniqueIds = world::Scoreboard::getInstance()->getAllEntities(); std::vector result; for (auto& uniqueId : uniqueIds) { result.push_back(std::to_string(uniqueId.id)); @@ -486,21 +491,21 @@ void Export_Compatibility_API() { "getAllTrackedTargets", []() -> std::vector> { std::vector> result; - auto uuids = GMLIB_Scoreboard::getInstance()->getAllPlayerUuids(); + auto uuids = world::Scoreboard::getInstance()->getAllPlayerUuids(); for (auto& uuid : uuids) { std::unordered_map data; data["Type"] = "Player"; data["Uuid"] = uuid.asString(); result.push_back(data); } - auto names = GMLIB_Scoreboard::getInstance()->getAllFakePlayers(); + auto names = world::Scoreboard::getInstance()->getAllFakePlayers(); for (auto& name : names) { std::unordered_map data; data["Type"] = "FakePlayer"; data["Name"] = name; result.push_back(data); } - auto uniqueIds = GMLIB_Scoreboard::getInstance()->getAllEntities(); + auto uniqueIds = world::Scoreboard::getInstance()->getAllEntities(); for (auto& uniqueId : uniqueIds) { std::unordered_map data; data["Type"] = "Entity"; @@ -510,38 +515,38 @@ void Export_Compatibility_API() { return result; } ); - RemoteCall::exportAs("GMLIB_API", "getPlayerFromUuid", [](std::string const& uuid) -> Player* { + RemoteCall::exportAs("GMLIB_API", "getPlayerFromUuid", [](std::string const& uuid) -> ::Player* { return ll::service::getLevel()->getPlayer(mce::UUID::fromString(uuid)); }); - RemoteCall::exportAs("GMLIB_API", "getPlayerFromUniqueId", [](std::string const& uniqueId) -> Actor* { + RemoteCall::exportAs("GMLIB_API", "getPlayerFromUniqueId", [](std::string const& uniqueId) -> ::Actor* { auto auid = parseScriptUniqueID(uniqueId); return ll::service::getLevel()->getPlayer(auid); }); - RemoteCall::exportAs("GMLIB_API", "getEntityFromUniqueId", [](std::string const& uniqueId) -> Actor* { + RemoteCall::exportAs("GMLIB_API", "getEntityFromUniqueId", [](std::string const& uniqueId) -> ::Actor* { auto auid = parseScriptUniqueID(uniqueId); return ll::service::getLevel()->fetchEntity(auid); }); RemoteCall::exportAs("GMLIB_API", "getWorldSpawn", []() -> std::pair { - return {GMLIB_Level::getInstance()->getWorldSpawn(), 0}; + return {world::Level::getInstance()->getWorldSpawn(), 0}; }); RemoteCall::exportAs("GMLIB_API", "setWorldSpawn", [](std::pair pos) -> bool { if (pos.second != 0) { return false; } - GMLIB_Level::getInstance()->setWorldSpawn(pos.first); + world::Level::getInstance()->setWorldSpawn(pos.first); return true; }); - RemoteCall::exportAs("GMLIB_API", "getPlayerSpawnPoint", [](Player* pl) -> std::pair { - auto player = (GMLIB_Player*)pl; + RemoteCall::exportAs("GMLIB_API", "getPlayerSpawnPoint", [](::Player* pl) -> std::pair { + auto player = (world::Player*)pl; auto res = player->getSpawnPoint(); return {res.first, res.second}; }); - RemoteCall::exportAs("GMLIB_API", "setPlayerSpawnPoint", [](Player* pl, std::pair pos) -> void { - auto player = (GMLIB_Player*)pl; + RemoteCall::exportAs("GMLIB_API", "setPlayerSpawnPoint", [](::Player* pl, std::pair pos) -> void { + auto player = (world::Player*)pl; player->setSpawnPoint(pos.first, pos.second); }); - RemoteCall::exportAs("GMLIB_API", "clearPlayerSpawnPoint", [](Player* pl) -> void { - auto player = (GMLIB_Player*)pl; + RemoteCall::exportAs("GMLIB_API", "clearPlayerSpawnPoint", [](::Player* pl) -> void { + auto player = (world::Player*)pl; player->clearSpawnPoint(); }); RemoteCall::exportAs( @@ -608,18 +613,18 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "getBlockTranslateKey", [](Block const* block) -> std::string { return block->buildDescriptionId(); }); - RemoteCall::exportAs("GMLIB_API", "getItemTranslateKey", [](ItemStack* item) -> std::string { + RemoteCall::exportAs("GMLIB_API", "getItemTranslateKey", [](::ItemStack* item) -> std::string { return item->getDescriptionId(); }); - RemoteCall::exportAs("GMLIB_API", "getEntityTranslateKey", [](Actor* entity) -> std::string { + RemoteCall::exportAs("GMLIB_API", "getEntityTranslateKey", [](::Actor* entity) -> std::string { return entity->getEntityLocNameString(); }); RemoteCall::exportAs( "GMLIB_API", "readNbtFromFile", - [](std::string const& path, bool isBinary) -> std::unique_ptr { - if (auto nbt = GMLIB_CompoundTag::readFromFile(path, isBinary)) { - return std::make_unique(nbt.value()); + [](std::string const& path, bool isBinary) -> std::unique_ptr<::CompoundTag> { + if (auto nbt = world::CompoundTag::readFromFile(path, isBinary)) { + return std::make_unique<::CompoundTag>(nbt.value()); } return nullptr; } @@ -627,33 +632,33 @@ void Export_Compatibility_API() { RemoteCall::exportAs( "GMLIB_API", "saveNbtToFile", - [](std::string const& path, CompoundTag* nbt, bool isBinary) -> bool { - return GMLIB_CompoundTag::saveToFile(path, *nbt, isBinary); + [](std::string const& path, ::CompoundTag* nbt, bool isBinary) -> bool { + return world::CompoundTag::saveToFile(path, *nbt, isBinary); } ); RemoteCall::exportAs("GMLIB_API", "getBlockDestroySpeed", [](Block const* block) -> float { return block->getDestroySpeed(); }); - RemoteCall::exportAs("GMLIB_API", "getDestroyBlockSpeed", [](ItemStack const* item, Block const* block) -> float { + RemoteCall::exportAs("GMLIB_API", "getDestroyBlockSpeed", [](::ItemStack const* item, Block const* block) -> float { return item->getDestroySpeed(*block); }); RemoteCall::exportAs( "GMLIB_API", "playerDestroyBlock", - [](Block const* block, std::pair pos, Player* player) -> void { + [](Block const* block, std::pair pos, ::Player* player) -> void { return block->playerDestroy(*player, pos.first); } ); - RemoteCall::exportAs("GMLIB_API", "itemCanDestroyBlock", [](ItemStack const* item, Block const* block) -> bool { + RemoteCall::exportAs("GMLIB_API", "itemCanDestroyBlock", [](::ItemStack const* item, Block const* block) -> bool { return item->canDestroy(block); }); - RemoteCall::exportAs("GMLIB_API", "itemCanDestroyInCreative", [](ItemStack const* item) -> bool { + RemoteCall::exportAs("GMLIB_API", "itemCanDestroyInCreative", [](::ItemStack const* item) -> bool { if (auto itemDef = item->getItem()) { return itemDef->canDestroyInCreative(); } return false; }); - RemoteCall::exportAs("GMLIB_API", "itemCanDestroySpecial", [](ItemStack const* item, Block const* block) -> bool { + RemoteCall::exportAs("GMLIB_API", "itemCanDestroySpecial", [](::ItemStack const* item, Block const* block) -> bool { return item->canDestroySpecial(*block); }); RemoteCall::exportAs("GMLIB_API", "blockCanDropWithAnyTool", [](Block const* block) -> bool { @@ -665,14 +670,14 @@ void Export_Compatibility_API() { RemoteCall::exportAs( "GMLIB_API", "blockPlayerWillDestroy", - [](Block const* block, Player* player, std::pair pos) -> bool { + [](Block const* block, ::Player* player, std::pair pos) -> bool { return block->playerWillDestroy(*player, pos.first); } ); - RemoteCall::exportAs("GMLIB_API", "playerAttack", [](Player* player, Actor* entity) -> bool { + RemoteCall::exportAs("GMLIB_API", "playerAttack", [](::Player* player, ::Actor* entity) -> bool { return player->attack(*entity, ActorDamageCause::EntityAttack); }); - RemoteCall::exportAs("GMLIB_API", "playerPullInEntity", [](Player* player, Actor* entity) -> bool { + RemoteCall::exportAs("GMLIB_API", "playerPullInEntity", [](::Player* player, ::Actor* entity) -> bool { return player->pullInEntity(*entity); }); RemoteCall::exportAs("GMLIB_API", "getBlockTranslateKeyFromName", [](std::string const& blockName) -> std::string { @@ -721,7 +726,7 @@ void Export_Compatibility_API() { return result; } ); - RemoteCall::exportAs("GMLIB_API", "getLegalEnchants", [](ItemStack const* item) -> std::vector { + RemoteCall::exportAs("GMLIB_API", "getLegalEnchants", [](::ItemStack const* item) -> std::vector { std::vector enchants = EnchantUtils::getLegalEnchants(item->getItem()); std::vector result; for (auto& enchant : enchants) { @@ -738,30 +743,34 @@ void Export_Compatibility_API() { RemoteCall::exportAs( "GMLIB_API", "applyEnchant", - [](ItemStack const* item, std::string const& typeName, int level, bool allowNonVanilla) -> bool { + [](::ItemStack const* item, std::string const& typeName, int level, bool allowNonVanilla) -> bool { return EnchantUtils::applyEnchant( - *(const_cast(item)), + *(const_cast<::ItemStack*>(item)), Enchant::getEnchantTypeFromName(HashedString(typeName)), level, allowNonVanilla ); } ); - RemoteCall::exportAs("GMLIB_API", "removeEnchants", [](ItemStack const* item) -> void { - EnchantUtils::removeEnchants((ItemStack&)*item); + RemoteCall::exportAs("GMLIB_API", "removeEnchants", [](::ItemStack const* item) -> void { + EnchantUtils::removeEnchants((::ItemStack&)*item); }); - RemoteCall::exportAs("GMLIB_API", "hasEnchant", [](ItemStack const* item, std::string const& typeName) -> bool { + RemoteCall::exportAs("GMLIB_API", "hasEnchant", [](::ItemStack const* item, std::string const& typeName) -> bool { return EnchantUtils::hasEnchant( Enchant::getEnchantTypeFromName(HashedString(typeName)), - *(const_cast(item)) - ); - }); - RemoteCall::exportAs("GMLIB_API", "getEnchantLevel", [](ItemStack const* item, std::string const& typeName) -> int { - return EnchantUtils::getEnchantLevel( - Enchant::getEnchantTypeFromName(HashedString(typeName)), - *(const_cast(item)) + *(const_cast<::ItemStack*>(item)) ); }); + RemoteCall::exportAs( + "GMLIB_API", + "getEnchantLevel", + [](::ItemStack const* item, std::string const& typeName) -> int { + return EnchantUtils::getEnchantLevel( + Enchant::getEnchantTypeFromName(HashedString(typeName)), + *(const_cast<::ItemStack*>(item)) + ); + } + ); RemoteCall::exportAs( "GMLIB_API", "getEnchantNameAndLevel", @@ -772,44 +781,44 @@ void Export_Compatibility_API() { RemoteCall::exportAs( "GMLIB_API", "dropPlayerItem", - [](Player* player, ItemStack const* item, bool randomly) -> bool { return player->drop(*item, randomly); } + [](::Player* player, ::ItemStack const* item, bool randomly) -> bool { return player->drop(*item, randomly); } ); - RemoteCall::exportAs("GMLIB_API", "getPlayerRuntimeId", [](Player* player) -> uint64 { + RemoteCall::exportAs("GMLIB_API", "getPlayerRuntimeId", [](::Player* player) -> uint64 { return player->getRuntimeID().id; }); - RemoteCall::exportAs("GMLIB_API", "getEntityRuntimeId", [](Actor* entity) -> uint64 { + RemoteCall::exportAs("GMLIB_API", "getEntityRuntimeId", [](::Actor* entity) -> uint64 { return entity->getRuntimeID().id; }); - RemoteCall::exportAs("GMLIB_API", "getEntityNameTag", [](Actor* entity) -> std::string { + RemoteCall::exportAs("GMLIB_API", "getEntityNameTag", [](::Actor* entity) -> std::string { return entity->getNameTag(); }); - RemoteCall::exportAs("GMLIB_API", "ItemisUnbreakable", [](ItemStack const* item) -> bool { - return ((GMLIB_ItemStack*)item)->isUnbreakable(); + RemoteCall::exportAs("GMLIB_API", "ItemisUnbreakable", [](::ItemStack const* item) -> bool { + return ((world::ItemStack*)item)->isUnbreakable(); }); - RemoteCall::exportAs("GMLIB_API", "setItemUnbreakable", [](ItemStack const* item, bool value) -> void { - ((GMLIB_ItemStack*)item)->setUnbreakable(value); + RemoteCall::exportAs("GMLIB_API", "setItemUnbreakable", [](::ItemStack const* item, bool value) -> void { + ((world::ItemStack*)item)->setUnbreakable(value); }); - RemoteCall::exportAs("GMLIB_API", "getItemShouldKeepOnDeath", [](ItemStack const* item) -> bool { - return ((GMLIB_ItemStack*)item)->getShouldKeepOnDeath(); + RemoteCall::exportAs("GMLIB_API", "getItemShouldKeepOnDeath", [](::ItemStack const* item) -> bool { + return ((world::ItemStack*)item)->getShouldKeepOnDeath(); }); - RemoteCall::exportAs("GMLIB_API", "setItemShouldKeepOnDeath", [](ItemStack const* item, bool value) -> void { - ((GMLIB_ItemStack*)item)->setShouldKeepOnDeath(value); + RemoteCall::exportAs("GMLIB_API", "setItemShouldKeepOnDeath", [](::ItemStack const* item, bool value) -> void { + ((world::ItemStack*)item)->setShouldKeepOnDeath(value); }); - RemoteCall::exportAs("GMLIB_API", "getItemLockMode", [](ItemStack const* item) -> int { - return (int)((GMLIB_ItemStack*)item)->getItemLockMode(); + RemoteCall::exportAs("GMLIB_API", "getItemLockMode", [](::ItemStack const* item) -> int { + return (int)((world::ItemStack*)item)->getItemLockMode(); }); - RemoteCall::exportAs("GMLIB_API", "setItemLockMode", [](ItemStack const* item, int value) -> void { - ((GMLIB_ItemStack*)item)->setItemLockMode((ItemLockMode)value); + RemoteCall::exportAs("GMLIB_API", "setItemLockMode", [](::ItemStack const* item, int value) -> void { + ((world::ItemStack*)item)->setItemLockMode((::ItemLockMode)value); }); - RemoteCall::exportAs("GMLIB_API", "getItemRepairCost", [](ItemStack const* item) -> int { + RemoteCall::exportAs("GMLIB_API", "getItemRepairCost", [](::ItemStack const* item) -> int { return item->getBaseRepairCost(); }); - RemoteCall::exportAs("GMLIB_API", "setItemRepairCost", [](ItemStack const* item, int cost) -> void { - (*(const_cast(item))).setRepairCost(cost); + RemoteCall::exportAs("GMLIB_API", "setItemRepairCost", [](::ItemStack const* item, int cost) -> void { + (*(const_cast<::ItemStack*>(item))).setRepairCost(cost); }); - RemoteCall::exportAs("GMLIB_API", "getItemCanDestroy", [](ItemStack const* item) -> std::vector { + RemoteCall::exportAs("GMLIB_API", "getItemCanDestroy", [](::ItemStack const* item) -> std::vector { std::vector result = {}; - for (auto& block : ((GMLIB_ItemStack*)item)->getCanDestroy()) { + for (auto& block : ((world::ItemStack*)item)->getCanDestroy()) { result.push_back(block->getTypeName()); } return result; @@ -817,13 +826,13 @@ void Export_Compatibility_API() { RemoteCall::exportAs( "GMLIB_API", "setItemCanDestroy", - [](ItemStack const* item, std::vector blocks) -> void { - ((GMLIB_ItemStack*)item)->setCanDestroy(blocks); + [](::ItemStack const* item, std::vector blocks) -> void { + ((world::ItemStack*)item)->setCanDestroy(blocks); } ); - RemoteCall::exportAs("GMLIB_API", "getItemCanPlaceOn", [](ItemStack const* item) -> std::vector { + RemoteCall::exportAs("GMLIB_API", "getItemCanPlaceOn", [](::ItemStack const* item) -> std::vector { std::vector result = {}; - for (auto& block : ((GMLIB_ItemStack*)item)->getCanPlaceOn()) { + for (auto& block : ((world::ItemStack*)item)->getCanPlaceOn()) { result.push_back(block->getTypeName()); } return result; @@ -831,47 +840,51 @@ void Export_Compatibility_API() { RemoteCall::exportAs( "GMLIB_API", "setItemCanPlaceOn", - [](ItemStack const* item, std::vector blocks) -> void { - ((GMLIB_ItemStack*)item)->setCanPlaceOn(blocks); + [](::ItemStack const* item, std::vector blocks) -> void { + ((world::ItemStack*)item)->setCanPlaceOn(blocks); } ); - RemoteCall::exportAs("GMLIB_API", "getPlayerHungry", [](Player* player) -> float { - return player->getMutableAttribute(Player::HUNGER)->getCurrentValue(); + RemoteCall::exportAs("GMLIB_API", "getPlayerHungry", [](::Player* player) -> float { + return player->getMutableAttribute(::Player::HUNGER)->getCurrentValue(); }); - RemoteCall::exportAs("GMLIB_API", "getPlayerArmorCoverPercentage", [](Player* player) -> float { + RemoteCall::exportAs("GMLIB_API", "getPlayerArmorCoverPercentage", [](::Player* player) -> float { return player->getArmorCoverPercentage(); }); - RemoteCall::exportAs("GMLIB_API", "getPlayerArmorValue", [](Player* player) -> int { + RemoteCall::exportAs("GMLIB_API", "getPlayerArmorValue", [](::Player* player) -> int { return player->getArmorValue(); }); - RemoteCall::exportAs("GMLIB_API", "getEntityOwnerUniqueId", [](Actor* entity) -> int64 { + RemoteCall::exportAs("GMLIB_API", "getEntityOwnerUniqueId", [](::Actor* entity) -> int64 { return entity->getOwnerId().id; }); - RemoteCall::exportAs("GMLIB_API", "getItemCategoryName", [](ItemStack const* item) -> std::string { + RemoteCall::exportAs("GMLIB_API", "getItemCategoryName", [](::ItemStack const* item) -> std::string { return item->getCategoryName(); }); - RemoteCall::exportAs("GMLIB_API", "getItemCustomName", [](ItemStack const* item) -> std::string { + RemoteCall::exportAs("GMLIB_API", "getItemCustomName", [](::ItemStack const* item) -> std::string { return item->getCustomName(); }); - RemoteCall::exportAs("GMLIB_API", "getItemEffecName", [](ItemStack const* item) -> std::string { + RemoteCall::exportAs("GMLIB_API", "getItemEffecName", [](::ItemStack const* item) -> std::string { return item->getEffectName(); }); - RemoteCall::exportAs("GMLIB_API", "itemIsFood", [](ItemStack const* item) -> bool { + RemoteCall::exportAs("GMLIB_API", "itemIsFood", [](::ItemStack const* item) -> bool { if (auto itemDef = item->getItem()) { return itemDef->isFood(); } return false; }); - RemoteCall::exportAs("GMLIB_API", "setPlayerUIItem", [](Player* player, int slot, ItemStack const* item) -> void { - player->setPlayerUIItem((PlayerUISlot)slot, *item); - }); - RemoteCall::exportAs("GMLIB_API", "getPlayerUIItem", [](Player* player, int slot) -> ItemStack* { - return const_cast(&player->getPlayerUIItem((PlayerUISlot)slot)); + RemoteCall::exportAs( + "GMLIB_API", + "setPlayerUIItem", + [](::Player* player, int slot, ::ItemStack const* item) -> void { + player->setPlayerUIItem((PlayerUISlot)slot, *item); + } + ); + RemoteCall::exportAs("GMLIB_API", "getPlayerUIItem", [](::Player* player, int slot) -> ::ItemStack* { + return const_cast<::ItemStack*>(&player->getPlayerUIItem((PlayerUISlot)slot)); }); RemoteCall::exportAs( "GMLIB_API", "sendInventorySlotPacket", - [](Player* player, int containerId, int slot, ItemStack const* item) -> void { + [](::Player* player, int containerId, int slot, ::ItemStack const* item) -> void { InventorySlotPacket((ContainerID)containerId, slot, *item).sendTo(*player); } ); @@ -880,60 +893,62 @@ void Export_Compatibility_API() { }); RemoteCall::exportAs("GMLIB_API", "hasPlayerNbt", [](std::string const& uuid) -> bool { auto uid = mce::UUID::fromString(uuid); - return GMLIB_Player::getPlayerNbt(uid) ? true : false; + return world::Player::getPlayerNbt(uid) ? true : false; }); - RemoteCall::exportAs("GMLIB_API", "getItemMaxCount", [](ItemStack const* item) -> int { + RemoteCall::exportAs("GMLIB_API", "getItemMaxCount", [](::ItemStack const* item) -> int { return item->getMaxStackSize(); }); - RemoteCall::exportAs("GMLIB_API", "entityHasFamily", [](Actor* entity, std::string const& family) -> bool { + RemoteCall::exportAs("GMLIB_API", "entityHasFamily", [](::Actor* entity, std::string const& family) -> bool { return entity->hasFamily(HashedString(family)); }); - RemoteCall::exportAs("GMLIB_API", "getPlayerDestroyBlockProgress", [](Player* player, Block const* block) -> float { - return player->getDestroyProgress(*block); - }); - RemoteCall::exportAs("GMLIB_API", "getEntityEffectVisible", [](Actor* entity, int effectId) -> bool { + RemoteCall::exportAs( + "GMLIB_API", + "getPlayerDestroyBlockProgress", + [](::Player* player, Block const* block) -> float { return player->getDestroyProgress(*block); } + ); + RemoteCall::exportAs("GMLIB_API", "getEntityEffectVisible", [](::Actor* entity, int effectId) -> bool { if (auto effect = entity->getEffect(effectId)) { return effect->mEffectVisible; } return 0; }); - RemoteCall::exportAs("GMLIB_API", "getEntityEffectDuration", [](Actor* entity, int effectId) -> int { + RemoteCall::exportAs("GMLIB_API", "getEntityEffectDuration", [](::Actor* entity, int effectId) -> int { if (auto effect = entity->getEffect(effectId)) { return effect->mDuration; } return 0; }); - RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationEasy", [](Actor* entity, int effectId) -> int { + RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationEasy", [](::Actor* entity, int effectId) -> int { if (auto effect = entity->getEffect(effectId)) { return effect->mDurationEasy; } return 0; }); - RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationHard", [](Actor* entity, int effectId) -> int { + RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationHard", [](::Actor* entity, int effectId) -> int { if (auto effect = entity->getEffect(effectId)) { return effect->mDurationHard; } return 0; }); - RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationNormal", [](Actor* entity, int effectId) -> int { + RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationNormal", [](::Actor* entity, int effectId) -> int { if (auto effect = entity->getEffect(effectId)) { return effect->mDurationNormal; } return 0; }); - RemoteCall::exportAs("GMLIB_API", "getEntityEffectAmplifier", [](Actor* entity, int effectId) -> int { + RemoteCall::exportAs("GMLIB_API", "getEntityEffectAmplifier", [](::Actor* entity, int effectId) -> int { if (auto effect = entity->getEffect(effectId)) { return effect->mAmplifier; } return 0; }); - RemoteCall::exportAs("GMLIB_API", "getEntityEffectAmbient", [](Actor* entity, int effectId) -> bool { + RemoteCall::exportAs("GMLIB_API", "getEntityEffectAmbient", [](::Actor* entity, int effectId) -> bool { if (auto effect = entity->getEffect(effectId)) { return effect->mAmbient; } return 0; }); - RemoteCall::exportAs("GMLIB_API", "entityHasEffect", [](Actor* entity, int effectId) -> int { + RemoteCall::exportAs("GMLIB_API", "entityHasEffect", [](::Actor* entity, int effectId) -> int { return entity->hasEffect(*MobEffect::getById(effectId)); }); RemoteCall::exportAs("GMLIB_API", "getGameDifficulty", []() -> int { @@ -961,8 +976,8 @@ void Export_Compatibility_API() { RemoteCall::exportAs( "GMLIB_API", "registerCustomShapelessRecipe", - [](std::string const& recipe_id, std::vector ingredients, ItemStack* result) -> void { - auto level = GMLIB_Level::getInstance(); + [](std::string const& recipe_id, std::vector ingredients, ::ItemStack* result) -> void { + auto level = world::Level::getInstance(); if (!level) { return; } @@ -973,7 +988,7 @@ void Export_Compatibility_API() { types.push_back(key); rt++; } - CustomRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, *result); + recipe::RecipeRegistry::registerShapelessCraftingTableRecipe(recipe_id, types, *result); } ); RemoteCall::exportAs( @@ -982,8 +997,8 @@ void Export_Compatibility_API() { [](std::string const& recipe_id, std::vector shape, std::vector ingredients, - ItemStack* result) -> void { - auto level = GMLIB_Level::getInstance(); + ::ItemStack* result) -> void { + auto level = world::Level::getInstance(); if (!level) { return; } @@ -994,7 +1009,7 @@ void Export_Compatibility_API() { types.push_back(key); rt++; } - CustomRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, *result); + recipe::RecipeRegistry::registerShapedCraftingTableRecipe(recipe_id, shape, types, *result); } ); } \ No newline at end of file diff --git a/src/Entry.cpp b/src/Entry.cpp index 9929e5f..1329b8d 100644 --- a/src/Entry.cpp +++ b/src/Entry.cpp @@ -3,7 +3,7 @@ ll::Logger logger(PLUGIN_NAME); -namespace GMLIB { +namespace gmlib { std::unique_ptr& LegacyRemoteCallApi::getInstance() { static std::unique_ptr instance; @@ -32,6 +32,6 @@ bool LegacyRemoteCallApi::enable() { return true; } bool LegacyRemoteCallApi::disable() { return true; } -} // namespace GMLIB +} // namespace gmlib LL_REGISTER_MOD(LegacyRemoteCallApi, LegacyRemoteCallApi::getInstance()); diff --git a/src/Entry.h b/src/Entry.h index 49821d5..0606144 100644 --- a/src/Entry.h +++ b/src/Entry.h @@ -2,7 +2,7 @@ #include #include -namespace GMLIB { +namespace gmlib { class LegacyRemoteCallApi { @@ -30,4 +30,4 @@ private: ll::mod::NativeMod& mSelf; }; -} // namespace GMLIB +} // namespace gmlib diff --git a/src/EventAPI.cpp b/src/EventAPI.cpp index c2b9570..6939a0f 100644 --- a/src/EventAPI.cpp +++ b/src/EventAPI.cpp @@ -1,4 +1,6 @@ #include "Global.h" +#include "ll/api/event/EventBus.h" +#include "mc/world/inventory/network/ItemStackRequestActionTransferBase.h" using namespace ll::hash_utils; class LegacyScriptEventManager { @@ -63,7 +65,7 @@ void Export_Event_API() { switch (doHash(eventName)) { case doHash("onClientLogin"): { REGISTER_EVENT_LISTEN( - Event::PacketEvent::ClientLoginAfterEvent, + gmlib::event::packet::ClientLoginAfterEvent, (std::string const& realName, std::string const& uuid, std::string const& serverXuid, @@ -74,7 +76,7 @@ void Export_Event_API() { } case doHash("onWeatherChange"): { REGISTER_EVENT_LISTEN( - Event::LevelEvent::WeatherUpdateBeforeEvent, + gmlib::event::level::WeatherUpdateBeforeEvent, (int lightningLevel, int rainLevel, int lightningLast, int rainLast), (ev.getLightningLevel(), ev.getRainLevel(), ev.getLightningLastTick(), ev.getRainingLastTick()), ev.cancel(), @@ -82,16 +84,16 @@ void Export_Event_API() { } case doHash("onMobPick"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::MobPickupItemBeforeEvent, - (Actor * mob, Actor * item), - (&ev.self(), (Actor*)&ev.getItemActor()), + gmlib::event::entity::MobPickupItemBeforeEvent, + (::Actor * mob, ::Actor * item), + (&ev.self(), (::Actor*)&ev.getItemActor()), ev.cancel(), ); } case doHash("onItemTrySpawn"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::ItemActorSpawnBeforeEvent, - (const ItemStack* item, std::pair position, int64 spawnerUniqueId), + gmlib::event::entity::ItemActorSpawnBeforeEvent, + (const ::ItemStack* item, std::pair position, int64 spawnerUniqueId), (&ev.getItem(), {ev.getPosition(), ev.getBlockSource().getDimensionId().id}, ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1), @@ -100,10 +102,10 @@ void Export_Event_API() { } case doHash("onItemSpawned"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::ItemActorSpawnAfterEvent, - (const ItemStack* item, Actor* itemActor, std::pair position, int64 spawnerUniqueId), + gmlib::event::entity::ItemActorSpawnAfterEvent, + (const ::ItemStack* item, ::Actor* itemActor, std::pair position, int64 spawnerUniqueId), (&ev.getItem(), - (Actor*)&ev.getItemActor(), + (::Actor*)&ev.getItemActor(), {ev.getPosition(), ev.getBlockSource().getDimensionId().id}, ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1), logger.error("Event \"onItemSpawned\" cannot be intercepted"), @@ -111,36 +113,36 @@ void Export_Event_API() { } case doHash("onEntityTryChangeDim"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::ActorChangeDimensionBeforeEvent, - (Actor * entity, int toDimId), + gmlib::event::entity::ActorChangeDimensionBeforeEvent, + (::Actor * entity, int toDimId), (&ev.self(), ev.getToDimensionId()), ev.cancel(), ); } case doHash("onLeaveBed"): { REGISTER_EVENT_LISTEN( - Event::PlayerEvent::PlayerStopSleepBeforeEvent, - (Player * pl), + gmlib::event::player::PlayerStopSleepBeforeEvent, + (::Player * pl), (&ev.self()), ev.cancel(), ); } case doHash("onDeathMessage"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::DeathMessageAfterEvent, - (std::string const& message, std::vector, Actor* dead), + gmlib::event::entity::DeathMessageAfterEvent, + (std::string const& message, std::vector, ::Actor* dead), (ev.getDeathMessage().first, ev.getDeathMessage().second, &ev.self()), logger.error("Event \"onDeathMessage\" cannot be intercepted"), ); } case doHash("onMobHurted"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::MobHurtAfterEvent, - (Actor * mob, Actor * source, float damage, int cause), + gmlib::event::entity::MobHurtAfterEvent, + (::Actor * mob, ::Actor * source, float damage, int cause), (&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()), logger.error("Event \"onMobHurted\" cannot be intercepted"), auto& damageSource = ev.getSource(); - Actor* source = nullptr; + ::Actor* source = nullptr; if (damageSource.isEntitySource()) { auto uniqueId = damageSource.getDamagingEntityUniqueID(); source = ll::service::getLevel()->fetchEntity(uniqueId); @@ -150,23 +152,23 @@ void Export_Event_API() { } case doHash("onEndermanTake"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::EndermanTakeBlockBeforeEvent, - (Actor * mob), + gmlib::event::entity::EndermanTakeBlockBeforeEvent, + (::Actor * mob), (&ev.self()), ev.cancel(), ); } case doHash("onEntityChangeDim"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::ActorChangeDimensionAfterEvent, - (Actor * mob, int fromDimId), + gmlib::event::entity::ActorChangeDimensionAfterEvent, + (::Actor * mob, int fromDimId), (&ev.self(), ev.getFromDimensionId()), logger.error("Event \"onEntityChangeDim\" cannot be intercepted"), ); } case doHash("onDragonRespawn"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::DragonRespawnBeforeEvent, + gmlib::event::entity::DragonRespawnBeforeEvent, (int64 enderDragonUniqueID), (ev.getEnderDragon().id), ev.cancel(), @@ -174,38 +176,38 @@ void Export_Event_API() { } case doHash("onProjectileTryCreate"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::ProjectileCreateBeforeEvent, - (Actor * mob, int64 uniqueId), + gmlib::event::entity::ProjectileCreateBeforeEvent, + (::Actor * mob, int64 uniqueId), (&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1), ev.cancel(), ); } case doHash("onProjectileCreate"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::ProjectileCreateAfterEvent, - (Actor * mob, int64 uniqueId), + gmlib::event::entity::ProjectileCreateAfterEvent, + (::Actor * mob, int64 uniqueId), (&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1), logger.error("Event \"onProjectileCreate\" cannot be intercepted"), ); } case doHash("onSpawnWanderingTrader"): { REGISTER_EVENT_LISTEN( - Event::EntityEvent::SpawnWanderingTraderBeforeEvent, + gmlib::event::entity::SpawnWanderingTraderBeforeEvent, (std::pair pos), ({ev.getPos(), ev.getRegion().getDimensionId()}), ev.cancel(), ); } case doHash("onHandleRequestAction"): { - REGISTER_EVENT_LISTEN(Event::PlayerEvent::HandleRequestActionBeforeEvent, - (Player * player, + REGISTER_EVENT_LISTEN(gmlib::event::player::HandleRequestActionBeforeEvent, + (::Player * player, std::string const& actionType, int count, std::string const& sourceContainerNetId, int sourceSlot, std::string const& destinationContainerNetId, int destinationSlot), - ((Player*)&ev.self(), + ((::Player*)&ev.self(), magic_enum::enum_name(requestAction->mActionType).data(), (int)requestAction->mAmount, magic_enum::enum_name(requestAction->mSrc.mOpenContainerNetId).data(), @@ -218,8 +220,8 @@ void Export_Event_API() { } case doHash("onSendContainerClosePacket"): { REGISTER_EVENT_LISTEN( - Event::PacketEvent::ContainerClosePacketSendAfterEvent, - (Player * player, int ContainerNetId), + event::packet::ContainerClosePacketSendAfterEvent, + (::Player * player, int ContainerNetId), (ev.getServerNetworkHandler() .getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId), (int)ev.getPacket().mContainerId), diff --git a/src/FormAPI.cpp b/src/FormAPI.cpp index 474516d..88477ba 100644 --- a/src/FormAPI.cpp +++ b/src/FormAPI.cpp @@ -1,8 +1,7 @@ #include "Global.h" +#include "gmlib/world/Player.h" -#include - -using namespace GMLIB::Server::Form; +using namespace gmlib::form; using namespace ll::hash_utils; class LegacyScriptFormManager { @@ -10,7 +9,7 @@ private: int64 mNextFormCallbackId = 0; int64 mNextFormId = 0; std::unordered_map> mNpcDialogueForms; - std::unordered_map> mChestForms; + // std::unordered_map> mChestForms; public: std::string getNextFormCallbackId() { @@ -45,6 +44,30 @@ public: return {}; } + /* + int64 createChestForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) { + auto formId = LegacyScriptFormManager::getInstance().getNextFormId(); + auto formPtr = std::make_unique(npcName, sceneName, dialogue); + mChestForms[formId] = std::move(formPtr); + return formId; + } + + bool destroyChestForm(int64 formId) { + if (mChestForms.contains(formId)) { + mChestForms.erase(formId); + return true; + } + return false; + } + + optional_ref getChestForm(int64 formId) { + if (mChestForms.contains(formId)) { + return mChestForms[formId].get(); + } + return {}; + } + + */ public: static LegacyScriptFormManager& getInstance() { static std::unique_ptr instance; @@ -56,10 +79,10 @@ public: }; #define PLAYER_DETECROR \ - [detectorId, result](Player& pl) -> bool { \ + [detectorId, result](::Player& pl) -> bool { \ try { \ if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", detectorId)) { \ - auto const& detector = RemoteCall::importAs("GMLIB_FORM_CALLBACK", detectorId); \ + auto const& detector = RemoteCall::importAs("GMLIB_FORM_CALLBACK", detectorId); \ return detector(&pl); \ } else { \ ServerSettingForm::removeElement(result); \ @@ -69,11 +92,11 @@ public: } #define CALLBACK_TYPE_STRING \ - [callbackId, result](Player& pl, std::string const& data) { \ + [callbackId, result](::Player& pl, std::string const& data) { \ try { \ if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \ auto const& callback = \ - RemoteCall::importAs("GMLIB_FORM_CALLBACK", callbackId); \ + RemoteCall::importAs("GMLIB_FORM_CALLBACK", callbackId); \ callback(&pl, data); \ } else { \ ServerSettingForm::removeElement(result); \ @@ -82,10 +105,10 @@ public: } #define CALLBACK_TYPE_BOOL \ - [callbackId, result](Player& pl, bool data) { \ + [callbackId, result](::Player& pl, bool data) { \ try { \ if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \ - auto const& callback = RemoteCall::importAs("GMLIB_FORM_CALLBACK", callbackId); \ + auto const& callback = RemoteCall::importAs("GMLIB_FORM_CALLBACK", callbackId); \ callback(&pl, data); \ } else { \ ServerSettingForm::removeElement(result); \ @@ -94,10 +117,11 @@ public: } #define CALLBACK_TYPE_DOUBLE \ - [callbackId, result](Player& pl, double data) { \ + [callbackId, result](::Player& pl, double data) { \ try { \ if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \ - auto const& callback = RemoteCall::importAs("GMLIB_FORM_CALLBACK", callbackId); \ + auto const& callback = \ + RemoteCall::importAs("GMLIB_FORM_CALLBACK", callbackId); \ callback(&pl, data); \ } else { \ ServerSettingForm::removeElement(result); \ @@ -107,10 +131,11 @@ public: #define CALLBACK_TYPE_LONG \ - [callbackId, result](Player& pl, int64 data) { \ + [callbackId, result](::Player& pl, int64 data) { \ try { \ if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \ - auto const& callback = RemoteCall::importAs("GMLIB_FORM_CALLBACK", callbackId); \ + auto const& callback = \ + RemoteCall::importAs("GMLIB_FORM_CALLBACK", callbackId); \ callback(&pl, data); \ } else { \ ServerSettingForm::removeElement(result); \ @@ -118,6 +143,16 @@ public: } catch (...) {} \ } +#define CALLBACK_TYPE_NORMAL \ + [callbackId](::Player& pl) { \ + try { \ + if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \ + auto const& callback = RemoteCall::importAs("GMLIB_FORM_CALLBACK", callbackId); \ + callback(&pl); \ + } \ + } catch (...) {} \ + } + void Export_Form_API() { //////////////////////////////// Form Manager ///////////////////////////////// @@ -273,30 +308,28 @@ void Export_Form_API() { RemoteCall::exportAs("GMLIB_NpcDialogueForm", "destroyForm", [](int64 formId) -> bool { return LegacyScriptFormManager::getInstance().destroyNpcDialogueForm(formId); }); - RemoteCall::exportAs("GMLIB_NpcDialogueForm", "addButton", [](int64 formId, std::string const& button) -> int { - if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) { - return formPtr->addButton(button); - } - return -1; - }); RemoteCall::exportAs( "GMLIB_NpcDialogueForm", - "sendTo", - [](int64 formId, Player* pl, std::string const& callbackId) -> void { + "addButton", + [](int64 formId, std::string const& button, std::string const& callbackId) -> void { if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) { - formPtr->sendTo(*pl, [callbackId](Player& pl, int index, NpcRequestPacket::RequestType type) -> void { - try { - if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { - auto const& callback = RemoteCall::importAs( - "GMLIB_FORM_CALLBACK", - callbackId - ); - callback(&pl, index, (int)type); - } - } catch (...) {} - }); + formPtr->addButton(button, CALLBACK_TYPE_NORMAL); } } ); + RemoteCall::exportAs( + "GMLIB_NpcDialogueForm", + "onPlayerClose", + [](int64 formId, std::string const& callbackId) -> void { + if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) { + formPtr->onPlayerClose(CALLBACK_TYPE_NORMAL); + } + } + ); + RemoteCall::exportAs("GMLIB_NpcDialogueForm", "sendTo", [](int64 formId, ::Player* pl) -> void { + if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) { + formPtr->sendTo(*pl); + } + }); ////////////////////////////// ChestForm ////////////////////////////// } \ No newline at end of file diff --git a/src/Global.h b/src/Global.h index 4879418..07da7b7 100644 --- a/src/Global.h +++ b/src/Global.h @@ -1,17 +1,17 @@ #pragma once -#include - #include +#include -using namespace GMLIB; -using namespace Server; -using namespace Mod; +using namespace gmlib; +using namespace world; +using namespace mod; +using namespace tools; #define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA") #define LIB_VERSION_MAJOR 0 #define LIB_VERSION_MINOR 13 -#define LIB_VERSION_PATCH 3 +#define LIB_VERSION_PATCH 4 #define LIB_VERSION Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH) diff --git a/src/LegacyModApi.cpp b/src/LegacyModApi.cpp index dc36bee..0fefa0d 100644 --- a/src/LegacyModApi.cpp +++ b/src/LegacyModApi.cpp @@ -22,7 +22,7 @@ void Export_Legacy_GMLib_ModAPI() { std::string const& result, int count, std::string const& unlock) -> void { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return; } @@ -33,7 +33,7 @@ void Export_Legacy_GMLib_ModAPI() { } auto res = RecipeIngredient(result, 0, count); auto unl = makeRecipeUnlockingKey(unlock); - JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl); + recipe::JsonRecipeRegistry::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl); } ); RemoteCall::exportAs( @@ -45,7 +45,7 @@ void Export_Legacy_GMLib_ModAPI() { std::string const& result, int count, std::string const& unlock) -> void { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return; } @@ -56,7 +56,7 @@ void Export_Legacy_GMLib_ModAPI() { } auto res = RecipeIngredient(result, 0, count); auto unl = makeRecipeUnlockingKey(unlock); - JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl); + recipe::JsonRecipeRegistry::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl); } ); RemoteCall::exportAs( @@ -66,13 +66,13 @@ void Export_Legacy_GMLib_ModAPI() { std::string const& input, std::string const& output, std::vector tags) -> void { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return; } auto inp = RecipeIngredient(input, 0, 1); auto outp = RecipeIngredient(output, 0, 1); - JsonRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags); + recipe::JsonRecipeRegistry::registerFurnaceRecipe(recipe_id, inp, outp, tags); } ); RemoteCall::exportAs( @@ -80,12 +80,12 @@ void Export_Legacy_GMLib_ModAPI() { "registerBrewingMixRecipe", [](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent ) -> void { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return; } auto rea = RecipeIngredient(reagent, 0, 1); - JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea); + recipe::JsonRecipeRegistry::registerBrewingMixRecipe(recipe_id, input, output, rea); } ); RemoteCall::exportAs( @@ -93,14 +93,14 @@ void Export_Legacy_GMLib_ModAPI() { "registerBrewingContainerRecipe", [](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent ) -> void { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return; } auto inp = RecipeIngredient(input, 0, 1); auto outp = RecipeIngredient(output, 0, 1); auto rea = RecipeIngredient(reagent, 0, 1); - JsonRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea); + recipe::JsonRecipeRegistry::registerBrewingContainerRecipe(recipe_id, inp, outp, rea); } ); RemoteCall::exportAs( @@ -111,11 +111,11 @@ void Export_Legacy_GMLib_ModAPI() { std::string const& base, std::string const& addition, std::string const& result) -> void { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return; } - JsonRecipe::registerSmithingTransformRecipe(recipe_id, smithing_template, base, addition, result); + recipe::JsonRecipeRegistry::registerSmithingTransformRecipe(recipe_id, smithing_template, base, addition, result); } ); RemoteCall::exportAs( @@ -125,11 +125,11 @@ void Export_Legacy_GMLib_ModAPI() { std::string const& smithing_template, std::string const& base, std::string const& addition) -> void { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return; } - JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition); + recipe::JsonRecipeRegistry::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition); } ); RemoteCall::exportAs( @@ -141,13 +141,13 @@ void Export_Legacy_GMLib_ModAPI() { std::string const& output, int output_data, int output_count) -> void { - auto level = GMLIB_Level::getInstance(); + auto level = world::Level::getInstance(); if (!level) { return; } auto inp = RecipeIngredient(input, 0, 1); auto outp = RecipeIngredient(output, 0, 1); - JsonRecipe::registerStoneCutterRecipe(recipe_id, inp, outp); + recipe::JsonRecipeRegistry::registerStoneCutterRecipe(recipe_id, inp, outp); } ); // 错误方块清理 @@ -156,29 +156,29 @@ void Export_Legacy_GMLib_ModAPI() { }); // 实验性 RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void { - auto list = GMLIB_Level::getAllExperiments(); + auto list = world::Level::getAllExperiments(); std::unordered_set set(list.begin(), list.end()); if (set.contains((AllExperiments)experiment_id)) { - GMLIB_Level::addExperimentsRequire((AllExperiments)experiment_id); + world::Level::addExperimentsRequire((AllExperiments)experiment_id); } else { ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id); } }); RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void { - if (GMLIB_Level::getInstance()) { - auto list = GMLIB_Level::getAllExperiments(); + if (world::Level::getInstance()) { + auto list = world::Level::getAllExperiments(); std::unordered_set set(list.begin(), list.end()); if (set.contains((AllExperiments)experiment_id)) { - GMLIB_Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value); + world::Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value); } else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id); } }); RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool { - if (GMLIB_Level::getInstance()) { - auto list = GMLIB_Level::getAllExperiments(); + if (world::Level::getInstance()) { + auto list = world::Level::getAllExperiments(); std::unordered_set set(list.begin(), list.end()); if (set.contains((AllExperiments)experiment_id)) { - return GMLIB_Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id)); + return world::Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id)); } else { ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id); return false; diff --git a/src/LegacyServerApi.cpp b/src/LegacyServerApi.cpp index 2218d7e..060e52b 100644 --- a/src/LegacyServerApi.cpp +++ b/src/LegacyServerApi.cpp @@ -2,62 +2,64 @@ void Export_Legacy_GMLib_ServerAPI() { RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void { - GMLIB_Level::tryEnableEducationEdition(); + world::Level::tryEnableEducationEdition(); }); RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void { - GMLIB_Level::tryRegisterAbilityCommand(); + world::Level::tryRegisterAbilityCommand(); }); RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void { - GMLIB_Level::setForceAchievementsEnabled(); + world::Level::setForceAchievementsEnabled(); }); - RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { GMLIB_Level::trustAllSkins(); }); + RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { world::Level::trustAllSkins(); }); RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void { - GMLIB_Level::requireServerResourcePackAndAllowClientResourcePack(); + world::Level::requireServerResourcePackAndAllowClientResourcePack(); }); RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string { - if (auto level = GMLIB_Level::getInstance()) { + if (auto level = world::Level::getInstance()) { return level->getLevelName(); } return {}; }); RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string const& name) -> void { - if (auto level = GMLIB_Level::getInstance()) { + if (auto level = world::Level::getInstance()) { level->setLevelName(name); } }); RemoteCall::exportAs("GMLib_ServerAPI", "getLevelSeed", []() -> std::string { - if (auto level = GMLIB_Level::getInstance()) { + if (auto level = world::Level::getInstance()) { return std::to_string(level->getSeed()); } return {}; }); RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void { - return GMLIB_Level::setFakeSeed(seed); + return world::Level::setFakeSeed(seed); }); RemoteCall::exportAs( "GMLib_ServerAPI", "spawnEntity", - [](std::pair pos, std::string const& name) -> Actor* { - return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name).as_ptr(); + [](std::pair pos, std::string const& name) -> ::Actor* { + return world::Spawner::spawnEntity(pos.first, pos.second, name).as_ptr(); } ); RemoteCall::exportAs( "GMLib_ServerAPI", "shootProjectile", - [](Actor* owner, std::string const& name, float speed, float offset) -> Actor* { - auto ac = (GMLIB_Actor*)owner; + [](::Actor* owner, std::string const& name, float speed, float offset) -> ::Actor* { + auto ac = (world::Actor*)owner; return ac->shootProjectile(name, speed, offset).as_ptr(); } ); RemoteCall::exportAs( "GMLib_ServerAPI", "throwEntity", - [](Actor* owner, Actor* actor, float speed, float offset) -> bool { - auto ac = (GMLIB_Actor*)owner; + [](::Actor* owner, ::Actor* actor, float speed, float offset) -> bool { + auto ac = (world::Actor*)owner; return ac->throwEntity(*actor, speed, offset); } ); - RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](Player* player) -> Actor* { return (Actor*)player; }); + RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](::Player* player) -> ::Actor* { + return (::Actor*)player; + }); RemoteCall::exportAs( "GMLib_ServerAPI", "addFakeList", @@ -72,7 +74,7 @@ void Export_Legacy_GMLib_ServerAPI() { return FakeList::removeAllFakeLists(); }); RemoteCall::exportAs("GMLib_ServerAPI", "getMaxPlayers", []() -> int { - if (auto level = GMLIB_Level::getInstance()) { + if (auto level = world::Level::getInstance()) { return level->getMaxPlayerCount(); } return {}; diff --git a/src/PlaceholderApi.cpp b/src/PlaceholderApi.cpp index a7ca003..69a487b 100644 --- a/src/PlaceholderApi.cpp +++ b/src/PlaceholderApi.cpp @@ -15,7 +15,7 @@ bool isParameters(std::string const& str) { std::string GetValue(std::string const& from) { return PlaceholderAPI::getValue(from); } -std::string GetValueWithPlayer(std::string const& key, Player* player) { return PlaceholderAPI::getValue(key, player); } +std::string GetValueWithPlayer(std::string const& key, ::Player* player) { return PlaceholderAPI::getValue(key, player); } bool registerPlayerPlaceholder( std::string const& PluginName, @@ -25,18 +25,18 @@ bool registerPlayerPlaceholder( if (RemoteCall::hasFunc(PluginName, FuncName)) { PlaceholderAPI::unregisterPlaceholder(PAPIName); if (isParameters(PAPIName)) { - auto Call = RemoteCall::importAs)>( + auto Call = RemoteCall::importAs)>( PluginName, FuncName ); PlaceholderAPI::registerPlayerPlaceholder( PAPIName, - [Call](Player* sp, std::unordered_map map) { return Call(sp, map); }, + [Call](::Player* sp, std::unordered_map map) { return Call(sp, map); }, PluginName ); } else { - auto Call = RemoteCall::importAs(PluginName, FuncName); - PlaceholderAPI::registerPlayerPlaceholder(PAPIName, [Call](Player* sp) { return Call(sp); }, PluginName); + auto Call = RemoteCall::importAs(PluginName, FuncName); + PlaceholderAPI::registerPlayerPlaceholder(PAPIName, [Call](::Player* sp) { return Call(sp); }, PluginName); } return true; } @@ -88,7 +88,7 @@ bool registerStaticPlaceholder( return false; } -std::string translateStringWithPlayer(std::string const& str, Player* pl) { +std::string translateStringWithPlayer(std::string const& str, ::Player* pl) { return PlaceholderAPI::translateString(str, pl); }