I think other mods have already tried to do this, maybe look at
Food Buff Observer created by @RepeatPan he would probably know as he is referenced as helping a lot in these kinds of mods
I would dare say I didn’t just try, but actually succeeded in that. I’m not uptodate, so this might be outdated info.
For a “simple” implementation, check out Frostfeast, especially frostfeast/ai/observers/food_buff_observer.lua. Basic idea is to have an observer hooked to the eat event, then add some entity-data to each food that depicts which buff to add. Add the observer to the hearthling, and watch the thing go. Unless SH ships now with an observer, you’ll need to add one yourself. Keep in mind that this might conflict with other mods (e.g. if you’re using Frostfeast’s observer, then when using Frostfeast, the Cook Mod and your mod, the buff could be added three times/do weird stuff, although I think buffs are kind of singleton-ish in SH?).
Thanks guys, I am actually looking at Cafe mod. I liked it but I didn’t like the thirst and the abundant food types.
I also just saw the observer thingy lol. I am not good at this at all.
Edit: I got the buff to work through potions but can’t get it to work through eating lol. (Tested through potions just to make sure the buff worked. Prob something with the Observer.
–Called first every time
function FoodBuffObserver:initialize()
– list all the saved variables
self._sv.entity = nil
end
–Called once on creation
function FoodBuffObserver:create(entity)
self._sv.entity = entity
end
–Always called. If restore, called after restore.
function FoodBuffObserver:activate()
–Wait for eat event.
self._entity = self._sv.entity
self._eat_listener = radiant.events.listen(self._entity, ‘stonehearth:eat_food’, self, self._on_eat)
end
function FoodBuffObserver:_on_eat(e)
– Check the food’s entity data
local food_data = radiant.entities.get_entity_data(e.food_uri, ‘stonehearth:food’)
if not food_data then
return
end
-- Check if there's a buff attached to it
local food_buff = food_data.buff_uri
-- If it is, give it to the worker
if food_buff then
radiant.entities.add_buff(self._entity, food_buff)
end
end
function FoodBuffObserver:destroy()
if self._eat_listener then
self._eat_listener:destroy()
self._eat_listener = nil
end
end
Hi, me again, now, I am trying to add a simple item, but Stonehearth doesn’t see the mod. When the game loads, i can’t change or edit the names of other mod files, but I can change mines meaning Stonehearth doesn’t see it. Any clue?
Thanks for the reply and help Hamnisu, but, where would that be under settings? I don’t see anything about mods.
Thanks!
Never mind I see it. I think I am not creating the smod file correctly. I zip the folder and rename it “.smod”. I don’t think that is how it is supposed to be done lol.
Edit: LMAO, found a file called, Stonehearth.log… completely told me what was wrong. Modding is better with errors logs.