[mod] (sorta) Depth Finder - command to get your y axis, in game
After installing More Ores and digging deep into the bowels of the earth, I began to really regret not having a way to calculate my depth. I mean, I felt like I'd been digger for an eternity, but how close was I to the mystical Mithril layer?
For that matter, what about the depths of mese and lava. Though I can't currently figure out how deep they normally are (even by searching the source), I'm sure if I did it would only make my desire to know my depth even stronger.
After a bit of reading up on Lua and scraping code from other mods, here is what I came up with (works):
The "- 0.5" is necessary to give the expected whole number value, likely because depth is calculated from the head / camera (don't know though).
Anyway, enjoy.
For that matter, what about the depths of mese and lava. Though I can't currently figure out how deep they normally are (even by searching the source), I'm sure if I did it would only make my desire to know my depth even stronger.
After a bit of reading up on Lua and scraping code from other mods, here is what I came up with (works):
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_chatcommand("depth", {
params = "",
description = "depth: Get current depth",
func = function(name, param)
local player = minetest.env:get_player_by_name(name)
if not player then
return
end
depth = (player:getpos()).y - 0.5;
minetest.chat_send_player(name, "You are currently "..(math.abs(depth)).." blocks "..(depth < 0 and 'below' or 'above').." sea level");
end,
})
The "- 0.5" is necessary to give the expected whole number value, likely because depth is calculated from the head / camera (don't know though).
Anyway, enjoy.