feat: Legacy Mod API

This commit is contained in:
Tsubasa6848
2024-02-08 21:23:40 +08:00
Unverified
parent 0226f8bbba
commit 97c0adbf6e
+119 -82
View File
@@ -1,108 +1,145 @@
#include "Global.h" #include "Global.h"
std::unordered_set<std::string> HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"};
std::unordered_set<int> ExperimentsList = {6, 7, 8, 9, 10, 12, 15, 16};
std::variant<std::string, std::vector<RecipeIngredient>> makeRecipeUnlockingKey(std::string& key) {
if (HardCodedKeys.count(key)) {
return key;
}
std::vector<RecipeIngredient> result;
auto item = RecipeIngredient(key, 0, 1);
result.emplace_back(item);
return result;
}
void ExportGMLib_ModAPI() { void ExportGMLib_ModAPI() {
/*
// 合成表部分 // 合成表部分
RemoteCall::exportAs("GMLib_ModAPI", "registerShapelessRecipe", [](std::string recipe_id, RemoteCall::exportAs(
std::vector<std::string> ingredients, std::string result, int count, std::string unlock) -> void { "GMLib_ModAPI",
std::vector<RecipeItem> types; "registerShapelessRecipe",
[](std::string recipe_id,
std::vector<std::string> ingredients,
std::string result,
int count,
std::string unlock) -> void {
std::vector<RecipeIngredient> types;
for (auto ing : ingredients) { for (auto ing : ingredients) {
RecipeItem key = {ing}; auto key = RecipeIngredient(ing, 0, 1);
types.push_back(key); types.push_back(key);
} }
RecipeItem res = {result, 0, count}; auto res = RecipeIngredient(result, 0, count);
RecipeItem unl = {unlock}; auto unl = makeRecipeUnlockingKey(unlock);
GMLib_Mod::addShapelessCraftingTableRecipe(recipe_id, types, res, {unl}); GMLIB::Mod::CustomRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
}); }
RemoteCall::exportAs("GMLib_ModAPI", "registerShapedRecipe", [](std::string recipe_id, std::vector<std::string> );
shape, std::vector<std::string> ingredients, std::string result, int count, std::string unlock) -> void { RemoteCall::exportAs(
std::vector<RecipeItem> types; "GMLib_ModAPI",
"registerShapedRecipe",
[](std::string recipe_id,
std::vector<std::string> shape,
std::vector<std::string> ingredients,
std::string result,
int count,
std::string unlock) -> void {
std::vector<RecipeIngredient> types;
for (auto ing : ingredients) { for (auto ing : ingredients) {
RecipeItem key = {ing}; auto key = RecipeIngredient(ing, 0, 1);
types.push_back(key); types.push_back(key);
} }
RecipeItem res = {result, 0, count}; auto res = RecipeIngredient(result, 0, count);
RecipeItem unl = {unlock}; auto unl = makeRecipeUnlockingKey(unlock);
GMLib_Mod::addShapedCraftingTableRecipe(recipe_id, shape, types, res, {unl}); 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<std::string> tags) -> void { RecipeItem inp = {input}; RecipeItem outp = RemoteCall::exportAs(
{output}; GMLib_Mod::addFurnaceRecipe(recipe_id, inp, outp, tags); "GMLib_ModAPI",
}); "registerFurnaceRecipe",
RemoteCall::exportAs("GMLib_ModAPI", "registerBrewingMixRecipe", [](std::string recipe_id, std::string input, [](std::string recipe_id, std::string input, std::string output, std::vector<std::string> tags) -> void {
std::string output, std::string reagent) -> void { RecipeItem rea = {reagent}; auto inp = RecipeIngredient(input, 0, 1);
GMLib_Mod::addBrewingMixRecipe(recipe_id, input, output, rea); auto outp = RecipeIngredient(output, 0, 1);
}); GMLIB::Mod::CustomRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
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}; RemoteCall::exportAs(
GMLib_Mod::addBrewingContainerRecipe(recipe_id, inp, outp, rea); "GMLib_ModAPI",
}); "registerBrewingMixRecipe",
RemoteCall::exportAs("GMLib_ModAPI", "registerSmithingTransformRecipe", [](std::string recipe_id, std::string [](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void {
smithing_template, std::string base, std::string addition, std::string result) -> void { auto rea = RecipeIngredient(reagent, 0, 1);
GMLib_Mod::addSmithingTransformRecipe(recipe_id, smithing_template, base, addition, result); GMLIB::Mod::CustomRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
}); }
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, RemoteCall::exportAs(
smithing_template, base, addition); "GMLib_ModAPI",
}); "registerBrewingContainerRecipe",
RemoteCall::exportAs("GMLib_ModAPI", "registerStoneCutterRecipe", [](std::string recipe_id, std::string input, [](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void {
int input_data, std::string output, int output_data, int output_count) -> void { RecipeItem inp = {input, auto inp = RecipeIngredient(input, 0, 1);
input_data}; RecipeItem outp = {output, output_data, output_count}; GMLib_Mod::addStoneCutterRecipe(recipe_id, auto outp = RecipeIngredient(output, 0, 1);
inp, outp); auto rea = RecipeIngredient(reagent, 0, 1);
}); GMLIB::Mod::CustomRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
}
//伤害类型 );
RemoteCall::exportAs("GMLib_ModAPI", "registerDamageCause", [](int vanilla_cause, std::string cause_name, RemoteCall::exportAs(
std::string direct_killer_type, std::string die_type) -> void { "GMLib_ModAPI",
GMLib_Mod::addDamageCause((ActorDamageCause)vanilla_cause, cause_name, direct_killer_type, die_type); "registerSmithingTransformRecipe",
}); [](std::string recipe_id,
RemoteCall::exportAs("GMLib_ModAPI", "translateResourcePack", [](std::string key1, std::vector<std::string> key2) std::string smithing_template,
-> std::string { return GMLib_Mod::i18nTranslate(key1, key2); std::string base,
}); std::string addition,
std::string result) -> void {
//物品定义 GMLIB::Mod::CustomRecipe::registerSmithingTransformRecipe(
RemoteCall::exportAs("GMLib_ModAPI", "addFireImmuneItem", [](std::string id) -> void { recipe_id,
GMLib_Mod::addFireImmuneItem(id); smithing_template,
}); base,
RemoteCall::exportAs("GMLib_ModAPI", "addExplosionImmuneItem", [](std::string id) -> void { addition,
GMLib_Mod::addExplosionImmuneItem(id); result
}); );
RemoteCall::exportAs("GMLib_ModAPI", "setArmorToughness", [](std::string id, double value) -> void { }
GMLib_Mod::addArmorToughnessDefinition(id, value); );
}); 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", [](bool value) -> void { RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
GMLib_Mod::setUnknownBlockCleaner(value); GMLIB::Mod::VanillaFix::setAutoCleanUnknownBlockEnabled();
}); });
//生物定义
RemoteCall::exportAs("GMLib_ModAPI", "setFixUndeadMobs", []() -> void {
GMLib_Mod::setFixUndeadMobs();
});
// 实验性 // 实验性
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void { RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
if (ExperimentsList.count(experiment_id)) { if (ExperimentsList.count(experiment_id)) {
GMLib_Mod::addExperimentsRequire((AllExperiments)experiment_id); GMLIB_Level::addExperimentsRequire((AllExperiments)experiment_id);
} else {
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
} }
else Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
}); });
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void { RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
if (ExperimentsList.count(experiment_id)) { if (ExperimentsList.count(experiment_id)) {
GMLib_Mod::setExperimentEnabled(((AllExperiments)experiment_id), value); GMLIB_Level::getLevel()->setExperimentEnabled(((AllExperiments)experiment_id), value);
} } else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
else Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
}); });
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool { RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
if (ExperimentsList.count(experiment_id)) { if (ExperimentsList.count(experiment_id)) {
return GMLib_Mod::getExperimentEnabled(((AllExperiments)experiment_id)); return GMLIB_Level::getLevel()->getExperimentEnabled(((AllExperiments)experiment_id));
} } else {
else { ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
return false; return false;
} }
}); });
*/
} }