feat: add custom recipe
This commit is contained in:
Vendored
+22
@@ -509,6 +509,28 @@ declare class Recipes {
|
|||||||
/** 解锁条件(也可以填物品命名空间ID) */
|
/** 解锁条件(也可以填物品命名空间ID) */
|
||||||
unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined
|
unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined
|
||||||
): boolean;
|
): boolean;
|
||||||
|
|
||||||
|
/** 注册自定义有序合成表 */
|
||||||
|
static registerCustomShapedRecipe(
|
||||||
|
/** 合成表唯一标识符 */
|
||||||
|
recipeId: string,
|
||||||
|
/** 合成表摆放方式,数组元素为字符串 */
|
||||||
|
shape: [string, string, string],
|
||||||
|
/** 材料数组 */
|
||||||
|
ingredients: string[],
|
||||||
|
/** 合成结果 */
|
||||||
|
result: Item
|
||||||
|
): boolean;
|
||||||
|
|
||||||
|
/** 注册自定义无序合成表 */
|
||||||
|
static registerCustomShapelessRecipe(
|
||||||
|
/** 合成表唯一标识符 */
|
||||||
|
recipeId: string,
|
||||||
|
/** 合成材料 */
|
||||||
|
ingredients: string[],
|
||||||
|
/** 合成结果 */
|
||||||
|
result: Item
|
||||||
|
): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 实验性功能类 */
|
/** 实验性功能类 */
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ const GMLIB_API = {
|
|||||||
registerShapedRecipe: ll.import("GMLib_ModAPI", "registerShapedRecipe"),
|
registerShapedRecipe: ll.import("GMLib_ModAPI", "registerShapedRecipe"),
|
||||||
/** 注册无序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
|
/** 注册无序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
|
||||||
registerShapelessRecipe: ll.import("GMLib_ModAPI", "registerShapelessRecipe"),
|
registerShapelessRecipe: ll.import("GMLib_ModAPI", "registerShapelessRecipe"),
|
||||||
|
/** 注册有序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
|
||||||
|
registerCustomShapedRecipe: ll.import("GMLIB_API", "registerShapedRecipe"),
|
||||||
|
/** 注册无序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
|
||||||
|
registerCustomShapelessRecipe: ll.import("GMLIB_API", "registerShapelessRecipe"),
|
||||||
/** 检测LRCA版本是否大于或等于此版本 @type {function(number,number,number):boolean} */
|
/** 检测LRCA版本是否大于或等于此版本 @type {function(number,number,number):boolean} */
|
||||||
isVersionMatched: ll.import("GMLIB_API", "isVersionMatched"),
|
isVersionMatched: ll.import("GMLIB_API", "isVersionMatched"),
|
||||||
/** 获取LRCA版本 @type {function():string} */
|
/** 获取LRCA版本 @type {function():string} */
|
||||||
@@ -1194,6 +1198,18 @@ class Recipes {
|
|||||||
return GMLIB_API.registerShapedRecipe(recipeId, shape, ingredients, result, count, unlock);
|
return GMLIB_API.registerShapedRecipe(recipeId, shape, ingredients, result, count, unlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册自定义有序合成表
|
||||||
|
* @param {string} recipeId 合成表唯一标识
|
||||||
|
* @param {[string,string,string]} shape 合成表摆放方式,数组元素为字符串
|
||||||
|
* @param {Array.<string>} ingredients 材料数组
|
||||||
|
* @param {Item} result 合成结果
|
||||||
|
* @returns {boolean} 是否注册成功
|
||||||
|
*/
|
||||||
|
static registerCustomShapedRecipe(recipeId, shape, ingredients, result) {
|
||||||
|
return GMLIB_API.registerCustomShapedRecipe(recipeId, shape, ingredients, result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册无序合成表
|
* 注册无序合成表
|
||||||
* @param {string} recipeId 合成表唯一标识
|
* @param {string} recipeId 合成表唯一标识
|
||||||
@@ -1206,6 +1222,17 @@ class Recipes {
|
|||||||
static registerShapelessRecipe(recipeId, ingredients, result, count = 1, unlock = "AlwaysUnlocked") {
|
static registerShapelessRecipe(recipeId, ingredients, result, count = 1, unlock = "AlwaysUnlocked") {
|
||||||
return GMLIB_API.registerShapelessRecipe(recipeId, ingredients, result, count, unlock);
|
return GMLIB_API.registerShapelessRecipe(recipeId, ingredients, result, count, unlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册自定义无序合成表
|
||||||
|
* @param {string} recipeId 合成表唯一标识
|
||||||
|
* @param {Array.<string>} ingredients 合成材料
|
||||||
|
* @param {Item} result 合成结果
|
||||||
|
* @returns {boolean} 是否注册成功
|
||||||
|
*/
|
||||||
|
static registerCustomShapelessRecipe(recipeId, ingredients, result) {
|
||||||
|
return GMLIB_API.registerCustomShapelessRecipe(recipeId, ingredients, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 实验性功能类 */
|
/** 实验性功能类 */
|
||||||
|
|||||||
@@ -958,4 +958,43 @@ void Export_Compatibility_API() {
|
|||||||
level->setDefaultGameType((GameType)gameMode);
|
level->setDefaultGameType((GameType)gameMode);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
RemoteCall::exportAs(
|
||||||
|
"GMLIB_API",
|
||||||
|
"registerCustomShapelessRecipe",
|
||||||
|
[](std::string const& recipe_id, std::vector<std::string> ingredients, ItemStack* result) -> void {
|
||||||
|
auto level = GMLIB_Level::getInstance();
|
||||||
|
if (!level) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::vector<Recipes::Type> types;
|
||||||
|
char rt = 'A';
|
||||||
|
for (auto& ing : ingredients) {
|
||||||
|
auto key = Recipes::Type(ing, rt, 1, 0);
|
||||||
|
types.push_back(key);
|
||||||
|
rt++;
|
||||||
|
}
|
||||||
|
CustomRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, *result);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
RemoteCall::exportAs(
|
||||||
|
"GMLIB_API",
|
||||||
|
"registerCustomShapedRecipe",
|
||||||
|
[](std::string const& recipe_id,
|
||||||
|
std::vector<std::string> shape,
|
||||||
|
std::vector<std::string> ingredients,
|
||||||
|
ItemStack* result) -> void {
|
||||||
|
auto level = GMLIB_Level::getInstance();
|
||||||
|
if (!level) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::vector<Recipes::Type> types;
|
||||||
|
char rt = 'A';
|
||||||
|
for (auto& ing : ingredients) {
|
||||||
|
auto key = Recipes::Type(ing, rt, 1, 0);
|
||||||
|
types.push_back(key);
|
||||||
|
rt++;
|
||||||
|
}
|
||||||
|
CustomRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, *result);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user