alternate_tool_recipes/init.lua

49 lines
1.2 KiB
Lua

local old_craftreg = minetest.register_craft
minetest.register_craft = function(c)
if (c.type == "" or not c.type) and c.output then
local tooltype =
(string.find(c.output, ":hoe_") and "hoe") or
(string.find(c.output, ":shovel_") and "shovel") or
(string.find(c.output, ":pick_") and "pick") or
(string.find(c.output, ":axe_") and "axe") or
(string.find(c.output, ":sword_") and "sword")
if not tooltype then old_craftreg(c); return end
if type(c.recipe) ~= "table" or #c.recipe ~= 3 or type(c.recipe[3]) ~= "table" then old_craftreg(c); return end
local A = c.recipe[1][math.min(#c.recipe[1], 2)]
local B = c.recipe[3][math.min(#c.recipe[3], 2)]
if tooltype == "hoe" then
c.recipe = {
{A, A, B},
{"",B,""},
{B,"",""}
}
elseif tooltype == "shovel" then
c.recipe = {
{"",A, A},
{"",B, A},
{B,"",""}
}
elseif tooltype == "pick" then
c.recipe = {
{A, A,""},
{"",B, A},
{B,"", A}
}
elseif tooltype == "axe" then
c.recipe = {
{A, A,""},
{A, B,""},
{B,"",""}
}
elseif tooltype == "sword" then
c.recipe = {
{"","",A},
{A, A,""},
{B, A,""}
}
end
end
old_craftreg(c)
end