Page 1 of 1

Programmatically get my posn

PostPosted: Thu Jun 23, 2016 04:46
by basil60
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!

Re: Programmatically get my posn

PostPosted: Thu Jun 23, 2016 11:54
by red-001
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)

Re: Programmatically get my posn

PostPosted: Fri Jun 24, 2016 04:46
by basil60
Thanks Red-001
So if I drop this into a mod, will blocks beneath my "feet" become clouds as I walk?

Basil

Re: Programmatically get my posn

PostPosted: Fri Jun 24, 2016 08:41
by oleastre
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

Re: Programmatically get my posn

PostPosted: Fri Jun 24, 2016 09:16
by red-001
dev.minetest.net is easier to read then the API documentation on github if you don't mind parts of it been outdated.