Programmatically get my posn

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

Programmatically get my posn

by basil60 » Post

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: 205
Joined: Tue Jan 26, 2016 20:15
GitHub: red-001
IRC: red-001

Re: Programmatically get my posn

by red-001 » Post

You can get the position of the a player and then calculate the position of the node below them based on that.

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 » Post

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 » Post

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: 205
Joined: Tue Jan 26, 2016 20:15
GitHub: red-001
IRC: red-001

Re: Programmatically get my posn

by red-001 » Post

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

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests