Workbench can now cut cushion block and cabinet

This commit is contained in:
Wuzzy 2023-07-21 15:40:05 +02:00
parent eaf7d6fc34
commit 0096b18d8e

View File

@ -1,5 +1,6 @@
local workbench = {} local workbench = {}
local registered_cuttable_nodes = {} local registered_cuttable_nodes = {}
local special_cuts = {}
screwdriver = screwdriver or {} screwdriver = screwdriver or {}
local min, ceil = math.min, math.ceil local min, ceil = math.min, math.ceil
@ -76,13 +77,23 @@ function workbench:get_output(inv, input, name)
local extended = workbench:cuttable_extended(input:get_name()) local extended = workbench:cuttable_extended(input:get_name())
for i = 1, #self.defs do for i = 1, #self.defs do
local nbox = self.defs[i] local nbox = self.defs[i]
if extended or nbox[3] == nil then local cuttype = nbox[1]
local count = min(nbox[2] * input:get_count(), input:get_stack_max()) local count = min(nbox[2] * input:get_count(), input:get_stack_max())
local item = name .. "_" .. nbox[1] local was_cut = false
if extended or nbox[3] == nil then
local item = name .. "_" .. cuttype
item = nbox[3] and item or "stairs:" .. nbox[1] .. "_" .. name:match(":(.*)") item = nbox[3] and item or "stairs:" .. cuttype .. "_" .. name:match(":(.*)")
if minetest.registered_items[item] then if minetest.registered_items[item] then
output[i] = item .. " " .. count output[i] = item .. " " .. count
was_cut = true
end
end
if not was_cut and special_cuts[input:get_name()] ~= nil then
local cut = special_cuts[input:get_name()][cuttype]
if cut then
output[i] = cut .. " " .. count
was_cut = true
end end
end end
end end
@ -90,6 +101,11 @@ function workbench:get_output(inv, input, name)
inv:set_list("forms", output) inv:set_list("forms", output)
end end
function workbench:register_special_cut(nodename, cutlist)
registered_cuttable_nodes[nodename] = true
special_cuts[nodename] = cutlist
end
local main_fs = "label[0.9,1.23;"..FS("Cut").."]" local main_fs = "label[0.9,1.23;"..FS("Cut").."]"
.."label[0.9,2.23;"..FS("Repair").."]" .."label[0.9,2.23;"..FS("Repair").."]"
..[[ box[-0.05,1;2.05,0.9;#555555] ..[[ box[-0.05,1;2.05,0.9;#555555]
@ -453,3 +469,7 @@ minetest.register_craft({
{"group:wood", "group:wood"} {"group:wood", "group:wood"}
} }
}) })
-- Special cuts for cushion block and cabinet
workbench:register_special_cut("xdecor:cushion_block", { slab = "xdecor:cushion" })
workbench:register_special_cut("xdecor:cabinet", { slab = "xdecor:cabinet_half" })