From 63949950bdc0719ff53197afea71cf5c30222c62 Mon Sep 17 00:00:00 2001 From: kilbith Date: Tue, 12 Jan 2016 14:27:13 +0100 Subject: [PATCH] Small simplifications --- chess.lua | 4 ++-- enchanting.lua | 2 +- mailbox.lua | 6 +++--- worktable.lua | 23 ++++++++++++----------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/chess.lua b/chess.lua index 2b02094..5d08f86 100644 --- a/chess.lua +++ b/chess.lua @@ -528,10 +528,10 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, count, pl if meta:get_string("lastMove") == "black" then minetest.chat_send_player(playerWhite, "["..os.date("%H:%M:%S").."] ".. - playerName.." has moved a "..pieceFrom:match("%a+:(%a+)")..", it's now your turn.") + playerName.." has moved a "..pieceFrom:match(":(.-)%_")..", it's now your turn.") elseif meta:get_string("lastMove") == "white" then minetest.chat_send_player(playerBlack, "["..os.date("%H:%M:%S").."] ".. - playerName.." has moved a "..pieceFrom:match("%a+:(%a+)")..", it's now your turn.") + playerName.." has moved a "..pieceFrom:match(":(.-)%_")..", it's now your turn.") end if pieceTo:find("king") then diff --git a/enchanting.lua b/enchanting.lua index b6c10a5..3aad80a 100644 --- a/enchanting.lua +++ b/enchanting.lua @@ -56,7 +56,7 @@ function enchanting.fields(pos, _, fields) local tool = inv:get_stack("tool", 1) local mese = inv:get_stack("mese", 1) local orig_wear = tool:get_wear() - local mod, name = tool:get_name():match("([%w_]+):([%w_]+)") + local mod, name = tool:get_name():match("(.*):(.*)") local enchanted_tool = mod..":enchanted_"..name.."_"..next(fields) if mese:get_count() > 0 and minetest.registered_tools[enchanted_tool] then diff --git a/mailbox.lua b/mailbox.lua index 28c4595..1f99e14 100644 --- a/mailbox.lua +++ b/mailbox.lua @@ -77,9 +77,9 @@ xdecor.register("mailbox", { local function img_col(stack) if not stack then return "" end if stack.inventory_image ~= "" then - return stack.inventory_image:match("([%w_]+)%.png")..".png" + return stack.inventory_image:match("(.*)%.png")..".png" else - return stack.tiles[1]:match("([%w_]+)%.png")..".png" + return stack.tiles[1]:match("(.*)%.png")..".png" end end @@ -95,7 +95,7 @@ function mailbox.formspec(pos, owner, num) ","..i..",#FFFFFF,x "..meta:get_string("stack"..i):match("%s(%d+)").."," img = img..i.."="..img_col(minetest.registered_items[ - meta:get_string("stack"..i):match("([%w_:]+)")]).."," + meta:get_string("stack"..i):match("(.*)%s")]).."," end end diff --git a/worktable.lua b/worktable.lua index 820932f..10d5aaf 100644 --- a/worktable.lua +++ b/worktable.lua @@ -34,8 +34,8 @@ local def = { -- Nodebox name, yield, definition. function worktable.get_recipe(item) if item:find("^group:") then if item:find("wool$") or item:find("dye$") then - item = item:match("[^,:]+$")..":white" - elseif minetest.registered_items["default:"..item:match("[^,:]+$")] then + item = item:sub(7)..":white" + elseif minetest.registered_items["default:"..item:sub(7)] then item = item:gsub("group:", "default:") else for node, definition in pairs(minetest.registered_items) do @@ -217,7 +217,7 @@ function worktable.fields(pos, _, fields) local formspec = meta:to_table().fields.formspec local filter = formspec:match("filter;;([%w_:]+)") or "" local pagenum = tonumber(formspec:match("#FFFF00,(%d+)")) or 1 - local tab_id = tonumber(formspec:match("tabheader%[.*;(%d+)%;.*]")) or 1 + local tab_id = tonumber(formspec:match("tabheader%[.*;(%d+)%;.*%]")) or 1 if fields.back then worktable.formspecs.main(meta) @@ -248,8 +248,7 @@ function worktable.fields(pos, _, fields) worktable.craftguide_formspec(meta, pagenum, nil, 1, filter, tab_id) else for item in pairs(fields) do - if item:match("[%w_]+:[%w_]+") and - minetest.get_craft_recipe(item).items then + if item:match(".-:") and minetest.get_craft_recipe(item).items then worktable.craftguide_formspec(meta, pagenum, item, 1, filter, tab_id) end end @@ -262,7 +261,7 @@ function worktable.dig(pos) inv:is_empty("tool") and inv:is_empty("storage") end -function worktable.contains(table, element) +function worktable.allowed(table, element) if table then for _, value in pairs(table) do if value == element then @@ -282,10 +281,10 @@ end function worktable.put(pos, listname, _, stack) local stackname = stack:get_name() - local mod, node = stackname:match("([%w_]+):([%w_]+)") + local mod, node = stackname:match("(.*):(.*)") if (listname == "tool" and stack:get_wear() > 0 and stackname ~= "xdecor:hammer") or - (listname == "input" and worktable.contains(nodes[mod], node)) or + (listname == "input" and worktable.allowed(nodes[mod], node)) or (listname == "hammer" and stackname == "xdecor:hammer") or listname == "storage" or listname == "trash" then if listname == "trash" then trash_delete(pos) end @@ -306,9 +305,11 @@ function worktable.take(pos, listname, _, stack, player) return stack:get_count() end -function worktable.move(pos, from_list, _, to_list, _, count) - if (from_list == "storage" and to_list == "storage") or to_list == "trash" then - if to_list == "trash" then trash_delete(pos) end +function worktable.move(pos, _, _, to_list, _, count) + if to_list == "storage" then + return count + elseif to_list == "trash" then + trash_delete(pos) return count end return 0