Programmatically get my posn

basil60
Member
 
Posts: 54
Joined: Sat Sep 12, 2015 22:07

Programmatically get my posn

by basil60 » Thu Jun 23, 2016 04:46

Hi
can I programmatically get the position of the block I'm standing on in Minetest?
I'd like to work on my first mod to change the block beneath me to another type. Gotta start somewhere!
 

red-001
Member
 
Posts: 126
Joined: Tue Jan 26, 2016 20:15
GitHub: red-001
IRC: red-001

Re: Programmatically get my posn

by red-001 » Thu Jun 23, 2016 11:54

You can get the position of the a player and then calculate the position of the node below them based on that.
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_joinplayer(function(player)
   local pos = player:getpos()
   pos.y = pos.y-1
   minetest.set_node(pos, {name="default:cloud"})
end)
 

basil60
Member
 
Posts: 54
Joined: Sat Sep 12, 2015 22:07

Re: Programmatically get my posn

by basil60 » Fri Jun 24, 2016 04:46

Thanks Red-001
So if I drop this into a mod, will blocks beneath my "feet" become clouds as I walk?

Basil
 

User avatar
oleastre
Member
 
Posts: 81
Joined: Wed Aug 13, 2014 21:39
GitHub: oleastre
In-game: oleastre

Re: Programmatically get my posn

by oleastre » Fri Jun 24, 2016 08:41

This will only work when the player joins the game, not when you are walking.

If you want to make it work while you are walking, have a look how it's done for the wielded torch light in the torches mod: viewtopic.php?f=11&t=14359

The basic of getting the player position is to get a reference to the player object. And there are many ways in minetest to get a player reference:
- when it connects/disconnects
- when it interact with a node
- when it uses some tools
...

All infos are in the api documentation https://github.com/minetest/minetest/bl ... ua_api.txt or in rubenwardy's modding book http://rubenwardy.com/minetest_modding_ ... a_api.html
 

red-001
Member
 
Posts: 126
Joined: Tue Jan 26, 2016 20:15
GitHub: red-001
IRC: red-001

Re: Programmatically get my posn

by red-001 » Fri Jun 24, 2016 09:16

dev.minetest.net is easier to read then the API documentation on github if you don't mind parts of it been outdated.
 


Return to Minetest General

Who is online

Users browsing this forum: No registered users and 44 guests

cron