Compare commits

...

4 Commits

Author SHA1 Message Date
mckaygerhard dcde4d7c05 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 59a65c6061
* backported 28a24a805b
2023-06-11 21:39:53 -04:00
mckaygerhard cd0c35b8c5 Added further sanity check as this keeps crashing somehow
* backporting c7e756afc7
* backporting 3823fce1e0
2023-06-11 19:25:37 -04:00
mckaygerhard 3e0ca1304d Formspec now updates after applying enchantment
* This prevents crash when trying to apply a second enchantment
* backported 556d978708
2023-06-11 19:21:03 -04:00
mckaygerhard 9f4002b749 fix undefined detection of 3d_armor and add support for repair of
* partial backport 03388d21c0
* fix i18n tranlation support identation
2023-06-11 19:16:22 -04:00
3 changed files with 71 additions and 29 deletions

View File

@ -2,32 +2,33 @@
xdecor = {}
local modpath = minetest.get_modpath("xdecor")
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
xdecor.reparaible_tools = {"pick", "axe", "shovel", "sword"}
xdecor.reparaible_tools = {"pick", "axe", "shovel", "hoe"}
dofile(modpath .. "/handlers/animations.lua")
dofile(modpath .. "/handlers/helpers.lua")

View File

@ -108,20 +108,29 @@ function enchanting.fields(pos, _, fields, sender)
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("(.*):(.*)")
local enchanted_tool = (mod or "") .. ":enchanted_" .. (name or "") .. "_" .. next(fields)
if tool and tool:get_name() and allowed_tools[tool:get_name()] then
local mod, name = tool:get_name():match("(.*):(.*)")
local enchanted_tool = (mod or "") .. ":enchanted_" .. (name or "") .. "_" .. next(fields)
if mese:get_count() >= mese_cost and reg_tools[enchanted_tool] then
minetest.sound_play("xdecor_enchanting", {
to_player = sender:get_player_name(),
gain = 0.8
})
-- 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
tool:replace(enchanted_tool)
tool:add_wear(orig_wear)
mese:take_item(mese_cost)
inv:set_stack("mese", 1, mese)
inv:set_stack("tool", 1, tool)
if mese:get_count() >= mese_cost and reg_tools[enchanted_tool] then
minetest.sound_play("xdecor_enchanting", {
to_player = sender:get_player_name(),
gain = 0.8
})
tool:replace(enchanted_tool)
tool:add_wear(orig_wear)
mese:take_item(mese_cost)
inv:set_stack("mese", 1, mese)
inv:set_stack("tool", 1, tool)
end
enchanting.formspec(pos)
end
end

View File

@ -46,6 +46,18 @@ end
function workbench:repairable(stack)
if custom_repairable[stack] then return true end
if ar_api then
for _, t in ipairs({
"armor_head",
"armor_torso",
"armor_legs",
"armor_feet",
"armor_shield",
}) do
if minetest.get_item_group(stack, t) then return true end
end
end
for _, t in ipairs(repairable_tools) do
if stack:find(t) then
return true
@ -122,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))
@ -145,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
@ -163,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