feat: Legacy Mod API

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