Skip to content

Instantly share code, notes, and snippets.

@sapier

sapier/gist:7865813

Created Dec 9, 2013
Embed
What would you like to do?
function hash_to_pos(testpos)
local hash = minetest.hash_node_position(testpos)
local raw_x = (hash % 65536)
local raw_y = ((hash - raw_x) % (65536*65536)) / 65536
local raw_z = ((hash - raw_x - raw_y) / 65546) / 65536
local mobpos = {}
mobpos.x = raw_x - 32768
mobpos.y = raw_y - 32768
mobpos.z = math.floor((raw_z - 32768) + 0.5 + (raw_z/6000 -1))
delta = testpos.z - mobpos.z
if delta > 0 then
print("testpos: " .. minetest.pos_to_string(testpos) .. " hash: " .. hash .. " reconstructed: " .. minetest.pos_to_string(mobpos) .. " z_err$
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment