Hello!
I have some question about tools. I have tool which displays some HUD. When on_use is called, I can modify this HUDs. But I didn't find callback for switching to other tool. But i need to hide HUD when the tool is deselected. How can i do this?
Tools events in mods
Re: Tools events in mods
there is no such callback, because switching hand items is mostly done client-side. You need to periodically check what item a client has wielded by inspecting the player through the various inventory methods instead.vladts wrote:Hello!
I have some question about tools. I have tool which displays some HUD. When on_use is called, I can modify this HUDs. But I didn't find callback for switching to other tool. But i need to hide HUD when the tool is deselected. How can i do this?
- sorcerykid
- Member
- Posts: 1847
- Joined: Fri Aug 26, 2016 15:36
- GitHub: sorcerykid
- In-game: Nemo
- Location: Illinois, USA
Re: Tools events in mods
If wield item changes are handled entirely client-side, then how does the API function minetest.get_wielded_item( ) work? I took a quick glance at src/network/serverpackethandler.cpp, and the server is clearly notified of player item events:sofar wrote: there is no such callback, because switching hand items is mostly done client-side. You need to periodically check what item a client has wielded by inspecting the player through the various inventory methods instead.
Code: Select all
void Server::handleCommand_PlayerItem(NetworkPacket* pkt)
{
if (pkt->getSize() < 2)
return;
Player *player = m_env->getPlayer(pkt->getPeerId());
if (player == NULL) {
errorstream << "Server::ProcessData(): Canceling: "
"No player for peer_id=" << pkt->getPeerId()
<< " disconnecting peer!" << std::endl;
m_con.DisconnectPeer(pkt->getPeerId());
return;
}
PlayerSAO *playersao = player->getPlayerSAO();
if (playersao == NULL) {
errorstream << "Server::ProcessData(): Canceling: "
"No player object for peer_id=" << pkt->getPeerId()
<< " disconnecting peer!" << std::endl;
m_con.DisconnectPeer(pkt->getPeerId());
return;
}
u16 item;
*pkt >> item;
playersao->setWieldIndex(item);
}
Re: Tools events in mods
totally agreed.sorcerykid wrote: Unless I missed something, a callback should therefore be extremely easy to implement in the engine. And it would undoubtedly streamline a number of mods (like 3d_armor and wield3d) that need to constantly poll this information.
https://github.com/minetest/minetest/issues/1377
- sorcerykid
- Member
- Posts: 1847
- Joined: Fri Aug 26, 2016 15:36
- GitHub: sorcerykid
- In-game: Nemo
- Location: Illinois, USA
Re: Tools events in mods
Ah thanks for that link :D After endless searching of Google, for some reason it never turned up that issue.
I'll give it a read, and see if maybe I could help or contribute in some way to get this rolling!
I'll give it a read, and see if maybe I could help or contribute in some way to get this rolling!
Re: Tools events in mods
there's a link to a PR in that thread that's currently pending. I've expressed my support for it, it's fairly trivial, so, let's hope it gets merged.sorcerykid wrote:Ah thanks for that link :D After endless searching of Google, for some reason it never turned up that issue.
I'll give it a read, and see if maybe I could help or contribute in some way to get this rolling!
Who is online
Users browsing this forum: No registered users and 8 guests