4 "cloud", -- Only used for the formspec display.
5 "wood", "junglewood", "pinewood", "acacia_wood",
6 "tree", "jungletree", "pinetree", "acacia_tree",
7 "cobble", "mossycobble", "desert_cobble",
8 "stone", "sandstone", "desert_stone", "obsidian",
9 "stonebrick", "sandstonebrick", "desert_stonebrick", "obsidianbrick",
10 "snowblock", "coalblock", "copperblock", "steelblock", "goldblock",
11 "bronzeblock", "mese", "diamondblock",
12 "brick", "cactus", "clay", "ice", "meselamp",
13 "glass", "obsidian_glass"
16 local def = { -- Node name, yield, nodebox shape.
17 {"nanoslab", "16", {-0.5, -0.5, -0.5, 0, -0.4375, 0}},
18 {"micropanel", "16", {-0.5, -0.5, -0.5, 0.5, -0.4375, 0}},
19 {"microslab", "8", {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}},
20 {"panel", "4", {-0.5, -0.5, -0.5, 0.5, 0, 0}},
21 {"slab", "2", {-0.5, -0.5, -0.5, 0.5, 0, 0.5}},
22 {"outerstair", "1", {{-0.5, -0.5, -0.5, 0.5, 0, 0.5}, {-0.5, 0, 0, 0, 0.5, 0.5}}},
23 {"stair", "1", {{-0.5, -0.5, -0.5, 0.5, 0, 0.5}, {-0.5, 0, 0, 0.5, 0.5, 0.5}}},
24 {"innerstair", "1", {{-0.5, -0.5, -0.5, 0.5, 0, 0.5}, {-0.5, 0, 0, 0.5, 0.5, 0.5}, {-0.5, 0, -0.5, 0, 0.5, 0}}}
27 function worktable.construct(pos)
28 local meta = minetest.get_meta(pos)
32 nodebtn[#nodebtn+1] = "item_image_button["..(i-1)..
33 ",0.5;1,1;xdecor:"..def[i][1].."_cloud;"..def[i][1]..";]"
35 nodebtn = table.concat(nodebtn)
37 meta:set_string("formspec", "size[8,7;]"..xdecor.fancy_gui..
38 "label[0,0;Cut your material into...]"..
40 "label[0,1.5;Input]"..
41 "list[current_name;input;0,2;1,1;]"..
42 "image[1,2;1,1;xdecor_saw.png]"..
43 "label[2,1.5;Output]"..
44 "list[current_name;output;2,2;1,1;]"..
46 "list[current_name;tool;5,2;1,1;]"..
47 "image[6,2;1,1;xdecor_anvil.png]"..
48 "label[6.8,1.5;Hammer]]"..
49 "list[current_name;hammer;7,2;1,1;]"..
50 "list[current_player;main;0,3.25;8,4;]")
51 meta:set_string("infotext", "Work Table")
53 local inv = meta:get_inventory()
54 inv:set_size("output", 1)
55 inv:set_size("input", 1)
56 inv:set_size("tool", 1)
57 inv:set_size("hammer", 1)
60 function worktable.fields(pos, formname, fields, sender)
61 local meta = minetest.get_meta(pos)
62 local inv = meta:get_inventory()
63 local inputstack = inv:get_stack("input", 1)
64 local outputstack = inv:get_stack("output", 1)
65 local outputcount = outputstack:get_count()
66 local inputname = inputstack:get_name()
67 local shape, get = {}, {}
70 for _, d in pairs(def) do
71 local nb, anz = d[1], d[2]
72 if outputcount < 99 and fields[nb] then
73 shape = "xdecor:"..nb.."_"..string.sub(inputname, 9)
76 if not minetest.registered_nodes[shape] then return end
77 inv:add_item("output", get)
78 inputstack:take_item()
79 inv:set_stack("input", 1, inputstack)
84 function worktable.dig(pos, player)
85 local meta = minetest.get_meta(pos)
86 local inv = meta:get_inventory()
88 if not inv:is_empty("input") or not inv:is_empty("output") or not
89 inv:is_empty("hammer") or not inv:is_empty("tool") then
95 function worktable.put(pos, listname, index, stack, player)
96 local stackname = stack:get_name()
97 local count = stack:get_count()
99 if listname == "output" then return 0 end
100 if listname == "input" then
101 if string.find(stackname, "default:") then return count
104 if listname == "hammer" then
105 if not (stackname == "xdecor:hammer") then return 0 end
107 if listname == "tool" then
108 local tdef = minetest.registered_tools[stackname]
109 local twear = stack:get_wear()
110 if not (tdef and twear > 0) then return 0 end
116 xdecor.register("worktable", {
117 description = "Work Table",
119 sounds = xdecor.wood,
121 "xdecor_worktable_top.png", "xdecor_worktable_top.png",
122 "xdecor_worktable_sides.png", "xdecor_worktable_sides.png",
123 "xdecor_worktable_front.png", "xdecor_worktable_front.png"
125 on_construct = worktable.construct,
126 on_receive_fields = worktable.fields,
127 can_dig = worktable.dig,
128 allow_metadata_inventory_put = worktable.put
131 for _, m in pairs(material) do
134 local nodename = "default:"..m
135 local ndef = minetest.registered_nodes[nodename]
136 if not ndef then return end
138 local function description(m)
139 if m == "cloud" then return "" end
140 return string.gsub(m, "%l", string.upper, 1).." "..string.gsub(w[1], "%l", string.upper, 1)
143 local function groups(m)
144 if string.find(m, "tree") or string.find(m, "wood") or m == "cactus" then
145 return {choppy=3, not_in_creative_inventory=1}
146 elseif m == "clay" or m == "snowblock" then
147 return {snappy=3, not_in_creative_inventory=1}
149 return {cracky=3, not_in_creative_inventory=1}
152 local function shady(w)
153 if string.find(w, "stair") or w == "slab" then return false end
157 xdecor.register(w[1].."_"..m, {
158 description = description(m),
159 light_source = ndef.light_source,
160 sounds = ndef.sounds,
163 node_box = {type = "fixed", fixed = w[3]},
164 sunlight_propagates = shady(w[1]),
165 on_place = minetest.rotate_node
170 minetest.register_abm({
171 nodenames = {"xdecor:worktable"},
172 interval = 3, chance = 1,
173 action = function(pos, node, active_object_count, active_object_count_wider)
174 local meta = minetest.get_meta(pos)
175 local inv = meta:get_inventory()
176 local tool = inv:get_stack("tool", 1)
177 local hammer = inv:get_stack("hammer", 1)
178 local wear = tool:get_wear()
179 local wear2 = hammer:get_wear()
181 local repair = -500 -- Tool's repairing factor (0-65535 -- 0 = new condition).
182 local wearhammer = 250 -- Hammer's wearing factor (0-65535 -- 0 = new condition).
184 if tool:is_empty() or hammer:is_empty() or wear == 0 then return end
186 tool:add_wear(repair)
187 hammer:add_wear(wearhammer)
189 inv:set_stack("tool", 1, tool)
190 inv:set_stack("hammer", 1, hammer)