Page 1 of 1

on_wielditem_change Lua function

PostPosted: Sun Jun 15, 2014 19:04
by MirceaKitsune
Thread for issue #1377:

Today I discovered stu's fantastic 3D-Armor mod. Which doesn't only add an armor system that reduces damage, but also the long awaited features of showing worn armor and the wielded item on the player model, allowing other players to see what you are wearing or holding!

Although the armor system works well and efficiently, engine limitations make it difficult to find a good way of handling wielded items. The server needs to periodically check when a player changed the selected item on the hotbar, which is laggy and costly.

Please add a Lua function that gets triggered when the item held by a player changes, and reports the new and possibly old item. It should typically execute when the player selects another hotbar slot which contains another item, or if an item was added / removed to / from the selected hotbar slot.

Visible wielded items are difficult to implement in a quick and cheap way without this. Even if it's for 3D-Armor or any other mod that implements them, an engine function to make it possible is essential in my opinion. Here's an example of what I'm thinking:

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.on_wielditem_change(player, old_item, new_item)
   mod.change_wielditem_appearance(player:get_player_name(), new_item)
end

Re: on_wielditem_change Lua function

PostPosted: Mon Jun 16, 2014 09:50
by 4aiman
For this to be possible as a feature, devs should consider changing the default model with more sophisticated one (which is used by 3d_armor, for example). Sadly, that had been discussed with no positive outcome.

Just imagine, that the engine would need to store all wielded items for every player. That will decrease speed. 3d_armor decreases speed too, but optionally.

So, I think that we should come up with a good deal of reasons for this to be not only implemented but added too.

Celeron55 had shown the if-this-could-be-used-for-many-causes-then-it's-a-good-addition attitude. Maybe that's not true nowadays, but think for more reasons.

BTW, Freeminer devs proposed an addition of statistics. Maybe your idea will find it's place there before hitting the Minetest engine. Imagine, being able to differentiate one's class or skill growth based on the time spent on some kind of a tool.