Jump to content

[Tutorial] Adding recipes to the crockpot


squeek

Recommended Posts

Note: For general information about adding recipes, look at the API Examples mod.

The code changes are no longer necessary, as they have been incorporated into Don't Starve as of the May 24th, 2014 patch (Rev. 102535)

Right now, Don't Starve does not have proper support for modded food being cooked in the crockpot; the food will be invisible after its done cooking (when its harvestable from the crockpot). There is this workaround, but it really breaks compatibility with mods/game updates in multiple ways.

Here is some code that will both fix the problem and will be compatible with other mods and game updates:

--[[	Add modded symbol switching support to cookpot stewer component]]--local function SwapToModdedProductAnim(inst, product)	if not inst:HasTag("burnt") then		local product = inst.components.stewer.product		if GLOBAL.ModManager:IsModdedCookerProduct(inst.prefab, product) then			inst.AnimState:OverrideSymbol("swap_cooked", product, product)		end	endendlocal function AddModdedCookpotProductSupport(inst)	if inst.components.stewer then		local ondonecooking_base = inst.components.stewer.ondonecooking		if ondonecooking_base then			inst.components.stewer.ondonecooking = function(inst)				ondonecooking_base(inst)				SwapToModdedProductAnim(inst)			end		end		local oncontinuedone_base = inst.components.stewer.oncontinuedone		if oncontinuedone_base then			inst.components.stewer.oncontinuedone = function(inst)				oncontinuedone_base(inst)				SwapToModdedProductAnim(inst)			end		end		local onspoil_base = inst.components.stewer.onspoil		if onspoil_base then			inst.components.stewer.onspoil = function(inst)				onspoil_base(inst)				SwapToModdedProductAnim(inst)			end		end	endendAddPrefabPostInit("cookpot", AddModdedCookpotProductSupport)--[[	Have ModManager keep track of recipes added by mods]]--local ModWrangler = GLOBAL.ModManager-- add a function to check if a product was added by a modfunction ModWrangler:IsModdedCookerProduct(cooker, name)	for i,modname in ipairs(self.enabledmods) do		local mod = self:GetMod(modname)		if mod.cookerrecipes and mod.cookerrecipes[cooker] and table.contains(mod.cookerrecipes[cooker], name) then			return true		end	end	return falseend-- add a table that will keep track of modded recipesenv.cookerrecipes = {}-- patch the environment's AddCookerRecipe function to keep track of modded recipeslocal AddCookerRecipe_base = env.AddCookerRecipe or function() endenv.AddCookerRecipe = function(cooker, recipe)	AddCookerRecipe_base(cooker, recipe)	if env.cookerrecipes[cooker] == nil then		env.cookerrecipes[cooker] = {}	end	if recipe.name then		table.insert(env.cookerrecipes[cooker], recipe.name)	endend

This code needs to be added to each mod that adds a recipe to the cookpot with a custom prefab as the result. To add it to your mod, create a file named "cookpotfix.lua" inside your mod folder's scripts folder (mods/<yourmodname>/scripts) and paste the above spoilered code into it. Then, in your modmain.lua, add the following line:

modimport("scripts/cookpotfix.lua")
Note: This line must be above any calls to AddCookerRecipe.

For the anim file of your prefab, the .zip must have the same name as the prefab and the build must have a symbol with the same name. If you're using Spriter, this means that you have to put your image(s) inside a subfolder with the same name as the prefab (example: <modfolder>/exported/testfood/testfood/image.png). Subfolder names are used to set the symbol names.

Your Palette window in Spriter should look like this (but testfood should be whatever your prefab's name is):

WP41OlQ.jpg

That's it. An example mod can be found here:

Example: Cookpot Fix

Obligatory screenshot:

h0unfI3.jpg

Link to comment
Share on other sites

Nice find, it works great. There is still the problem of it turning to rot immediately though, but I think I read that they will be fixing that.

 

Thanks again.

Yep, that should be fixed in some future patch. The bug report thread about it is here.
Link to comment
Share on other sites

We can add new crock pot food, but the question I have it is possbile to edit existing recipes?

I want  to make something like if there is monster meat in recipe then cook monster version of the dish, no monster meat make standart version.

Link to comment
Share on other sites

We can add new crock pot food, but the question I have it is possbile to edit existing recipes?

I want  to make something like if there is monster meat in recipe then cook monster version of the dish, no monster meat make standart version.

You could do that by adding the recipe with a higher priority than the default one.

To truly edit a recipe, though, you should be able to do:

local cooking = GLOBAL.require "cooking"local honeyham_recipe = cooking.recipes.cookpot.honeyham-- make honeyham uncookable using monster meatlocal honeyham_test_base = honeyham_recipe.testhoneyham_recipe.test = function(cooker, names, tags)    local couldcook = honeyham_test_base(cooker, names, tags)    return couldcook and not tags.monsterend
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...