From dcde4d7c05996e14ba2fd0bc469825ca718bbfda Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Sun, 11 Jun 2023 21:36:45 -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/59a65c60611ebe8ef3ced2e406968f049d1aa757 * backported https://github.com/MT-Eurythmia/xdecor/commit/28a24a805be109eb8ab32b8633b1dfef52bab408 --- src/enchanting.lua | 6 ++++++ src/workbench.lua | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/enchanting.lua b/src/enchanting.lua index 8323357..4570473 100644 --- a/src/enchanting.lua +++ b/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/src/workbench.lua b/src/workbench.lua index 530953c..2f7ca25 100644 --- a/src/workbench.lua +++ b/src/workbench.lua @@ -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