add howlight command

This commit is contained in:
poikilos 2019-06-05 14:52:46 -04:00
parent ad4dffe594
commit 14021606d5
2 changed files with 25 additions and 7 deletions

17
chatcommands.lua Normal file
View File

@ -0,0 +1,17 @@
minetest.register_chatcommand("howlight", {
description = "Show the light level of the ground below you",
func = function(name)
local player = minetest.get_player_by_name(name)
if player then
local player_pos = vector.round(player:get_pos())
-- local pos = vector.new(player_pos.x, player_pos.y - 1 , player_pos.z)
local pos = player_pos
-- underground, light is always zero, so z-1 doesn't work.
local pos_string = minetest.pos_to_string(pos)
minetest.chat_send_player(name, "Light level at " .. pos_string .. " is " .. minetest.get_node_light(pos) .. ".")
return true
else
return false, "You are not connected to minetestserver."
end
end
})

View File

@ -20,6 +20,7 @@ local nodelock = {}
local modpath = minetest.get_modpath("metatools")
dofile(modpath .. "/assertions.lua")
dofile(modpath .. "/chatcommands.lua")
minetest.register_craftitem("metatools:stick",{
description = "Meta stick",
@ -162,7 +163,7 @@ function meta_exec(struct)
for category, req in pairs(struct.required) do
if category == "position" and not assert_pos(req) then
return false, ("- %s - Failure : Invalid position : %s"):format(struct.scope, dump_normalize(req))
elseif category == "contextid" and not assert_contextid(req) then
return false, ("- %s - Failutre : Invalid contextid : %s"):format(struct.scope, dump_normalize(req))
@ -215,7 +216,7 @@ function meta_exec(struct)
if not assert_contextid(req.contextid) then
return false, ("- %s - Failure : Invalid context id : %s"):format(struct.scope, dump_normalize(req.contextid))
end
if not metatools.contexts[req.contextid].mode == req.mode then
return false, ("- %s - Failure : Invalid mode, %s is required"):format(struct.scope, dump_normalize(req.mode))
end
@ -350,7 +351,7 @@ function metatools.purge(contextid)
local inv = meta:get_inventory()
inv:set_lists({})
return true, "inventory purged"
else
meta:from_table(nil)
return true, "fields purged"
@ -543,7 +544,7 @@ minetest.register_chatcommand("meta", {
format(summ.id, summ.mode, minetest.pos_to_string(summ.pos), summ.owner)
end
return true, retstr .. ("- meta::contexts - %d contexts"):format(#ctxs)
-- meta open (x,y,z) [fields|inventory]
elseif params[1] == "open" then
@ -702,7 +703,7 @@ minetest.register_chatcommand("meta", {
}
}
})
-- meta purge
elseif params[1] == "purge" then
return meta_exec({
@ -782,7 +783,7 @@ minetest.register_chatcommand("meta", {
}
}
})
else
return false, "- meta::list - Unknown subcommand '" .. params[2] .. "', please consult '/meta help' for help"
end
@ -822,7 +823,7 @@ minetest.register_chatcommand("meta", {
}
}
})
-- meta itemstack add <itemstack>
elseif params[2] == "add" then
return meta_exec({