Jump to content

Custom cookpot food not showing in cookpot

Recommended Posts

Edit: Solution found!


The solution was to remove the recipe & call to AddCookerRecipe from scripts/prefabs/applesauce.lua, leaving only the prefab code there, and create a new file called scripts/recipes.lua, which I then ensured loaded through my modmain.lua with a call to modimport("scripts/recipes.lua").




Hey friends

I'm making a mod which involves some custom food and recipes. I've got mostly everything worked out, but I have the problem that the cooked food isn't displaying in the cookpot when ready to be harvested.

I've seen there are other topics regarding this, from Lumina, the tutorial from Squeek, and a tutorial mod from Kuloslav. Also saw the text about when modded food animation was first enabled in the game, eliminating the need for a manual code fix

I've tried reusing the resources in the above examples and tutorials to make Lumina's chocolate, tried reusing assets from the PickleIt mod, and tried reusing assets from DST's included cook_pot_food animation build.


I must be completely oblivious to some small thing. In every case the inventory item displays correctly, and the proper animation is used as an idle animation when dropping the item on the ground. But in a total of zero cases have I gotten the food to show in the cookpot when finished cooking.

I even extracted the game's scripts.zip so they would be loaded and modified cookpot.lua's ShowProduct function to give me debug statements to ensure the correct food name was being passed to inst.AnimState:OverrideSymbol.

The relevant code in my Prefab:


The animation root in the .scml is called "food", it has an animation timeline within this root called "applesauce", and the resulting anim .zip is called "applesauce.zip". The animation plays correctly in Spriter, and a proper centered pivot point is set. I've decompiled Klei's cook_pot_food .bins using nsimplex's Krane from ktools to generate an .scml and ensured my .scml's underlying XML matched where necessary.

Does anybody have any further tips on what I could try or double check to maybe find out what I've missed?

Thanks for the help :)


Edited by Yuuvee
quoting solution in first post
Link to comment
Share on other sites

Very interesting, although I had added a debug print to check this, you asking me made me double check... And in the cooking.lua's ShowProduct, IsModCookingProduct is actually returning false, meaning OverrideSymbol is trying to grab from "cook_pot_food" rather than my anim.

local function ShowProduct(inst)
    print("cooked food "..inst.components.stewer.product)

    if not inst:HasTag("burnt") then
        local product = inst.components.stewer.product
        if IsModCookingProduct(inst.prefab, product) then
            print("IsModCookingProduct() -> true")
            inst.AnimState:OverrideSymbol("swap_cooked", product, product)
            print("IsModCookingProduct() -> false")
            inst.AnimState:OverrideSymbol("swap_cooked", "cook_pot_food", product)


So I checked the source for that in cooking.lua, did a quick print debug, and the mod.cookerrecipes table is totally empty. So the following if naturally returns false:

if mod.cookerrecipes and mod.cookerrecipes[cooker] and table.contains(mod.cookerrecipes[cooker], name) then

Am I adding my recipe incorrectly? The cookpot still actually cooks my food and with the ingredients I specify too. Here's my full applesauce prefab code.

require "tuning"

local assets = {
	Asset("ANIM", "anim/applesauce.zip"),
	Asset("ATLAS", "images/applesauce.xml"),
	Asset("IMAGE", "images/applesauce.tex"),

local function fn(Sim)
	print("creating an applesauce obj")
	local inst = CreateEntity()




	if not TheWorld.ismastersim then
		return inst



    inst.components.edible.healthvalue = 0
    inst.components.edible.hungervalue = TUNING.CALORIES_TINY
    inst.components.edible.sanityvalue = 0
    inst.components.edible.foodtype = FOODTYPE.VEGGIE

    inst.components.perishable.onperishreplacement = "spoiled_food"

    inst.components.stackable.maxsize = TUNING.STACK_SIZE_MEDITEM


    inst.components.inventoryitem.imagename = "applesauce"
    inst.components.inventoryitem.atlasname = "images/applesauce.xml"





	local applesauce = {
		name = "applesauce",
		test = function(cooker, names, tags) return names.apple and names.honey and tags.fruit >= 3 and tags.sweetener >= 1 end,
		priority = 100,
		weight = 100,
		perishtime = TUNING.PERISH_MED,
		cooktime = 0.15,
	AddCookerRecipe("cookpot", applesauce)

	return inst


return Prefab("common/applesauce", fn, assets) 

Specifically curious about lines 60-72. Is `AddCookerRecipe` really the proper method to call here? I'm going to dig in the code a little more and see if I can find where/when a mod's recipes are added to its mod.cookerrecipes table. Or maybe I have to do this myself in my mod code?


Thanks for taking a look :)



Edit: Oh, I also meant to say that I did find this snippet in modutil.lua, which looks like it should be the AddCookerRecipe method that I call, but my debug print call never actually fires, so I wonder if we're intended to use a different method to add a cooker recipe.

	env.cookerrecipes = {}
	env.AddCookerRecipe = function(cooker, recipe)
		print("env.AddCookerRecipe called with "..recipe.name)
		initprint("AddCookerRecipe", cooker, recipe.name)
		AddCookerRecipe(cooker, recipe)
		if env.cookerrecipes[cooker] == nil then
	        env.cookerrecipes[cooker] = {}
	    if recipe.name then
	        table.insert(env.cookerrecipes[cooker], recipe.name)


Edited by Yuuvee
More detail
Link to comment
Share on other sites

Inside cooking.lua there is a function

function AddCookerRecipe(cooker, recipe)
	if not cookerrecipes[cooker] then
		cookerrecipes[cooker] = {}
	cookerrecipes[cooker][recipe.name] = recipe

It should work fine, if you are overriding this file too, check if the function is correct, and/or try to debug inside this function to make sure your code is calling it, printing all recipes added, or something like that you should be able to see if its adding or not.

If it's not adding, try to debug before your call of this, something should be blocking the call, otherwise it should work fine.


That code you post, wont call the correct AddCookerRecipe, also don't require "cooking.lua" as it will "erase" the table calling the "local cookerrecipes = {}" code, or if you do need to require, require it first hand, not on everycall you make to AddCookerRecipe.

Link to comment
Share on other sites

I fixed it! Thanks so much for the help caioketo :)

Any calls to require cooking were already there in the base game code, I just added some prints. You were right though, the other AddCookerRecipe was being called. It seems the root of the problem was how I was creating my recipe. I mistakenly had it inside of the prefab code, which was causing AddCookerRecipe to be called on each instantiation of an applesauce object, and the game didn't like that for whatever reason.


The solution was to remove the recipe & call to AddCookerRecipe from scripts/prefabs/applesauce.lua, leaving only the prefab code there, and create a new file called scripts/recipes.lua, which I then ensured loaded through my modmain.lua with a call to modimport("scripts/recipes.lua").


The recipe is added once on mod load, the mod.cookerrecipes table becomes populated, and my anim displays correctly in the cookpot upon being cooked. Thanks again :D 

Link to comment
Share on other sites

On 1/7/2018 at 5:20 PM, Yuuvee said:

The solution was to remove the recipe & call to AddCookerRecipe from scripts/prefabs/applesauce.lua, leaving only the prefab code there, and create a new file called scripts/recipes.lua, which I then ensured loaded through my modmain.lua with a call to modimport("scripts/recipes.lua").

I'm having the exact same problem you were, but I'm not sure I understand how you fixed it. Correct me if I'm wrong but you did this right?

1 - Created recipes.lua and moved the string crockpot recipe string(s) there

2 - At the end of applesauce.lua you added a line that read, "AddCookerRecipe("cookpot", applesauce)"

3 - Had the modmain call for recipes.lua in the PrefabFiles section near the top.


Am I correct? Or is there something wrong here?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...