measure: Fix crash on punching air (#46)

This commit is contained in:
ANAND 2019-03-24 07:51:02 +05:30 committed by Billy S
parent 980b23f6ad
commit 79068f558c

View File

@ -15,24 +15,24 @@ minetest.register_craftitem("measure:stick", {
local name = user:get_player_name()
if not pointed_thing or pointed_thing.type == "object" then
if not pointed_thing or pointed_thing.type ~= "node" then
minetest.chat_send_player(name, "Please punch a valid node!")
return itemstack
return
end
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
local pos = minetest.get_pointed_thing_position(pointed_thing, "above")
if not pos then
minetest.chat_send_player(name, "Please punch a valid position!")
return
end
local meta = itemstack:get_meta()
local coord1 = meta:get_string("coord1")
local coord1 = meta:get("coord1")
if coord1 and coord1 ~= "" then
if coord1 then
coord1 = minetest.deserialize(coord1)
minetest.chat_send_player(name, ("Got node 2 at " .. (pos.x .. "," .. pos.y .. "," .. pos.z) .. ". Calculating..."))
local coord1 = minetest.deserialize(meta:get_string("coord1"))
coord1 = minetest.deserialize(meta:get_string("coord1"))
local coord2 = pos
local distance = vector.distance(coord1, coord2)
minetest.chat_send_player(name, ("--\nDistance: " .. distance .. " nodes.\n"..deltas_as_string(coord1, coord2)))