squeek Posted March 15, 2014 Share Posted March 15, 2014 (edited) 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) endendThis 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):That's it. An example mod can be found here:Example: Cookpot FixObligatory screenshot: Edited May 24, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32910-tutorial-adding-recipes-to-the-crockpot/ Share on other sites More sharing options...
UnderwearApp Posted March 15, 2014 Share Posted March 15, 2014 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. Link to comment https://forums.kleientertainment.com/forums/topic/32910-tutorial-adding-recipes-to-the-crockpot/#findComment-432363 Share on other sites More sharing options...
squeek Posted March 15, 2014 Author Share Posted March 15, 2014 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 https://forums.kleientertainment.com/forums/topic/32910-tutorial-adding-recipes-to-the-crockpot/#findComment-432366 Share on other sites More sharing options...
_Q_ Posted March 15, 2014 Share Posted March 15, 2014 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 https://forums.kleientertainment.com/forums/topic/32910-tutorial-adding-recipes-to-the-crockpot/#findComment-432371 Share on other sites More sharing options...
squeek Posted March 15, 2014 Author Share Posted March 15, 2014 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 https://forums.kleientertainment.com/forums/topic/32910-tutorial-adding-recipes-to-the-crockpot/#findComment-432386 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now