From 0d3147b13d53d9c84eb33c92b65bd4333aafb939 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 9 Mar 2021 00:57:13 +0100 Subject: [PATCH] add 2 more patterns types (WIP) --- mods/CORE/mcl_commands/API.md | 2 -- mods/CORE/mcl_commands/init.lua | 14 +++++++++++++- mods/CORE/mcl_commands/mod.conf | 2 +- mods/MISC/mcl_basic_commands/setblock.lua | 12 ++++-------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/mods/CORE/mcl_commands/API.md b/mods/CORE/mcl_commands/API.md index 013fb0809..41ef2d02d 100644 --- a/mods/CORE/mcl_commands/API.md +++ b/mods/CORE/mcl_commands/API.md @@ -68,7 +68,5 @@ If not specified, a value will be by default with the word pattern. * alphanumeric * username: value must be a valid username * json: value must be a json string (will be parsed automaticaly) - -TODO: * color value must be a color string or a valid named color * nodename value must be a valid node name diff --git a/mods/CORE/mcl_commands/init.lua b/mods/CORE/mcl_commands/init.lua index 1c143731e..755b5def9 100644 --- a/mods/CORE/mcl_commands/init.lua +++ b/mods/CORE/mcl_commands/init.lua @@ -22,7 +22,9 @@ mcl_commands.types = { alphascore = "([A-Za-z_]+)", alphanumeric = "([A-Za-z0-9]+)", username = "([A-Za-z0-9-_]+)", - json = "(.+)", + json = "(.+)", --FIXME + color = "([^ ]+)", --FIXME + nodename = "([A-Za-z_]+)", } function mcl_commands.register_command(name, def) @@ -201,6 +203,16 @@ function mcl_commands.build(name, chat_def) elseif param == "json" then table.insert(params, parse_json(res[pointer])) pointer = pointer + 1 + elseif param == "color" then + table.insert(params, mcl_util.get_color(res[pointer])) + pointer = pointer + 1 + elseif param == "nodename" then + if minetest.registered_nodes[res[pointer]] then + table.insert(params, res[pointer]) + pointer = pointer + 1 + else + return false, S("Param "..pointer.." must be a valid nodename!") + end else table.insert(params, res[pointer]) pointer = pointer + 1 diff --git a/mods/CORE/mcl_commands/mod.conf b/mods/CORE/mcl_commands/mod.conf index 247ea2164..667eb79bf 100644 --- a/mods/CORE/mcl_commands/mod.conf +++ b/mods/CORE/mcl_commands/mod.conf @@ -1,6 +1,6 @@ name = mcl_commands author = AFCMS description = MCL2 commands API -depends = mcl_colors +depends = mcl_colors, mcl_util optional_depends = diff --git a/mods/MISC/mcl_basic_commands/setblock.lua b/mods/MISC/mcl_basic_commands/setblock.lua index a092dfe69..8d6e124e5 100644 --- a/mods/MISC/mcl_basic_commands/setblock.lua +++ b/mods/MISC/mcl_basic_commands/setblock.lua @@ -2,14 +2,10 @@ local S = minetest.get_translator("mcl_commands") mcl_commands.register_command("setblock", { func = function(cmd) - cmd:sub(":pos:pos :node:text", { --TODO:replace by upcomming nodename type - func = function(name) - local itemstack = ItemStack(nodestring) - if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then - return false, S("Invalid node") --workaround - end - minetest.set_node(p, {name=nodestring}) - return true, S("@1 spawned.", nodestring) + cmd:sub(":pos:pos :node:nodename", { + func = function(name, pos, node) + minetest.set_node(pos, {name=node}) + return true, S("@1 spawned.", node) --return false, S("Invalid parameters (see /help setblock)") end, privs = {},