Page 1 of 1

feature request: register_on_use

PostPosted: Sun Nov 16, 2014 01:40
by addi
there should be a function which is caled, when somebody uses an item.
register_on_punchnode does not work here, because only in itemdef. on_use is caled.

Example problem:

you have an node "mymod:barrel_water" placed somewhere in the landscape.
now you want to check if this "mymod:barrel_water" is punched with "bucket:bucket_empty", --> replace "bucket:bucket_empty" with "bucket:bucket_water"

using on_punchnode or register_on_punch does not work here, because its not caled.

the solution could be to override the bucket, but if another mod wants todo the same, they conflict together.

so there is need for an register_on_use function wich is also caled if an item is used.

example:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_on_use(function(item [itemStack], node [node], user [Player], pointed_thing[pt])

   if item:get_name() == "bucket:bucket_empty"
   and node.name == "mymod:barrel_water" then
      user:set_wielded_item("bucket:bucket_water")
   end
end)


would be great to see something like that in 0.4.11

Re: feature request: register_on_use

PostPosted: Sun Nov 16, 2014 09:19
by Krock
I like this idea, but it would be better when the register_on_punchnode is called after on_use

Re: feature request: register_on_use

PostPosted: Sun Nov 16, 2014 10:23
by rubenwardy
They won't necessarily conflict.

Pseudo code:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
bucket = get bucket def
old func = bucket.on_use
bucket.on_use = function(one, two, three)
    -- do stuff
    call old func with one, two, three
end