adapt: adapt gmlib 1.0.0-rc.2 and levilamina 1.1.0

This commit is contained in:
zimuya4153
2025-03-22 00:10:55 +08:00
Unverified
parent b34c84f157
commit accf1d0664
15 changed files with 883 additions and 621 deletions
+81 -80
View File
@@ -1,4 +1,6 @@
#include "Global.h"
#include <gmlib/mc/world/Level.h>
#include <mc/world/item/crafting/RecipeIngredient.h>
std::unordered_set<std::string> HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"};
@@ -17,17 +19,18 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& result,
int count,
std::string const& unlock) -> void {
if (!GMLIB_Level::getInstance().has_value()) return;
std::vector<RecipeIngredient> types;
for (auto ing : ingredients) {
types.emplace_back(ing, 0, 1);
}
GMLIB::Mod::JsonRecipe::registerShapelessCraftingTableRecipe(
recipe_id,
types,
RecipeIngredient(result, 0, count),
makeRecipeUnlockingKey(unlock)
);
// if (!GMLIB_Level::getInstance().has_value()) return;
// std::vector<RecipeIngredient> types;
// for (auto ing : ingredients) {
// types.emplace_back(ing, 0, 1);
// }
// GMLIB::Mod::JsonRecipe::registerShapelessCraftingTableRecipe(
// recipe_id,
// types,
// RecipeIngredient(result, 0, count),
// makeRecipeUnlockingKey(unlock)
// );
throw std::runtime_error("GMLib_ModAPI::registerShapelessRecipe is not implemented");
}
);
RemoteCall::exportAs(
@@ -39,18 +42,19 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& result,
int count,
std::string const& unlock) -> void {
if (!GMLIB_Level::getInstance().has_value()) return;
std::vector<RecipeIngredient> types;
for (auto ing : ingredients) {
types.push_back(RecipeIngredient(ing, 0, 1));
}
GMLIB::Mod::JsonRecipe::registerShapedCraftingTableRecipe(
recipe_id,
shape,
types,
RecipeIngredient(result, 0, count),
makeRecipeUnlockingKey(unlock)
);
// if (!GMLIB_Level::getInstance().has_value()) return;
// std::vector<RecipeIngredient> types;
// for (auto ing : ingredients) {
// types.push_back(RecipeIngredient(ing, 0, 1));
// }
// GMLIB::Mod::JsonRecipe::registerShapedCraftingTableRecipe(
// recipe_id,
// shape,
// types,
// RecipeIngredient(result, 0, count),
// makeRecipeUnlockingKey(unlock)
// );
throw std::runtime_error("GMLib_ModAPI::registerShapedRecipe is not implemented");
}
);
RemoteCall::exportAs(
@@ -60,13 +64,14 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& input,
std::string const& output,
std::vector<std::string> tags) -> void {
if (!GMLIB_Level::getInstance().has_value()) return;
GMLIB::Mod::JsonRecipe::registerFurnaceRecipe(
recipe_id,
RecipeIngredient(input, 0, 1),
RecipeIngredient(output, 0, 1),
tags
);
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerFurnaceRecipe(
// recipe_id,
// RecipeIngredient(input, 0, 1),
// RecipeIngredient(output, 0, 1),
// tags
// );
throw std::runtime_error("GMLib_ModAPI::registerFurnaceRecipe is not implemented");
}
);
RemoteCall::exportAs(
@@ -74,8 +79,10 @@ void Export_Legacy_GMLib_ModAPI() {
"registerBrewingMixRecipe",
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
) -> void {
if (!GMLIB_Level::getInstance().has_value()) return;
GMLIB::Mod::JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, RecipeIngredient(reagent, 0, 1));
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, RecipeIngredient(reagent, 0,
// 1));
throw std::runtime_error("GMLib_ModAPI::registerBrewingMixRecipe is not implemented");
}
);
RemoteCall::exportAs(
@@ -83,13 +90,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 {
if (!GMLIB_Level::getInstance().has_value()) return;
GMLIB::Mod::JsonRecipe::registerBrewingContainerRecipe(
recipe_id,
RecipeIngredient(input, 0, 1),
RecipeIngredient(output, 0, 1),
RecipeIngredient(reagent, 0, 1)
);
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerBrewingContainerRecipe(
// recipe_id,
// RecipeIngredient(input, 0, 1),
// RecipeIngredient(output, 0, 1),
// RecipeIngredient(reagent, 0, 1)
// );
throw std::runtime_error("GMLib_ModAPI::registerBrewingContainerRecipe is not implemented");
}
);
RemoteCall::exportAs(
@@ -100,14 +108,15 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& base,
std::string const& addition,
std::string const& result) -> void {
if (!GMLIB_Level::getInstance().has_value()) return;
GMLIB::Mod::JsonRecipe::registerSmithingTransformRecipe(
recipe_id,
smithing_template,
base,
addition,
result
);
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerSmithingTransformRecipe(
// recipe_id,
// smithing_template,
// base,
// addition,
// result
// );
throw std::runtime_error("GMLib_ModAPI::registerSmithingTransformRecipe is not implemented");
}
);
RemoteCall::exportAs(
@@ -117,8 +126,9 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& smithing_template,
std::string const& base,
std::string const& addition) -> void {
if (!GMLIB_Level::getInstance().has_value()) return;
GMLIB::Mod::JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
throw std::runtime_error("GMLib_ModAPI::registerSmithingTrimRecipe is not implemented");
}
);
RemoteCall::exportAs(
@@ -130,49 +140,40 @@ void Export_Legacy_GMLib_ModAPI() {
std::string const& output,
int output_data,
int output_count) -> void {
if (!GMLIB_Level::getInstance().has_value()) return;
GMLIB::Mod::JsonRecipe::registerStoneCutterRecipe(
recipe_id,
RecipeIngredient(input, 0, 1),
RecipeIngredient(output, 0, 1)
);
// if (!GMLIB_Level::getInstance().has_value()) return;
// GMLIB::Mod::JsonRecipe::registerStoneCutterRecipe(
// recipe_id,
// RecipeIngredient(input, 0, 1),
// RecipeIngredient(output, 0, 1)
// );
throw std::runtime_error("GMLib_ModAPI::registerStoneCutterRecipe is not implemented");
}
);
// 错误方块清理
RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
GMLIB::Mod::VanillaFix::setAutoCleanUnknownBlockEnabled();
// GMLIB::Mod::VanillaFix::setAutoCleanUnknownBlockEnabled();
throw std::runtime_error("GMLib_ModAPI::setUnknownBlockCleaner is not implemented");
});
// 实验性
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
auto list = GMLIB_Level::getAllExperiments();
std::unordered_set<AllExperiments> set(list.begin(), list.end());
if (set.contains((AllExperiments)experiment_id)) {
GMLIB_Level::addExperimentsRequire((AllExperiments)experiment_id);
} else {
ll::io::LoggerRegistry::getInstance().getOrCreate("Server")->error("Experiment ID '{}' does not exist!", experiment_id);
}
GMLevel::getInstance().and_then([&](GMLevel& level) {
level.setExperimentEnabled((AllExperiments)experiment_id);
return true;
});
});
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
if (GMLIB_Level::getInstance()) {
auto list = GMLIB_Level::getAllExperiments();
std::unordered_set<AllExperiments> set(list.begin(), list.end());
if (set.contains((AllExperiments)experiment_id)) {
GMLIB_Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value);
} else ll::io::LoggerRegistry::getInstance().getOrCreate("Server")->error("Experiment ID '{}' does not exist!", experiment_id);
}
GMLevel::getInstance().and_then([&](GMLevel& level) {
level.setExperimentEnabled((AllExperiments)experiment_id, value);
return true;
});
});
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
if (GMLIB_Level::getInstance()) {
auto list = GMLIB_Level::getAllExperiments();
std::unordered_set<AllExperiments> set(list.begin(), list.end());
if (set.contains((AllExperiments)experiment_id)) {
return GMLIB_Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
}
ll::io::LoggerRegistry::getInstance().getOrCreate("Server")->error("Experiment ID '{}' does not exist!", experiment_id);
}
return false;
return GMLevel::getInstance()
.transform([&](GMLevel& level) { return level.getExperimentEnabled((AllExperiments)experiment_id); })
.value_or(false);
});
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {
GMLIB::Mod::VanillaFix::setFixI18nEnabled();
// GMLIB::Mod::VanillaFix::setFixI18nEnabled();
throw std::runtime_error("GMLib_ModAPI::setFixI18nEnabled is not implemented");
});
}