From 7a7d33b3faa9c990239d7092be548261fcca2d1f Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Sun, 11 Jun 2023 21:45:59 -0400 Subject: [PATCH] Fix many workbench and enchanting table bugs from MT-Eurythmia * fix crash https://github.com/Mynetest/Mynetest-server/issues/105 * detect that hammer is present and detect if that mese list are mese * backported https://github.com/MT-Eurythmia/xdecor/commit/59a65c60611ebe8ef3ced2e406968f049> * backported https://github.com/MT-Eurythmia/xdecor/commit/28a24a805be109eb8ab32b8633b1dfef5> --- mods/xdecor/init.lua | 32 ++++++++++++++++---------------- mods/xdecor/src/enchanting.lua | 6 ++++++ mods/xdecor/src/workbench.lua | 30 +++++++++++++++++++++++++----- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/mods/xdecor/init.lua b/mods/xdecor/init.lua index f41b9ce..ad13908 100644 --- a/mods/xdecor/init.lua +++ b/mods/xdecor/init.lua @@ -7,24 +7,24 @@ local ar_api = minetest.get_modpath("3d_armor") -- Intllib local S if minetest.get_translator ~= nil then - S = minetest.get_translator("xdecor") -- 5.x translation function + S = minetest.get_translator("xdecor") -- 5.x translation function else - if minetest.get_modpath("intllib") then - dofile(minetest.get_modpath("intllib") .. "/init.lua") - if intllib.make_gettext_pair then - gettext, ngettext = intllib.make_gettext_pair() -- new gettext method - else - gettext = intllib.Getter() -- old text file method + if minetest.get_modpath("intllib") then + dofile(minetest.get_modpath("intllib") .. "/init.lua") + if intllib.make_gettext_pair then + gettext, ngettext = intllib.make_gettext_pair() -- new gettext method + else + gettext = intllib.Getter() -- old text file method + end + S = gettext + else -- boilerplate function + S = function(str, ...) + local args = {...} + return str:gsub("@%d+", function(match) + return args[tonumber(match:sub(2))] + end) + end end - S = gettext - else -- boilerplate function - S = function(str, ...) - local args = {...} - return str:gsub("@%d+", function(match) - return args[tonumber(match:sub(2))] - end) - end - end end xdecor.S = S diff --git a/mods/xdecor/src/enchanting.lua b/mods/xdecor/src/enchanting.lua index 8323357..4570473 100644 --- a/mods/xdecor/src/enchanting.lua +++ b/mods/xdecor/src/enchanting.lua @@ -112,6 +112,12 @@ function enchanting.fields(pos, _, fields, sender) local mod, name = tool:get_name():match("(.*):(.*)") local enchanted_tool = (mod or "") .. ":enchanted_" .. (name or "") .. "_" .. next(fields) + -- Mynetest: check that the "mese" list actually contains mese. + if mese:get_name() ~= "default:mese_crystal" then + inv:set_stack("mese", 1, nil) + return + end + if mese:get_count() >= mese_cost and reg_tools[enchanted_tool] then minetest.sound_play("xdecor_enchanting", { to_player = sender:get_player_name(), diff --git a/mods/xdecor/src/workbench.lua b/mods/xdecor/src/workbench.lua index 3da902d..2f7ca25 100644 --- a/mods/xdecor/src/workbench.lua +++ b/mods/xdecor/src/workbench.lua @@ -48,11 +48,11 @@ function workbench:repairable(stack) if ar_api then for _, t in ipairs({ - "armor_head", - "armor_torso", - "armor_legs", - "armor_feet", - "armor_shield", + "armor_head", + "armor_torso", + "armor_legs", + "armor_feet", + "armor_shield", }) do if minetest.get_item_group(stack, t) then return true end end @@ -134,6 +134,9 @@ local formspecs = { } function workbench:set_formspec(meta, id) + if not formspecs[id] then + return + end meta:set_string("formspec", "size[8,7;]list[current_player;main;0,3.25;8,4;]" .. formspecs[id] .. xbg .. default.get_hotbar_bg(0,3.25)) @@ -157,6 +160,16 @@ function workbench.fields(pos, _, fields) if fields.quit then return end local meta = minetest.get_meta(pos) + if fields.back and meta then + local inv = meta:get_inventory() + if inv:is_empty("input") then + inv:set_list("forms", {}) + else + local input = inv:get_stack("input", 1) + workbench:get_output(inv, input, input:get_name()) + end + end + local id = fields.back and 1 or fields.craft and 2 or fields.storage and 3 if not id then return end @@ -175,6 +188,13 @@ function workbench.timer(pos) local tool = inv:get_stack("tool", 1) local hammer = inv:get_stack("hammer", 1) + -- Mynetest: check that the item is a hammer. See https://github.com/Mynetest/Mynetest-server/issues/105 + if hammer:get_name() ~= "xdecor:hammer" then + timer:stop() + inv:set_stack("hammer", 1, nil) + return + end + if tool:is_empty() or hammer:is_empty() or tool:get_wear() == 0 then timer:stop() return