How to get player highlighted node?

Post Reply
User avatar
xeranas
Member
Posts: 162
Joined: Fri Feb 05, 2016 11:06

How to get player highlighted node?

by xeranas » Post

When player pointed to node then node becomes with borders or highlighted I would like to get meta data (at least node name) about that node. I must be missed on lua API documentation. Anyone can point me to right API to achieve what I looking?

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: How to get player highlighted node?

by stu » Post

xeranas wrote:When player pointed to node then node becomes with borders or highlighted I would like to get meta data (at least node name) about that node. I must be missed on lua API documentation. Anyone can point me to right API to achieve what I looking?
This is possible with ray-casting https://github.com/minetest/minetest/bl ... .txt#L2720
Simply cast a ray along the player's line of sight and return the first blocking node/object. However, since this is server-side, there may be some discrepancy between client and server due to lag.

Client side modding might be better suited to this task as the pointed node info is already known by the client and is available in the F5 debug info. I am not sure if this is accessible with current CSM but I believe it has been suggested.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: How to get player highlighted node?

by Byakuren » Post

Should note that minetest.raycast is not available in the stable version.
Every time a mod API is left undocumented, a koala dies.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: How to get player highlighted node?

by stu » Post

Byakuren wrote:Should note that minetest.raycast is not available in the stable version.
That is a very fair and valid point, if backwards compatibility is a concern then you could use good old `minetest.line_of_sight` to the same end, however, this does not have the same selection-box level of accuracy as `minetest.raycast` and cannot detect entities.

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: How to get player highlighted node?

by Linuxdirk » Post

It is called the "pointed thing".

http://dev.minetest.net/pointed_thing

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: How to get player highlighted node?

by stu » Post

Linuxdirk wrote:It is called the "pointed thing".

http://dev.minetest.net/pointed_thing
Admittedly, the OP does not say that they require this information without using a tool to click on the highlighted node. If that is not the case then `pointed_thing` might well be what they are looking for.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: How to get player highlighted node?

by Byakuren » Post

He says that he wants to know the metadata of nodes when the user looks at them ("becomes with borders or highlighted"), which I think means before the player clicks on it. But it also doesn't look like he needs an intersection point, so minetest.line_of_sight would probably suffice.
Every time a mod API is left undocumented, a koala dies.

User avatar
xeranas
Member
Posts: 162
Joined: Fri Feb 05, 2016 11:06

Re: How to get player highlighted node?

by xeranas » Post

Thanks for answers I probably try both variants and see how its goes. Ideally for my case it would be perfect something like "player.get_pointed_thing(above)" as I would like to know 'pointed_thing' before actually using tool. I feel that it is bit unwise in performance to re-calculate 'my pointed node' via other generic purpose api methods like minetest.line_of_sight / minetest.raycast to get what engine already knows, F5 pointing_at tells exacly what node I'm pointing at.

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: How to get player highlighted node?

by Krock » Post

xeranas wrote:F5 pointing_at tells exacly what node I'm pointing at.
While this is true for the client-sided modifications, it won't work for server mods, as the server does not calculate the pointed node of each player. Notice that the raycast function/object can also be used to calculate the shooting line of an object, if the collision detection is too inefficient/slow for this task.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: How to get player highlighted node?

by Linuxdirk » Post

xeranas wrote:as I would like to know 'pointed_thing' before actually using tool.
What's wrong with getting the pointed_thing when using the tool and then decide in the tool's function what to do?

User avatar
xeranas
Member
Posts: 162
Joined: Fri Feb 05, 2016 11:06

Re: How to get player highlighted node?

by xeranas » Post

Linuxdirk wrote:
xeranas wrote:as I would like to know 'pointed_thing' before actually using tool.
What's wrong with getting the pointed_thing when using the tool and then decide in the tool's function what to do?
To my understanding you must use mouse click to invoke callback where 'pointed' object will be returned. That alone is big restriction. If I would need mark-and-perform action it would take 3 steps: 1 select correct tool, 2 mouse click to invoke on use (perform mark action), 3 mouse click to invoke un_use (check if there marked area then perform action, mark otherwise). IMO it would be useless 'helper' category tool if I would need at least 2 mouse clicks to perform simple action.

I was thinking about mod similar to builders wand*:
https://youtu.be/_hDrbP7ql40?t=9m40s

The main thing what I like about builders wand is it let player fast see where blocks will be placed before it actually placed (without additional mouse/keyboard clicks).

*let me know if such mod exist on minetest

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: How to get player highlighted node?

by stu » Post

xeranas wrote: I was thinking about mod similar to builders wand*:
https://youtu.be/_hDrbP7ql40?t=9m40s

The main thing what I like about builders wand is it let player fast see where blocks will be placed before it actually placed (without additional mouse/keyboard clicks).
Unfortunately, I am not sure either method would be suitable for this due the aforementioned lag. Something like this would currently need to be done in the engine itself, however, it may one day be possible using CSM. This is, after all, what client-side modding should be good for.

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: How to get player highlighted node?

by Linuxdirk » Post

All the information is already there (debug screen). it just has to be made accessible via the API.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: How to get player highlighted node?

by stu » Post

Linuxdirk wrote:All the information is already there (debug screen). it just has to be made accessible via the API.
Indeed, that and a way to produce the visuals without (ab)using server-side entities.

Post Reply

Who is online

Users browsing this forum: rudzik8 and 6 guests