feature request: register_on_use

User avatar
addi
Member
 
Posts: 605
Joined: Thu Sep 20, 2012 03:16

feature request: register_on_use

by addi » Sun Nov 16, 2014 01:40

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
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: feature request: register_on_use

by Krock » Sun Nov 16, 2014 09:19

I like this idea, but it would be better when the register_on_punchnode is called after on_use
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: feature request: register_on_use

by rubenwardy » Sun Nov 16, 2014 10:23

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
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 7 guests

cron