From 2ee28825741a3820caada1ea79069737bbb15d17 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:42:36 +0800 Subject: [PATCH 1/4] feat: disable action --- .github/workflows/build.yml | 27 ----------------- .github/workflows/release.yml | 56 ----------------------------------- 2 files changed, 83 deletions(-) delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 60e9a2c..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,27 +0,0 @@ -on: - pull_request: - push: - workflow_dispatch: - -jobs: - build: - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - - - uses: xmake-io/github-action-setup-xmake@v1 - - - run: | - xmake repo -u - - - run: | - xmake f -a x64 -m release -p windows -v -y - - - run: | - xmake -w -y - - - uses: actions/upload-artifact@v3 - with: - name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }} - path: | - bin/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 42bf5e2..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,56 +0,0 @@ -on: - release: - types: - - published - -jobs: - build: - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - - - uses: xmake-io/github-action-setup-xmake@v1 - - - run: | - xmake repo -u - - - run: | - xmake f -a x64 -m release -p windows -v -y - - - run: | - xmake -w -y - - - uses: actions/upload-artifact@v3 - with: - name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }} - path: | - bin/ - - upload-to-release: - needs: - - build - permissions: - contents: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: actions/download-artifact@v3 - with: - name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }} - path: release/ - - - run: | - cp LICENSE README.md release/ - - - name: Archive release - run: | - cd release - zip -r ../${{ github.event.repository.name }}-windows-x64.zip * - cd .. - - - uses: softprops/action-gh-release@v1 - with: - append_body: true - files: | - ${{ github.event.repository.name }}-windows-x64.zip From 0226f8bbbad318a064aff61fcbf094cf2122d781 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 8 Feb 2024 20:27:17 +0800 Subject: [PATCH 2/4] feat: add action --- .github/workflows/build.yml | 32 ++++++++++++++++++++ .github/workflows/release.yml | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a74f60b --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,32 @@ +on: + pull_request: + push: + workflow_dispatch: + +jobs: + build: + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + submodules: recursive + + - uses: actions/checkout@v4 + + - uses: xmake-io/github-action-setup-xmake@v1 + + - run: | + xmake repo -u + + - run: | + xmake f -a x64 -m release -p windows -v -y + + - run: | + xmake -w -y + + - uses: actions/upload-artifact@v3 + with: + name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }} + path: | + bin/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..42bf5e2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +on: + release: + types: + - published + +jobs: + build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + + - uses: xmake-io/github-action-setup-xmake@v1 + + - run: | + xmake repo -u + + - run: | + xmake f -a x64 -m release -p windows -v -y + + - run: | + xmake -w -y + + - uses: actions/upload-artifact@v3 + with: + name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }} + path: | + bin/ + + upload-to-release: + needs: + - build + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v3 + with: + name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }} + path: release/ + + - run: | + cp LICENSE README.md release/ + + - name: Archive release + run: | + cd release + zip -r ../${{ github.event.repository.name }}-windows-x64.zip * + cd .. + + - uses: softprops/action-gh-release@v1 + with: + append_body: true + files: | + ${{ github.event.repository.name }}-windows-x64.zip From 97c0adbf6e794997611b45587fa42320552b95e3 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:23:40 +0800 Subject: [PATCH 3/4] feat: Legacy Mod API --- src/LegacyModApi.cpp | 245 +++++++++++++++++++++++++------------------ 1 file changed, 141 insertions(+), 104 deletions(-) diff --git a/src/LegacyModApi.cpp b/src/LegacyModApi.cpp index 24d4e4c..609195c 100644 --- a/src/LegacyModApi.cpp +++ b/src/LegacyModApi.cpp @@ -1,108 +1,145 @@ #include "Global.h" +std::unordered_set HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"}; +std::unordered_set ExperimentsList = {6, 7, 8, 9, 10, 12, 15, 16}; + +std::variant> makeRecipeUnlockingKey(std::string& key) { + if (HardCodedKeys.count(key)) { + return key; + } + std::vector result; + auto item = RecipeIngredient(key, 0, 1); + result.emplace_back(item); + return result; +} + void ExportGMLib_ModAPI() { - /* - //合成表部分 - RemoteCall::exportAs("GMLib_ModAPI", "registerShapelessRecipe", [](std::string recipe_id, - std::vector ingredients, std::string result, int count, std::string unlock) -> void { - std::vector types; - for (auto ing : ingredients) { - RecipeItem key = {ing}; - types.push_back(key); - } - RecipeItem res = {result, 0, count}; - RecipeItem unl = {unlock}; - GMLib_Mod::addShapelessCraftingTableRecipe(recipe_id, types, res, {unl}); - }); - RemoteCall::exportAs("GMLib_ModAPI", "registerShapedRecipe", [](std::string recipe_id, std::vector - shape, std::vector ingredients, std::string result, int count, std::string unlock) -> void { - std::vector types; - for (auto ing : ingredients) { - RecipeItem key = {ing}; - types.push_back(key); - } - RecipeItem res = {result, 0, count}; - RecipeItem unl = {unlock}; - GMLib_Mod::addShapedCraftingTableRecipe(recipe_id, shape, types, res, {unl}); - }); - RemoteCall::exportAs("GMLib_ModAPI", "registerFurnaceRecipe", [](std::string recipe_id, std::string input, - std::string output, std::vector tags) -> void { RecipeItem inp = {input}; RecipeItem outp = - {output}; GMLib_Mod::addFurnaceRecipe(recipe_id, inp, outp, tags); - }); - RemoteCall::exportAs("GMLib_ModAPI", "registerBrewingMixRecipe", [](std::string recipe_id, std::string input, - std::string output, std::string reagent) -> void { RecipeItem rea = {reagent}; - GMLib_Mod::addBrewingMixRecipe(recipe_id, input, output, rea); - }); - RemoteCall::exportAs("GMLib_ModAPI", "registerBrewingContainerRecipe", [](std::string recipe_id, std::string - input, std::string output, std::string reagent) -> void { RecipeItem inp = {input}; RecipeItem outp = {output}; - RecipeItem rea = {reagent}; - GMLib_Mod::addBrewingContainerRecipe(recipe_id, inp, outp, rea); - }); - RemoteCall::exportAs("GMLib_ModAPI", "registerSmithingTransformRecipe", [](std::string recipe_id, std::string - smithing_template, std::string base, std::string addition, std::string result) -> void { - GMLib_Mod::addSmithingTransformRecipe(recipe_id, smithing_template, base, addition, result); - }); - RemoteCall::exportAs("GMLib_ModAPI", "registerSmithingTrimRecipe", [](std::string recipe_id, std::string - smithing_template, std::string base, std::string addition) -> void { GMLib_Mod::addSmithingTrimRecipe(recipe_id, - smithing_template, base, addition); - }); - RemoteCall::exportAs("GMLib_ModAPI", "registerStoneCutterRecipe", [](std::string recipe_id, std::string input, - int input_data, std::string output, int output_data, int output_count) -> void { RecipeItem inp = {input, - input_data}; RecipeItem outp = {output, output_data, output_count}; GMLib_Mod::addStoneCutterRecipe(recipe_id, - inp, outp); - }); - - //伤害类型 - RemoteCall::exportAs("GMLib_ModAPI", "registerDamageCause", [](int vanilla_cause, std::string cause_name, - std::string direct_killer_type, std::string die_type) -> void { - GMLib_Mod::addDamageCause((ActorDamageCause)vanilla_cause, cause_name, direct_killer_type, die_type); - }); - RemoteCall::exportAs("GMLib_ModAPI", "translateResourcePack", [](std::string key1, std::vector key2) - -> std::string { return GMLib_Mod::i18nTranslate(key1, key2); - }); - - //物品定义 - RemoteCall::exportAs("GMLib_ModAPI", "addFireImmuneItem", [](std::string id) -> void { - GMLib_Mod::addFireImmuneItem(id); - }); - RemoteCall::exportAs("GMLib_ModAPI", "addExplosionImmuneItem", [](std::string id) -> void { - GMLib_Mod::addExplosionImmuneItem(id); - }); - RemoteCall::exportAs("GMLib_ModAPI", "setArmorToughness", [](std::string id, double value) -> void { - GMLib_Mod::addArmorToughnessDefinition(id, value); - }); - - //错误方块清理 - RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", [](bool value) -> void { - GMLib_Mod::setUnknownBlockCleaner(value); - }); - - //生物定义 - RemoteCall::exportAs("GMLib_ModAPI", "setFixUndeadMobs", []() -> void { - GMLib_Mod::setFixUndeadMobs(); - }); - - //实验性 - RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void { - if (ExperimentsList.count(experiment_id)) { - GMLib_Mod::addExperimentsRequire((AllExperiments)experiment_id); - } - else Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id); - }); - RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void { - if (ExperimentsList.count(experiment_id)) { - GMLib_Mod::setExperimentEnabled(((AllExperiments)experiment_id), value); - } - else Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id); - }); - RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool { - if (ExperimentsList.count(experiment_id)) { - return GMLib_Mod::getExperimentEnabled(((AllExperiments)experiment_id)); - } - else { - Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id); - return false; - } - }); - */ + // 合成表部分 + RemoteCall::exportAs( + "GMLib_ModAPI", + "registerShapelessRecipe", + [](std::string recipe_id, + std::vector ingredients, + std::string result, + int count, + std::string unlock) -> void { + std::vector types; + for (auto ing : ingredients) { + auto key = RecipeIngredient(ing, 0, 1); + types.push_back(key); + } + auto res = RecipeIngredient(result, 0, count); + auto unl = makeRecipeUnlockingKey(unlock); + GMLIB::Mod::CustomRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl); + } + ); + RemoteCall::exportAs( + "GMLib_ModAPI", + "registerShapedRecipe", + [](std::string recipe_id, + std::vector shape, + std::vector ingredients, + std::string result, + int count, + std::string unlock) -> void { + std::vector types; + for (auto ing : ingredients) { + auto key = RecipeIngredient(ing, 0, 1); + types.push_back(key); + } + auto res = RecipeIngredient(result, 0, count); + auto unl = makeRecipeUnlockingKey(unlock); + GMLIB::Mod::CustomRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl); + } + ); + RemoteCall::exportAs( + "GMLib_ModAPI", + "registerFurnaceRecipe", + [](std::string recipe_id, std::string input, std::string output, std::vector tags) -> void { + auto inp = RecipeIngredient(input, 0, 1); + auto outp = RecipeIngredient(output, 0, 1); + GMLIB::Mod::CustomRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags); + } + ); + RemoteCall::exportAs( + "GMLib_ModAPI", + "registerBrewingMixRecipe", + [](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void { + auto rea = RecipeIngredient(reagent, 0, 1); + GMLIB::Mod::CustomRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea); + } + ); + RemoteCall::exportAs( + "GMLib_ModAPI", + "registerBrewingContainerRecipe", + [](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void { + auto inp = RecipeIngredient(input, 0, 1); + auto outp = RecipeIngredient(output, 0, 1); + auto rea = RecipeIngredient(reagent, 0, 1); + GMLIB::Mod::CustomRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea); + } + ); + RemoteCall::exportAs( + "GMLib_ModAPI", + "registerSmithingTransformRecipe", + [](std::string recipe_id, + std::string smithing_template, + std::string base, + std::string addition, + std::string result) -> void { + GMLIB::Mod::CustomRecipe::registerSmithingTransformRecipe( + recipe_id, + smithing_template, + base, + addition, + result + ); + } + ); + RemoteCall::exportAs( + "GMLib_ModAPI", + "registerSmithingTrimRecipe", + [](std::string recipe_id, std::string smithing_template, std::string base, std::string addition) -> void { + GMLIB::Mod::CustomRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition); + } + ); + RemoteCall::exportAs( + "GMLib_ModAPI", + "registerStoneCutterRecipe", + [](std::string recipe_id, + std::string input, + int input_data, + std::string output, + int output_data, + int output_count) -> void { + auto inp = RecipeIngredient(input, 0, 1); + auto outp = RecipeIngredient(output, 0, 1); + GMLIB::Mod::CustomRecipe::registerStoneCutterRecipe(recipe_id, inp, outp); + } + ); + // 错误方块清理 + RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void { + GMLIB::Mod::VanillaFix::setAutoCleanUnknownBlockEnabled(); + }); + // 实验性 + RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void { + if (ExperimentsList.count(experiment_id)) { + GMLIB_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 (ExperimentsList.count(experiment_id)) { + GMLIB_Level::getLevel()->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 (ExperimentsList.count(experiment_id)) { + return GMLIB_Level::getLevel()->getExperimentEnabled(((AllExperiments)experiment_id)); + } else { + ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id); + return false; + } + }); } \ No newline at end of file From a4d568620d4381c4c87440f78f94b4c2349f5c7c Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:43:05 +0800 Subject: [PATCH 4/4] feat: add more api --- src/CompatibilityApi.cpp | 16 ++++++++++++++++ src/Global.h | 6 +++++- src/LegacyModApi.cpp | 2 +- src/LegacyServerApi.cpp | 2 +- src/Plugin.cpp | 4 +++- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index e69de29..a572e22 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -0,0 +1,16 @@ +#include "Global.h" + +void Export_Compatibility_API() { + RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float { + return GMLIB_Level::getLevel()->getServerMspt(); + }); + RemoteCall::exportAs("GMLIB_API", "getServerCurrentTps", []() -> float { + return GMLIB_Level::getLevel()->getServerCurrentTps(); + }); + RemoteCall::exportAs("GMLIB_API", "getServerAverageTps", []() -> float { + return GMLIB_Level::getLevel()->getServerAverageTps(); + }); + RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector { + return GMLIB_Player::getAllUuids(); + }); +} \ No newline at end of file diff --git a/src/Global.h b/src/Global.h index 774383a..c445e32 100644 --- a/src/Global.h +++ b/src/Global.h @@ -4,4 +4,8 @@ #define PLUGIN_NAME "GMLIB-LRCA" -extern ll::Logger logger; \ No newline at end of file +extern ll::Logger logger; + +extern void Export_Legacy_GMLib_ModAPI(); +extern void Export_Legacy_GMLib_ServerAPI(); +extern void Export_Compatibility_API(); \ No newline at end of file diff --git a/src/LegacyModApi.cpp b/src/LegacyModApi.cpp index 609195c..fd8bc1b 100644 --- a/src/LegacyModApi.cpp +++ b/src/LegacyModApi.cpp @@ -13,7 +13,7 @@ std::variant> makeRecipeUnlockingKey( return result; } -void ExportGMLib_ModAPI() { +void Export_Legacy_GMLib_ModAPI() { // 合成表部分 RemoteCall::exportAs( "GMLib_ModAPI", diff --git a/src/LegacyServerApi.cpp b/src/LegacyServerApi.cpp index 07647b7..0a7a385 100644 --- a/src/LegacyServerApi.cpp +++ b/src/LegacyServerApi.cpp @@ -1,6 +1,6 @@ #include "Global.h" -void ExportGMLib_ServerAPI() { +void Export_Legacy_GMLib_ServerAPI() { RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void { GMLIB_Level::addEducationEditionRequired(); }); diff --git a/src/Plugin.cpp b/src/Plugin.cpp index f6cdb5e..a9b0f8e 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -7,7 +7,9 @@ namespace plugin { Plugin::Plugin(ll::plugin::NativePlugin& self) : mSelf(self) { // Code for loading the plugin goes here. - + Export_Legacy_GMLib_ModAPI(); + Export_Legacy_GMLib_ServerAPI(); + Export_Compatibility_API(); logger.info("GMLIB-LegacyRemoteCallApi Loaded!"); logger.info("Author: GroupMountain"); logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");