2 "cloud", -- only used for the formspec display
3 "wood", "junglewood", "pinewood", "tree", "pinetree",
4 "stone", "sandstone", "desert_stone", "obsidian",
5 "stonebrick", "sandstonebrick", "desert_stonebrick", "obsidianbrick",
6 "copperblock", "bronzeblock", "goldblock", "steelblock", "diamondblock",
7 "meselamp", "glass", "obsidian_glass" }
9 local def = { -- node name, yield, nodebox shape
10 {"nanoslab", "16", {-0.5, -0.5, -0.5, 0, -0.4375, 0}},
11 {"microslab_half", "16", {-0.5, -0.5, -0.5, 0.5, -0.4375, 0}},
12 {"microslab", "8", {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}},
13 {"panel", "4", {-0.5, -0.5, -0.5, 0.5, 0, 0}},
14 {"slab", "2", {-0.5, -0.5, -0.5, 0.5, 0, 0.5}},
15 {"outerstair", "1", {{-0.5, -0.5, -0.5, 0.5, 0, 0.5}, {-0.5, 0, 0, 0, 0.5, 0.5}}},
16 {"stair", "1", {{-0.5, -0.5, -0.5, 0.5, 0, 0.5}, {-0.5, 0, 0, 0.5, 0.5, 0.5}}},
17 {"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}}}
20 local function xconstruct(pos)
21 local meta = minetest.get_meta(pos)
25 nodebtn[#nodebtn+1] = "item_image_button["..(i-1)..",0.5;1,1;xdecor:"..def[i][1].."_cloud;"..def[i][1]..";]"
27 nodebtn = table.concat(nodebtn)
29 meta:set_string("formspec", "size[8,7;]"..fancy_gui..
30 "label[0,0;Cut your material into...]"..
32 "label[0,1.5;Input]"..
33 "list[current_name;input;0,2;1,1;]"..
34 "image[1,2;1,1;xdecor_saw.png]"..
35 "label[2,1.5;Output]"..
36 "list[current_name;output;2,2;1,1;]"..
37 "label[4.5,1.5;Damaged tool]"..
38 "list[current_name;src;5,2;1,1;]"..
39 "image[6,2;1,1;xdecor_hammer.png]"..
40 "label[6.8,1.5;Hammer]]"..
41 "list[current_name;fuel;7,2;1,1;]"..
42 "list[current_player;main;0,3.25;8,4;]")
43 meta:set_string("infotext", "Work Table")
44 local inv = meta:get_inventory()
45 inv:set_size("output", 1)
46 inv:set_size("input", 1)
47 inv:set_size("src", 1)
48 inv:set_size("fuel", 1)
51 local function xfields(pos, formname, fields, sender)
52 local meta = minetest.get_meta(pos)
53 local inv = meta:get_inventory()
54 local inputstack = inv:get_stack("input", 1)
55 local outputstack = inv:get_stack("output", 1)
64 if (inputstack:get_name() == "default:"..v) and (outputstack:get_count() < 99) then
67 shape = "xdecor:"..w[1].."_"..v
69 give[i+1] = inv:add_item("output", shape)
71 inputstack:take_item()
72 inv:set_stack("input", 1, inputstack)
79 local function xdig(pos, player)
80 local meta = minetest.get_meta(pos)
81 local inv = meta:get_inventory()
82 if not inv:is_empty("input") or not inv:is_empty("output")
83 or not inv:is_empty("fuel") or not inv:is_empty("src") then
88 xdecor.register("worktable", {
89 description = "Work Table", groups = {snappy=3},
90 sounds = default.node_sound_wood_defaults(),
91 tiles = {"xdecor_worktable_top.png", "xdecor_worktable_top.png",
92 "xdecor_worktable_sides.png", "xdecor_worktable_sides.png",
93 "xdecor_worktable_front.png", "xdecor_worktable_front.png"},
94 on_construct = xconstruct,
95 on_receive_fields = xfields,
98 local function lightlvl(material)
99 if (material == "meselamp") then return 12 else return 0 end
102 local function stype(material)
103 if string.find(material, "glass") or string.find(material, "lamp") then
104 return default.node_sound_glass_defaults()
105 elseif string.find(material, "wood") or string.find(material, "tree") then
106 return default.node_sound_wood_defaults()
108 return default.node_sound_stone_defaults()
112 local function tnaming(material)
113 if string.find(material, "block") then
114 local newname = string.gsub(material, "(block)", "_%1")
115 return "default_"..newname..".png"
116 elseif string.find(material, "brick") then
117 local newname = string.gsub(material, "(brick)", "_%1")
118 return "default_"..newname..".png"
119 else return "default_"..material..".png" end
122 for m=1, #material do
123 local v = material[m]
124 local light = lightlvl(v)
125 local sound = stype(v)
126 local tile = tnaming(v)
130 xdecor.register(w[1].."_"..v, {
131 description = w[1], light_source = light, sounds = sound,
132 tiles = {tile}, groups = {snappy=3, not_in_creative_inventory=1},
133 on_place = minetest.rotate_node, node_box = {type = "fixed", fixed = w[3]} })
137 -- Repair Tool's code by Krock, modified by kilbith
139 minetest.register_abm({
140 nodenames = {"xdecor:worktable"},
141 interval = 5, chance = 1,
142 action = function(pos, node, active_object_count, active_object_count_wider)
143 local meta = minetest.get_meta(pos)
144 local inv = meta:get_inventory()
145 local src = inv:get_stack("src", 1)
146 local wear = src:get_wear()
149 if (src:is_empty() or wear == 0 or wear == 65535) then return end
150 local fuel = inv:get_stack("fuel", 1)
151 if (fuel:is_empty() or fuel:get_name() ~= "xdecor:hammer") then return end
153 if (wear + repair < 0) then src:add_wear(repair + wear)
154 else src:add_wear(repair) end
156 inv:set_stack("src", 1, src)
157 inv:remove_item("fuel", "xdecor:hammer 1")