Small simplifications

This commit is contained in:
kilbith 2016-01-12 14:27:13 +01:00
parent d8f4b8f578
commit 63949950bd
4 changed files with 18 additions and 17 deletions

View File

@ -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 if meta:get_string("lastMove") == "black" then
minetest.chat_send_player(playerWhite, "["..os.date("%H:%M:%S").."] ".. 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 elseif meta:get_string("lastMove") == "white" then
minetest.chat_send_player(playerBlack, "["..os.date("%H:%M:%S").."] ".. 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 end
if pieceTo:find("king") then if pieceTo:find("king") then

View File

@ -56,7 +56,7 @@ function enchanting.fields(pos, _, fields)
local tool = inv:get_stack("tool", 1) local tool = inv:get_stack("tool", 1)
local mese = inv:get_stack("mese", 1) local mese = inv:get_stack("mese", 1)
local orig_wear = tool:get_wear() 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) local enchanted_tool = mod..":enchanted_"..name.."_"..next(fields)
if mese:get_count() > 0 and minetest.registered_tools[enchanted_tool] then if mese:get_count() > 0 and minetest.registered_tools[enchanted_tool] then

View File

@ -77,9 +77,9 @@ xdecor.register("mailbox", {
local function img_col(stack) local function img_col(stack)
if not stack then return "" end if not stack then return "" end
if stack.inventory_image ~= "" then if stack.inventory_image ~= "" then
return stack.inventory_image:match("([%w_]+)%.png")..".png" return stack.inventory_image:match("(.*)%.png")..".png"
else else
return stack.tiles[1]:match("([%w_]+)%.png")..".png" return stack.tiles[1]:match("(.*)%.png")..".png"
end end
end end
@ -95,7 +95,7 @@ function mailbox.formspec(pos, owner, num)
","..i..",#FFFFFF,x "..meta:get_string("stack"..i):match("%s(%d+)").."," ","..i..",#FFFFFF,x "..meta:get_string("stack"..i):match("%s(%d+)")..","
img = img..i.."="..img_col(minetest.registered_items[ img = img..i.."="..img_col(minetest.registered_items[
meta:get_string("stack"..i):match("([%w_:]+)")]).."," meta:get_string("stack"..i):match("(.*)%s")])..","
end end
end end

View File

@ -34,8 +34,8 @@ local def = { -- Nodebox name, yield, definition.
function worktable.get_recipe(item) function worktable.get_recipe(item)
if item:find("^group:") then if item:find("^group:") then
if item:find("wool$") or item:find("dye$") then if item:find("wool$") or item:find("dye$") then
item = item:match("[^,:]+$")..":white" item = item:sub(7)..":white"
elseif minetest.registered_items["default:"..item:match("[^,:]+$")] then elseif minetest.registered_items["default:"..item:sub(7)] then
item = item:gsub("group:", "default:") item = item:gsub("group:", "default:")
else else
for node, definition in pairs(minetest.registered_items) do 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 formspec = meta:to_table().fields.formspec
local filter = formspec:match("filter;;([%w_:]+)") or "" local filter = formspec:match("filter;;([%w_:]+)") or ""
local pagenum = tonumber(formspec:match("#FFFF00,(%d+)")) or 1 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 if fields.back then
worktable.formspecs.main(meta) worktable.formspecs.main(meta)
@ -248,8 +248,7 @@ function worktable.fields(pos, _, fields)
worktable.craftguide_formspec(meta, pagenum, nil, 1, filter, tab_id) worktable.craftguide_formspec(meta, pagenum, nil, 1, filter, tab_id)
else else
for item in pairs(fields) do for item in pairs(fields) do
if item:match("[%w_]+:[%w_]+") and if item:match(".-:") and minetest.get_craft_recipe(item).items then
minetest.get_craft_recipe(item).items then
worktable.craftguide_formspec(meta, pagenum, item, 1, filter, tab_id) worktable.craftguide_formspec(meta, pagenum, item, 1, filter, tab_id)
end end
end end
@ -262,7 +261,7 @@ function worktable.dig(pos)
inv:is_empty("tool") and inv:is_empty("storage") inv:is_empty("tool") and inv:is_empty("storage")
end end
function worktable.contains(table, element) function worktable.allowed(table, element)
if table then if table then
for _, value in pairs(table) do for _, value in pairs(table) do
if value == element then if value == element then
@ -282,10 +281,10 @@ end
function worktable.put(pos, listname, _, stack) function worktable.put(pos, listname, _, stack)
local stackname = stack:get_name() 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 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 == "hammer" and stackname == "xdecor:hammer") or
listname == "storage" or listname == "trash" then listname == "storage" or listname == "trash" then
if listname == "trash" then trash_delete(pos) end if listname == "trash" then trash_delete(pos) end
@ -306,9 +305,11 @@ function worktable.take(pos, listname, _, stack, player)
return stack:get_count() return stack:get_count()
end end
function worktable.move(pos, from_list, _, to_list, _, count) function worktable.move(pos, _, _, to_list, _, count)
if (from_list == "storage" and to_list == "storage") or to_list == "trash" then if to_list == "storage" then
if to_list == "trash" then trash_delete(pos) end return count
elseif to_list == "trash" then
trash_delete(pos)
return count return count
end end
return 0 return 0