MineClone5/mods/MISC/mcl_commands/setblock.lua

22 lines
821 B
Lua
Raw Normal View History

2021-03-05 09:47:48 +01:00
local S = minetest.get_translator("mcl_commands")
minetest.register_chatcommand("setblock", {
params = S("<X>,<Y>,<Z> <NodeString>"),
description = S("Set node at given position"),
privs = {give=true, interact=true},
func = function(name, param)
local p = {}
2021-04-15 23:41:34 +02:00
local nodestring
2021-03-05 09:47:48 +01:00
p.x, p.y, p.z, nodestring = param:match("^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) +(.+)$")
p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
if p.x and p.y and p.z and nodestring then
local itemstack = ItemStack(nodestring)
if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then
return false, S("Invalid node")
end
minetest.set_node(p, {name=nodestring})
return true, S("@1 spawned.", nodestring)
end
return false, S("Invalid parameters (see /help setblock)")
end,
})