Overriding default "eat" behavior with register_on_item_eat

cronvel
Member
 
Posts: 18
Joined: Fri Jan 11, 2019 16:50
GitHub: cronvel

Overriding default "eat" behavior with register_on_item_eat

by cronvel » Thu Nov 14, 2019 13:04

I'm trying to code a small survival mod with hunger/thirst management (and more).
The documentation on minetest.register_on_item_eat() says that overriding the default behavior (healing) can be done if the callback return true but instead it crashes the game, or return an ItemStack but healing occurs nonetheless.

So how to procede to avoid healing using minetest.register_on_item_eat()?

While I will patch most edible items one by one with a code like this (and it works):
Code: Select all
if minetest.get_modpath("farming") then
    minetest.override_item("farming:bread", {
        on_use = survival_status.item_eat( { satiation = 8 } )
    })
end

... I would like a global behavior approach to avoid keeping track of all farming mods changes.

Any idea?
 

cronvel
Member
 
Posts: 18
Joined: Fri Jan 11, 2019 16:50
GitHub: cronvel

Re: Overriding default "eat" behavior with register_on_item_

by cronvel » Thu Nov 14, 2019 14:16

Ok, sorry, something went wrong with another mod.
Returning ItemStack prevents the default behavior, like it should.
However, returning true really crashes the game, like mentioned earlier.
The wiki doc must be fixed.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 4 guests