[solved] Can you detect node and get its location

User avatar
Semmett9
Member
 
Posts: 149
Joined: Sun Oct 07, 2012 13:48

[solved] Can you detect node and get its location

by Semmett9 » Mon Oct 17, 2016 17:22

I am making a mod which detects the node above it and if its air it replaces it with a node.

so lets say I have a node (default:dirt) at 0,0,0
when i hit this done (with on_punch) it checks the node at 0,1,0
After this it checks what the node at 0,1,0 and if its air it places a node there (default:dirt)

What i have tried'

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
pos.y = pos.y + 1;
if minetest.find_node_near(
{x = pos.x, y = pos.y + height, z = pos.z }, 1, {"default:dirt"}) then

The code above works but you cannot put two nodes together since since it looks for the dirt in X, Y and Z

So if i place a node at 0,0,0 then hit it it will place a node at 0,1,0
However if i place a node at 0,0,1 it will detect the node at 0,0,0 and 0,1,0 and not place a node.


I have also the code shown below but it just crashes the game

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
 if minetest.find_node_in_area(
{x = pos.x, y = pos.y, z = pos.z },
{x = pos.x, y = pos.y, z = pos.z },
{"scaffolding:scaffolding"}) then


If anyone knows how to solve the problem feel free to reply.

many thanks
Last edited by Semmett9 on Mon Oct 17, 2016 19:53, edited 1 time in total.
 

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

Re: Can you detect node and get its location

by rubenwardy » Mon Oct 17, 2016 19:25

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
local target_pos = { x = pos.x, y = pos.y, z = pos.z }
target_pos.y = target_pos.y + 1
local node = minetest.get_node(target_pos)


will get the node above pos. you can then do:

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
if node.name == "air" then
    minetest.set_node(target_pos, { name = "default:dirt" })
end


to replace the node above with dirt if it is air
 

User avatar
Semmett9
Member
 
Posts: 149
Joined: Sun Oct 07, 2012 13:48

Re: Can you detect node and get its location

by Semmett9 » Mon Oct 17, 2016 19:52

rubenwardy wrote:
+ Spoiler


Thanks for the help
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 7 guests

cron