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