2 screwdriver = screwdriver or {}
4 -- Nodes allowed to be cut.
5 -- Only the regular, solid blocks without metas or explosivity can be cut.
7 for node, def in pairs(minetest.registered_nodes) do
8 if (def.drawtype == "normal" or def.drawtype:sub(1,5) == "glass") and
9 (def.groups.cracky or def.groups.choppy) and
10 not def.on_construct and
11 not def.after_place_node and
12 not def.on_rightclick and
14 not def.allow_metadata_inventory_take and
15 not (def.groups.not_in_creative_inventory == 1) and
16 not def.groups.wool and
17 not def.description:find("Ore") and
19 def.description ~= "" and
22 nodes[#nodes+1] = node
26 -- Nodeboxes definitions.
28 -- Name Yield X Y Z W H L
29 {"nanoslab", 16, { 0, 0, 0, 8, 1, 8 }},
30 {"micropanel", 16, { 0, 0, 0, 16, 1, 8 }},
31 {"microslab", 8, { 0, 0, 0, 16, 1, 16 }},
32 {"thinstair", 8, { 0, 7, 0, 16, 1, 8 },
33 { 0, 15, 8, 16, 1, 8 }},
34 {"cube", 4, { 0, 0, 0, 8, 8, 8 }},
35 {"panel", 4, { 0, 0, 0, 16, 8, 8 }},
37 {"doublepanel", 2, { 0, 0, 0, 16, 8, 8 },
38 { 0, 8, 8, 16, 8, 8 }},
39 {"halfstair", 2, { 0, 0, 0, 8, 8, 16 },
40 { 0, 8, 8, 8, 8, 8 }},
41 {"outerstair", 1, { 0, 0, 0, 16, 8, 16 },
42 { 0, 8, 8, 8, 8, 8 }},
44 {"innerstair", 1, { 0, 0, 0, 16, 8, 16 },
45 { 0, 8, 8, 16, 8, 8 },
49 -- Tools allowed to be repaired.
50 function workbench:repairable(stack)
51 local tools = {"pick", "axe", "shovel", "sword", "hoe", "armor", "shield"}
52 for _, t in pairs(tools) do
53 if stack:find(t) then return true end
58 function workbench:get_output(inv, input, name)
59 if inv:is_empty("input") then
60 inv:set_list("forms", {}) return
64 for _, n in pairs(self.defs) do
65 local count = math.min(n[2] * input:get_count(), input:get_stack_max())
66 local item = name.."_"..n[1]
67 if not n[3] then item = "stairs:"..n[1].."_"..name:match(":(.*)") end
68 output[#output+1] = item.." "..count
70 inv:set_list("forms", output)
75 [[ label[0.9,1.23;Cut]
76 label[0.9,2.23;Repair]
77 box[-0.05,1;2.05,0.9;#555555]
78 box[-0.05,2;2.05,0.9;#555555]
79 button[0,0;2,1;craft;Crafting]
80 button[2,0;2,1;storage;Storage]
81 image[3,1;1,1;gui_furnace_arrow_bg.png^[transformR270]
82 image[0,1;1,1;worktable_saw.png]
83 image[0,2;1,1;worktable_anvil.png]
84 image[3,2;1,1;hammer_layout.png]
85 list[context;input;2,1;1,1;]
86 list[context;tool;2,2;1,1;]
87 list[context;hammer;3,2;1,1;]
88 list[context;forms;4,0;4,3;] ]],
90 [[ image[5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]
91 button[0,0;1.5,1;back;< Back]
92 list[current_player;craft;2,0;3,3;]
93 list[current_player;craftpreview;6,1;1,1;]
94 listring[current_player;main]
95 listring[current_player;craft] ]],
97 [[ list[context;storage;0,1;8,2;]
98 button[0,0;1.5,1;back;< Back]
99 listring[context;storage]
100 listring[current_player;main] ]]
103 function workbench:set_formspec(meta, id)
104 meta:set_string("formspec", "size[8,7;]list[current_player;main;0,3.25;8,4;]"..
105 formspecs[id]..xbg..default.get_hotbar_bg(0,3.25))
108 function workbench.construct(pos)
109 local meta = minetest.get_meta(pos)
110 local inv = meta:get_inventory()
112 inv:set_size("tool", 1)
113 inv:set_size("input", 1)
114 inv:set_size("hammer", 1)
115 inv:set_size("forms", 4*3)
116 inv:set_size("storage", 8*2)
118 meta:set_string("infotext", "Work Bench")
119 workbench:set_formspec(meta, 1)
122 function workbench.fields(pos, _, fields)
123 local meta = minetest.get_meta(pos)
124 if fields.back then workbench:set_formspec(meta, 1)
125 elseif fields.craft then workbench:set_formspec(meta, 2)
126 elseif fields.storage then workbench:set_formspec(meta, 3) end
129 function workbench.dig(pos)
130 local inv = minetest.get_meta(pos):get_inventory()
131 return inv:is_empty("input") and inv:is_empty("hammer") and
132 inv:is_empty("tool") and inv:is_empty("storage")
135 function workbench.timer(pos)
136 local timer = minetest.get_node_timer(pos)
137 local inv = minetest.get_meta(pos):get_inventory()
138 local tool = inv:get_stack("tool", 1)
139 local hammer = inv:get_stack("hammer", 1)
141 if tool:is_empty() or hammer:is_empty() or tool:get_wear() == 0 then
145 -- Tool's wearing range: 0-65535 | 0 = new condition.
149 inv:set_stack("tool", 1, tool)
150 inv:set_stack("hammer", 1, hammer)
154 function workbench.put(_, listname, _, stack)
155 local stackname = stack:get_name()
156 if (listname == "tool" and stack:get_wear() > 0 and workbench:repairable(stackname)) or
157 (listname == "input" and minetest.registered_nodes[stackname.."_cube"]) or
158 (listname == "hammer" and stackname == "xdecor:hammer") or
159 listname == "storage" then
160 return stack:get_count()
165 function workbench.take(_, listname, _, stack, player)
166 if listname == "forms" then
167 local inv = player:get_inventory()
168 if inv:room_for_item("main", stack:get_name()) then return -1 end
171 return stack:get_count()
174 function workbench.move(_, from_list, _, to_list, _, count)
175 if to_list == "storage" and from_list ~= "forms" then return count end
179 function workbench.on_put(pos, listname, _, stack)
180 local inv = minetest.get_meta(pos):get_inventory()
181 if listname == "input" then
182 local input = inv:get_stack("input", 1)
183 workbench:get_output(inv, input, stack:get_name())
184 elseif listname == "tool" or listname == "hammer" then
185 local timer = minetest.get_node_timer(pos)
190 function workbench.on_take(pos, listname, index, stack)
191 local inv = minetest.get_meta(pos):get_inventory()
192 local input = inv:get_stack("input", 1)
194 if listname == "input" then
195 if stack:get_name() == input:get_name() then
196 workbench:get_output(inv, input, stack:get_name())
198 inv:set_list("forms", {})
200 elseif listname == "forms" then
201 input:take_item(math.ceil(stack:get_count() / workbench.defs[index][2]))
202 inv:set_stack("input", 1, input)
203 workbench:get_output(inv, input, input:get_name())
207 xdecor.register("workbench", {
208 description = "Work Bench",
209 groups = {cracky=2, choppy=2, oddly_breakable_by_hand=1},
210 sounds = default.node_sound_wood_defaults(),
211 tiles = {"xdecor_workbench_top.png", "xdecor_workbench_top.png",
212 "xdecor_workbench_sides.png", "xdecor_workbench_sides.png",
213 "xdecor_workbench_front.png", "xdecor_workbench_front.png"},
214 on_rotate = screwdriver.rotate_simple,
215 can_dig = workbench.dig,
216 on_timer = workbench.timer,
217 on_construct = workbench.construct,
218 on_receive_fields = workbench.fields,
219 on_metadata_inventory_put = workbench.on_put,
220 on_metadata_inventory_take = workbench.on_take,
221 allow_metadata_inventory_put = workbench.put,
222 allow_metadata_inventory_take = workbench.take,
223 allow_metadata_inventory_move = workbench.move
226 for _, d in pairs(workbench.defs) do
228 local node = nodes[i]
229 local def = minetest.registered_nodes[node]
234 groups.not_in_creative_inventory = 1
236 for k, v in pairs(def.groups) do
237 if k ~= "wood" and k ~= "stone" and k ~= "level" then
243 if #def.tiles > 1 and not (def.drawtype:sub(1,5) == "glass") then
246 tiles = {def.tiles[1]}
249 tiles = {def.tile_images[1]}
252 if not minetest.registered_nodes["stairs:slab_"..node:match(":(.*)")] then
253 stairs.register_stair_and_slab(node:match(":(.*)"), node, groups, tiles,
254 def.description.." Stair", def.description.." Slab", def.sounds)
257 minetest.register_node(":"..node.."_"..d[1], {
258 description = def.description.." "..d[1]:gsub("^%l", string.upper),
260 paramtype2 = "facedir",
261 drawtype = "nodebox",
265 -- `unpack` has been changed to `table.unpack` in newest Lua versions.
266 node_box = xdecor.pixelbox(16, {unpack(d, 3)}),
267 sunlight_propagates = true,
268 on_place = minetest.rotate_node