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!
Programmatically get my posn
Re: Programmatically get my posn
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)
My mods: Mute, Extra TNT blast effectsnyancats_plus and More charcommands
Example CSM mods:Chatlog and Formspec editor
Example CSM mods:Chatlog and Formspec editor
Re: Programmatically get my posn
Thanks Red-001
So if I drop this into a mod, will blocks beneath my "feet" become clouds as I walk?
Basil
So if I drop this into a mod, will blocks beneath my "feet" become clouds as I walk?
Basil
Re: Programmatically get my posn
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
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
dev.minetest.net is easier to read then the API documentation on github if you don't mind parts of it been outdated.
My mods: Mute, Extra TNT blast effectsnyancats_plus and More charcommands
Example CSM mods:Chatlog and Formspec editor
Example CSM mods:Chatlog and Formspec editor
Who is online
Users browsing this forum: Google [Bot] and 15 guests