饥荒Mod 开发(八):游戏所有食材和食物

饥荒Mod 开发(七):调试技巧
饥荒Mod 开发(九):物品栏排列

饥荒中内置了很多烹饪的食物,每种食物都可以由不同的食材烹饪出来,今天介绍如何将内置的食物打印出来。

食材

饥荒中的食材可以放入烹饪锅,每个食材都有很多的属性,比如名字,类型,“度数”

-- 为 "meat" 这个食材添加 "meat" 属性,属性的值是 1。
AddIngredientValues({"meat"}, {meat=1}, true, true)

-- 为 "monstermeat" 这个食材添加 "meat" 和 "monster" 两个属性,每个属性的值都是 1。
AddIngredientValues({"monstermeat"}, {meat=1, monster=1}, true, true)

-- 为 "froglegs"、"drumstick" 和 "batwing" 这些食材添加 "meat" 属性,属性的值是 0.5。
AddIngredientValues({"froglegs", "drumstick", "batwing"}, {meat=.5}, true)

-- 为 "smallmeat" 这个食材添加 "meat" 属性,属性的值是 0.5。
AddIngredientValues({"smallmeat"}, {meat=.5}, true, true)

-- 为 "plantmeat" 这个食材添加 "meat" 属性,属性的值是 1。
AddIngredientValues({"plantmeat"}, {meat=1}, true)

在这里插入图片描述
我们也可以调用AddIngredientValues 添加自己的食材

食谱

游戏有一个lua代码文件定义了很多的内置食物。每种食物的烹饪时间,食物类型,生命/节/精神值,以及保鲜时间等。代码路径如下:
data\scripts\preparedfoods.lua

--部分代码解释
butterflymuffin =
{
    -- test 是一个函数,用于检查是否可以制作这个食物。
    -- 这个函数接受三个参数:cooker(烹饪设备),names(食材的名称),tags(食材的标签)。
    -- 这个函数返回 true 如果食材中包含蝴蝶翅膀,不包含肉类,并且包含蔬菜。
    test = function(cooker, names, tags) return names.butterflywings and not tags.meat and tags.veggie end,

    -- priority 决定了在多个配方都可以制作的情况下,哪个配方会被优先选择。数字越大,优先级越高。
    priority = 1,

    -- weight 决定了这个食物的重量,可能影响角色移动速度。
    weight = 1,

    -- foodtype 是这个食物的类型,这里是 "VEGGIE",表示这是一个蔬菜类食物。
    foodtype = "VEGGIE",

    -- health,hunger,sanity 分别表示这个食物恢复的生命值,饥饿值和精神值。
    health = TUNING.HEALING_MED,
    hunger = TUNING.CALORIES_LARGE,
    sanity = TUNING.SANITY_TINY,

    -- perishtime 是这个食物的腐烂时间,单位是天。
    perishtime = TUNING.PERISH_SLOW,

    -- cooktime 是这个食物的烹饪时间,实际 2 *20 秒。
    cooktime = 2,
},

食物

如何判断烹饪的结果

饥荒中判断烹饪结果是通过食物的test函数来判断的,当我们放入4个原料的时候,游戏会按照优先级遍历所有的食物,挨个调用test函数,只要test函数返回true,就认为可以烹饪。所以不同的原料是可以烹饪出相同的食物的。
饥荒提供了一个函数用来判断烹饪结果。源码在:data\scripts\cooking.lua

-- 引入 cooking 模块
local cooking = require("cooking")

-- 创建一个表来存储食材
local ings = {}

-- 向食材表中添加四个 "twigs"
table.insert(ings, "twigs")
table.insert(ings, "twigs")
table.insert(ings, "twigs")
table.insert(ings, "twigs")

-- 调用 cooking.CalculateRecipe 函数来计算烹饪的结果和所需的时间
-- "cookpot" 是烹饪设备的类型,ings 是食材表
-- CalculateRecipe 函数返回两个值:烹饪的结果(product)和所需的时间(cooktime)
local product, cooktime = cooking.CalculateRecipe("cookpot", ings)

输出饥荒中所有的食材和食物

在modmain.lua 文件中,复制下面的代码。进入以后洗之后,打开调试页面, 按下键盘F1 键盘,可以将结果输出到文件中,文件的目录比较深,可以用everything 搜索一下,我的路径

C:\WeGameApps\rail_user_data\2000013\76561197981883591\cloud_storage\user_space\2199037600743566342\formal\content\files\myfoods.txt
-- 导入 "cooking" 模块,这个模块包含了食材和食谱的定义。
local cooking = GLOBAL.require("cooking")

-- 添加一个按键处理器。这个处理器会在玩家按下或释放一个键时被调用。
GLOBAL.TheInput:AddKeyHandler(function(key, down)
    -- 检查按下的键是否是 F1 键
    if (key == GLOBAL.KEY_F1 and not down) then
       local content = "-----------------原料------------------------"
       -- 遍历所有的食材。
       for name, v in pairs(cooking.ingredients) do
            -- 将食材的名称添加到 content 字符串中。
            content = content .. tostring(GLOBAL.STRINGS.NAMES[string.upper(name)]) .. "(" .. name .. ")\n"
            -- 如果这个食材有标签,那么遍历这些标签,并将它们添加到 content 字符串中。
            if v.tags then              
                for tag, tagval in pairs(v.tags) do
                    content = content .. tag .. ":" .. tostring(tagval) .. "\t"
                end
            end
            content = content .. "\n"
       end
       -- 遍历所有的食谱。
       content = content .. "-----------------食谱------------------------\n"
       for cooker, v in pairs(cooking.recipes) do
            -- 将烹饪设备的名称添加到 content 字符串中。
            content = content .. cooker .. "\n"
            -- 遍历这个烹饪设备可以制作的所有食物,并将这些食物的信息添加到 content 字符串中。
            for name, recipe in pairs(v) do
                content = content .. tostring(GLOBAL.STRINGS.NAMES[string.upper(name)]) .. "("..  name .. "):" .. " foodtype:" .. tostring(recipe.foodtype) .. " health:" .. tostring(recipe.health) .. " hunger:" .. tostring(recipe.hunger) .. " sanity:" .. tostring(recipe.sanity) .. " \n\n"
            end
            content = content .. "\n"
       end
       -- 将 content 字符串保存到 "myfoods.txt" 文件中。
       TheSim:SetPersistentString("myfoods.txt", content)	
    end
end)
KLEI     1 -----------------原料------------------------蝴蝶翅膀(butterflywings)
decoration:2	

熟红蘑菇(red_cap_cooked)
veggie:0.5	precook:1	

烤椰子(coconut_cooked)
fruit:1	fat:1	

洞穴蝙蝠翅膀(batwing)
meat:0.5	

龙虾(lobster)
fish:2	

熟甘薯(sweet_potato_cooked)
veggie:1	precook:1	

采摘的绿蘑菇(green_cap)
veggie:0.5	

鱼(fish)
meat:0.5	fish:1	

熟蛙腿(froglegs_cooked)
meat:0.5	precook:1	

鼹鼠(mole)
meat:0.5	

茄子(eggplant)
veggie:1	

榴莲(durian)
monster:1	fruit:1	

烤咖啡豆(coffeebeans_cooked)
fruit:1	

熟火龙果(dragonfruit_cooked)
fruit:1	precook:1	

晾干的水母(jellyjerky)
monster:1	fish:1	jellyfish:1	

熟鳗鱼(eel_cooked)
fish:1	meat:0.5	precook:1	

采摘的蓝蘑菇(blue_cap)
veggie:0.5	

生鱼肉(fish_raw)
meat:0.5	fish:1	

nil(monstermeat_cooked)
monster:1	meat:1	precook:1	

干海带(seaweed_dried)
dried:1	veggie:1	

nil(smallmeat_cooked)
meat:0.5	precook:1	

高脚鸟蛋(tallbirdegg)
egg:4	

nil(egg_cooked)
egg:1	precook:1	

冰(ice)
frozen:1	

熟水母(jellyfish_cooked)
monster:1	fish:1	jellyfish:1	

鱼翅(shark_fin)
meat:0.5	fish:1	

烤桦栗果(acorn_cooked)
seed:1	precook:1	

烤茄子(eggplant_cooked)
veggie:1	precook:1	

分成两半的椰子(coconut_halved)
fruit:1	fat:1	

nil(meat_cooked)
meat:1	precook:1	

浆果(berries)
fruit:0.5	

蜂蜜(honey)
sweetener:1	

热带鱼(tropical_fish)
meat:0.5	fish:1	

熟小丑鱼(fish4_cooked)
meat:0.5	fish:1	

仙人掌花(cactus_flower)
veggie:0.5	

熟小鱼块(fish_raw_small_cooked)
fish:0.5	precook:1	

曼德拉草(mandrake)
magic:1	veggie:1	

蜂巢(honeycomb)
sweetener:1	

洞穴香蕉(cave_banana)
fruit:1	

咖啡豆(coffeebeans)
fruit:0.5	

兔蟹(crab)
fish:0.5	

nil(lobster_cooked)
fish:2	precook:1	

熟贻贝(mussel_cooked)
fish:0.5	precook:1	

鸟蛋(bird_egg)
egg:1	

贻贝(mussel)
fish:0.5	

熟帽贝(limpets_cooked)
fish:0.5	precook:1	

小丑鱼(fish4)
meat:0.5	fish:1	

死狗鱼(fish_med)
meat:0.5	fish:1	

鱼卵(roe)
meat:0.5	fish:1	

帽贝(limpets)
fish:0.5	

蛙腿(froglegs)
meat:0.5	

熟彩虹水母(rainbowjellyfish_cooked)
monster:1	fish:1	jellyfish:1	

炸鸟腿(drumstick_cooked)
meat:0.5	precook:1	

死彩虹水母(rainbowjellyfish_dead)
monster:1	fish:1	jellyfish:1	

熟鸟蛋(bird_egg_cooked)
egg:1	precook:1	

彩虹水母(rainbowjellyfish)
monster:1	fish:1	jellyfish:1	

鳗鱼(eel)
meat:0.5	fish:1	

烤胡萝卜(carrot_cooked)
veggie:1	precook:1	

小肉(smallmeat)
meat:0.5	

死水母(jellyfish_dead)
monster:1	fish:1	jellyfish:1	

水母(jellyfish)
monster:1	fish:1	jellyfish:1	

超臭榴莲(durian_cooked)
monster:1	fruit:1	precook:1	

熟鱼卵(roe_cooked)
meat:0.5	fish:1	

熟霓虹鱼(fish5_cooked)
meat:0.5	fish:1	

霓虹鱼(fish5)
meat:0.5	fish:1	

熟紫石斑鱼(fish3_cooked)
meat:0.5	fish:1	

切片熟石榴(pomegranate_cooked)
fruit:1	precook:1	

肉干(meat_dried)
dried:1	meat:1	

nil(honey_cooked)
sweetener:1	precook:1	

树枝(twigs)
inedible:1	

熟绿蘑菇(green_cap_cooked)
veggie:0.5	precook:1	

南瓜(pumpkin)
veggie:1	

nil(tropical_fish_cooked)
fish:1	meat:0.5	precook:1	

剑鱼(swordfish)
meat:0.5	fish:1	

熟叶肉(plantmeat_cooked)
meat:1	precook:1	

胡萝卜(carrot)
veggie:1	

鱼排(fish_med_cooked)
meat:0.5	fish:1	

背鳍(dorsalfin)
inedible:1	

西瓜(watermelon)
fruit:1	

渡渡鸟蛋(doydoyegg)
egg:1	

熟蓝蘑菇(blue_cap_cooked)
veggie:0.5	precook:1	

熟鱼(fish_cooked)
fish:1	meat:0.5	precook:1	

烤海带(seaweed_cooked)
veggie:1	precook:1	

小鱼块(fish_raw_small)
fish:0.5	

玉米(corn)
veggie:1	

叶肉(plantmeat)
meat:1	

带电的羊奶(goatmilk)
dairy:1	

桦栗果(acorn)
seed:1	

烤西瓜(watermelon_cooked)
fruit:1	precook:1	

nil(honeycomb_cooked)
sweetener:1	precook:1	

煎渡渡鸟蛋(doydoyegg_cooked)
egg:1	precook:1	

苔藓(cutlichen)
veggie:1	

仙人掌肉(cactus_meat)
veggie:1	

nil(egg)
egg:1	

熟蝙蝠翅膀(batwing_cooked)
meat:0.5	precook:1	

怪物肉(monstermeat)
meat:1	monster:1	

火龙果(dragonfruit)
fruit:1	

紫石斑鱼(fish3)
meat:0.5	fish:1	

烤南瓜(pumpkin_cooked)
veggie:1	precook:1	

肉(meat)
meat:1	

海带(seaweed)
veggie:1	

烤浆果(berries_cooked)
fruit:0.5	precook:1	

鸟腿(drumstick)
meat:0.5	

石榴(pomegranate)
fruit:1	

熟仙人掌肉(cactus_meat_cooked)
veggie:1	precook:1	

黄油(butter)
dairy:1	fat:1	

nil(mandrake_cooked)
veggie:1	magic:1	precook:1	

甘薯(sweet_potato)
veggie:1	

熟香蕉(cave_banana_cooked)
fruit:1	precook:1	

怪物肉干(monstermeat_dried)
dried:1	meat:1	monster:1	

小风干肉(smallmeat_dried)
dried:1	meat:0.5	

爆米花(corn_cooked)
veggie:1	precook:1	

nil(cutlichen_cooked)
veggie:1	precook:1	

煎高脚鸟蛋(tallbirdegg_cooked)
egg:4	precook:1	

采摘的红蘑菇(red_cap)
veggie:0.5	

-----------------食谱------------------------
portablecookpot
贻贝浓汤(musselbouillabaise): foodtype:MEAT health:20 hunger:37.5 sanity:15 

怪物鞑靼(monstertartare): foodtype:MEAT health:3 hunger:37.5 sanity:10 

甘薯蛋奶酥(sweetpotatosouffle): foodtype:VEGGIE health:20 hunger:37.5 sanity:15 

鲜果可丽饼(freshfruitcrepes): foodtype:VEGGIE health:60 hunger:150 sanity:15 


cookpot
香蕉冻(bananapop): foodtype:VEGGIE health:20 hunger:12.5 sanity:33 

热带鱼汤(tropicalbouillabaisse): foodtype:MEAT health:20 hunger:37.5 sanity:15 

鲜贝浓汤(bisque): foodtype:MEAT health:60 hunger:18.75 sanity:5 

怪物千层饼(monsterlasagna): foodtype:MEAT health:-20 hunger:37.5 sanity:-20 

酸橘汁腌鱼(ceviche): foodtype:MEAT health:20 hunger:25 sanity:5 

蛙腿三明治(frogglebunwich): foodtype:MEAT health:20 hunger:37.5 sanity:5 

水母冻(jellyopop): foodtype:MEAT health:20 hunger:12.5 sanity:0 

南瓜饼干(pumpkincookie): foodtype:VEGGIE health:0 hunger:37.5 sanity:15 

潮湿黏糊(wetgoop): foodtype:nil health:0 hunger:0 sanity:0 

鳗鱼料理(unagi): foodtype:MEAT health:20 hunger:18.75 sanity:5 

火鸡正餐(turkeydinner): foodtype:MEAT health:20 hunger:75 sanity:5 

炸鱼排(fishsticks): foodtype:MEAT health:40 hunger:37.5 sanity:5 

曼德拉草汤(mandrakesoup): foodtype:VEGGIE health:100 hunger:150 sanity:5 

培根煎蛋(baconeggs): foodtype:MEAT health:20 hunger:75 sanity:5 

鱼翅汤(sharkfinsoup): foodtype:MEAT health:40 hunger:12.5 sanity:-10 

华夫饼(waffles): foodtype:VEGGIE health:60 hunger:37.5 sanity:5 

辣椒炖肉(hotchili): foodtype:MEAT health:20 hunger:37.5 sanity:0 

水果圣代(fruitmedley): foodtype:VEGGIE health:20 hunger:25 sanity:5 

西瓜冰棍(watermelonicle): foodtype:VEGGIE health:3 hunger:12.5 sanity:20 

芝士蛋糕(powcake): foodtype:VEGGIE health:-3 hunger:0 sanity:0 

加州卷(californiaroll): foodtype:MEAT health:20 hunger:37.5 sanity:10 

龙虾汤(lobsterbisque): foodtype:MEAT health:60 hunger:25 sanity:10 

蔬菜杂烩(ratatouille): foodtype:VEGGIE health:3 hunger:25 sanity:5 

鱼肉玉米卷(fishtacos): foodtype:MEAT health:20 hunger:37.5 sanity:5 

炖肉汤(bonestew): foodtype:MEAT health:12 hunger:150 sanity:5 

鱼子酱(caviar): foodtype:MEAT health:3 hunger:12.5 sanity:33 

肉丸(meatballs): foodtype:MEAT health:3 hunger:62.5 sanity:5 

蝴蝶松饼(butterflymuffin): foodtype:VEGGIE health:20 hunger:37.5 sanity:5 

冰淇淋(icecream): foodtype:VEGGIE health:0 hunger:25 sanity:50 

果酱(jammypreserves): foodtype:VEGGIE health:3 hunger:37.5 sanity:5 

海鲜牛排(surfnturf): foodtype:MEAT health:60 hunger:37.5 sanity:33 

酿茄子(stuffedeggplant): foodtype:VEGGIE health:3 hunger:37.5 sanity:5 

鳄梨酱(guacamole): foodtype:MEAT health:20 hunger:37.5 sanity:0 

蜜汁卤肉(honeynuggets): foodtype:MEAT health:20 hunger:37.5 sanity:5 

海鲜浓汤(seafoodgumbo): foodtype:MEAT health:40 hunger:37.5 sanity:20 

什锦干果(trailmix): foodtype:VEGGIE health:30 hunger:12.5 sanity:5 

龙虾正餐(lobsterdinner): foodtype:MEAT health:60 hunger:37.5 sanity:50 

太妃糖(taffy): foodtype:VEGGIE health:-3 hunger:25 sanity:15 

波兰水饺(perogies): foodtype:MEAT health:40 hunger:37.5 sanity:5 

火龙果派(dragonpie): foodtype:VEGGIE health:40 hunger:75 sanity:5 

肉串(kabobs): foodtype:MEAT health:3 hunger:37.5 sanity:5 

花沙拉(flowersalad): foodtype:VEGGIE health:40 hunger:12.5 sanity:5 

咖啡(coffee): foodtype:VEGGIE health:3 hunger:9.375 sanity:-5 

蜜汁火腿(honeyham): foodtype:MEAT health:30 hunger:75 sanity:5 



饥荒Mod 开发(七):调试技巧
饥荒Mod 开发(九):物品栏排列

  • 23
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值