2015-08-05 17:47:52 +03:00
|
|
|
local worktable = {}
|
|
|
|
|
2015-06-13 15:05:41 +03:00
|
|
|
local material = {
|
2015-06-25 18:25:36 +03:00
|
|
|
"cloud", -- Only used for the formspec display.
|
2015-08-02 03:00:29 +03:00
|
|
|
"wood", "junglewood", "pinewood", "acacia_wood",
|
|
|
|
"tree", "jungletree", "pinetree", "acacia_tree",
|
2015-06-25 18:25:36 +03:00
|
|
|
"cobble", "mossycobble", "desert_cobble",
|
2015-06-13 15:05:41 +03:00
|
|
|
"stone", "sandstone", "desert_stone", "obsidian",
|
|
|
|
"stonebrick", "sandstonebrick", "desert_stonebrick", "obsidianbrick",
|
2015-08-08 19:29:53 +03:00
|
|
|
"coalblock", "copperblock", "steelblock", "goldblock",
|
2015-08-01 19:30:01 +03:00
|
|
|
"bronzeblock", "mese", "diamondblock",
|
2015-08-08 19:29:53 +03:00
|
|
|
"brick", "cactus", "ice", "meselamp",
|
2015-06-25 18:25:36 +03:00
|
|
|
"glass", "obsidian_glass"
|
|
|
|
}
|
|
|
|
|
2015-08-19 14:54:37 +03:00
|
|
|
local def = { -- Node name, nodebox shape.
|
|
|
|
{"nanoslab", {-.5,-.5,-.5,0,-.4375,0}},
|
|
|
|
{"micropanel", {-.5,-.5,-.5,.5,-.4375,0}},
|
|
|
|
{"microslab", {-.5,-.5,-.5,.5,-.4375,.5}},
|
|
|
|
{"panel", {-.5,-.5,-.5,.5,0,0}},
|
|
|
|
{"slab", {-.5,-.5,-.5,.5,0,.5}},
|
|
|
|
{"outerstair", {{-.5,-.5,-.5,.5,0,.5},{-.5,0,0,0,.5,.5}}},
|
|
|
|
{"stair", {{-.5,-.5,-.5,.5,0,.5},{-.5,0,0,.5,.5,.5}}},
|
|
|
|
{"innerstair", {{-.5,-.5,-.5,.5,0,.5},{-.5,0,0,.5,.5,.5},{-.5,0,-.5,0,.5,0}}}
|
2015-06-13 15:05:41 +03:00
|
|
|
}
|
|
|
|
|
2015-08-05 17:47:52 +03:00
|
|
|
function worktable.construct(pos)
|
2015-06-13 15:05:41 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
|
2015-08-03 01:36:32 +03:00
|
|
|
local nodebtn = {}
|
2015-08-08 16:11:46 +03:00
|
|
|
for i = 1, #def do
|
2015-06-15 17:37:11 +03:00
|
|
|
nodebtn[#nodebtn+1] = "item_image_button["..(i-1)..
|
2015-07-30 00:55:01 +03:00
|
|
|
",0.5;1,1;xdecor:"..def[i][1].."_cloud;"..def[i][1]..";]"
|
2015-06-13 15:05:41 +03:00
|
|
|
end
|
2015-06-14 20:55:59 +03:00
|
|
|
nodebtn = table.concat(nodebtn)
|
|
|
|
|
2015-08-16 22:57:17 +03:00
|
|
|
local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
|
2015-08-16 22:14:01 +03:00
|
|
|
meta:set_string("formspec", "size[8,7;]"..xbg..
|
2015-08-08 11:54:17 +03:00
|
|
|
"label[0,0;Cut your material into...]"..nodebtn..
|
|
|
|
"label[0,1.5;Input]".."list[current_name;input;0,2;1,1;]"..
|
2015-06-13 15:05:41 +03:00
|
|
|
"image[1,2;1,1;xdecor_saw.png]"..
|
2015-08-08 11:54:17 +03:00
|
|
|
"label[2,1.5;Output]".."list[current_name;output;2,2;1,1;]"..
|
|
|
|
"label[5,1.5;Tool]".."list[current_name;tool;5,2;1,1;]"..
|
2015-07-29 14:52:39 +03:00
|
|
|
"image[6,2;1,1;xdecor_anvil.png]"..
|
2015-08-08 11:54:17 +03:00
|
|
|
"label[6.8,1.5;Hammer]".."list[current_name;hammer;7,2;1,1;]"..
|
2015-06-13 15:05:41 +03:00
|
|
|
"list[current_player;main;0,3.25;8,4;]")
|
2015-06-14 16:29:30 +03:00
|
|
|
meta:set_string("infotext", "Work Table")
|
2015-06-25 18:25:36 +03:00
|
|
|
|
2015-06-13 15:05:41 +03:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("output", 1)
|
|
|
|
inv:set_size("input", 1)
|
2015-07-31 16:42:40 +03:00
|
|
|
inv:set_size("tool", 1)
|
|
|
|
inv:set_size("hammer", 1)
|
2015-06-13 15:05:41 +03:00
|
|
|
end
|
|
|
|
|
2015-08-12 21:49:07 +03:00
|
|
|
function worktable.fields(pos, _, fields, _)
|
2015-06-13 15:05:41 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local inputstack = inv:get_stack("input", 1)
|
|
|
|
local outputstack = inv:get_stack("output", 1)
|
2015-08-03 01:36:32 +03:00
|
|
|
local outputcount = outputstack:get_count()
|
|
|
|
local inputname = inputstack:get_name()
|
2015-08-06 22:19:42 +03:00
|
|
|
local outputname = outputstack:get_name()
|
2015-08-07 17:52:36 +03:00
|
|
|
local shape, get, outputshape = {}, {}, {}
|
2015-08-19 14:54:37 +03:00
|
|
|
local name = dump(fields):match("%w+")
|
|
|
|
|
|
|
|
if outputcount < 99 and fields[name] then
|
|
|
|
outputshape = outputname:match(name)
|
|
|
|
if name ~= outputshape and outputcount > 0 then return end
|
|
|
|
shape = "xdecor:"..name.."_"..inputname:sub(9)
|
|
|
|
get = shape.." "..worktable.anz(name)
|
|
|
|
|
|
|
|
if minetest.registered_nodes[shape] then
|
|
|
|
inv:add_item("output", get)
|
|
|
|
inputstack:take_item()
|
|
|
|
inv:set_stack("input", 1, inputstack)
|
2015-06-13 15:05:41 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-19 14:54:37 +03:00
|
|
|
function worktable.anz(n)
|
|
|
|
if n == "nanoslab" or n == "micropanel" then return 16
|
|
|
|
elseif n == "microslab" then return 8
|
|
|
|
elseif n == "panel" then return 4
|
|
|
|
elseif n == "slab" then return 2
|
|
|
|
else return 1 end
|
|
|
|
end
|
|
|
|
|
2015-08-12 21:49:07 +03:00
|
|
|
function worktable.dig(pos, _)
|
2015-06-13 15:05:41 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2015-06-25 18:25:36 +03:00
|
|
|
|
2015-07-05 19:25:53 +03:00
|
|
|
if not inv:is_empty("input") or not inv:is_empty("output") or not
|
2015-08-03 01:36:32 +03:00
|
|
|
inv:is_empty("hammer") or not inv:is_empty("tool") then
|
2015-06-25 18:25:36 +03:00
|
|
|
return false
|
|
|
|
end
|
2015-06-13 15:05:41 +03:00
|
|
|
return true
|
|
|
|
end
|
2015-06-11 23:06:54 +03:00
|
|
|
|
2015-08-12 21:49:07 +03:00
|
|
|
function worktable.put(_, listname, _, stack, _)
|
2015-08-02 21:55:19 +03:00
|
|
|
local stackname = stack:get_name()
|
2015-08-03 00:02:56 +03:00
|
|
|
local count = stack:get_count()
|
2015-08-19 14:54:37 +03:00
|
|
|
local mat = table.concat(material)
|
2015-07-05 13:08:33 +03:00
|
|
|
|
2015-08-01 19:30:01 +03:00
|
|
|
if listname == "output" then return 0 end
|
2015-08-02 21:55:19 +03:00
|
|
|
if listname == "input" then
|
2015-08-07 17:52:36 +03:00
|
|
|
if stackname:find("default:") and mat:match(stackname:sub(9)) then
|
|
|
|
return count
|
|
|
|
else return 0 end
|
2015-08-02 21:55:19 +03:00
|
|
|
end
|
2015-07-31 16:42:40 +03:00
|
|
|
if listname == "hammer" then
|
2015-08-02 21:55:19 +03:00
|
|
|
if not (stackname == "xdecor:hammer") then return 0 end
|
2015-07-05 17:40:33 +03:00
|
|
|
end
|
2015-07-31 16:42:40 +03:00
|
|
|
if listname == "tool" then
|
2015-08-02 21:55:19 +03:00
|
|
|
local tdef = minetest.registered_tools[stackname]
|
2015-07-29 17:51:41 +03:00
|
|
|
local twear = stack:get_wear()
|
2015-08-02 21:55:19 +03:00
|
|
|
if not (tdef and twear > 0) then return 0 end
|
2015-07-29 17:51:41 +03:00
|
|
|
end
|
2015-08-03 01:36:32 +03:00
|
|
|
|
|
|
|
return count
|
2015-07-05 13:08:33 +03:00
|
|
|
end
|
|
|
|
|
2015-06-13 20:08:35 +03:00
|
|
|
xdecor.register("worktable", {
|
2015-06-25 18:25:36 +03:00
|
|
|
description = "Work Table",
|
2015-08-08 19:29:53 +03:00
|
|
|
groups = {cracky=2, choppy=2},
|
2015-08-16 22:57:17 +03:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2015-06-25 18:25:36 +03:00
|
|
|
tiles = {
|
|
|
|
"xdecor_worktable_top.png", "xdecor_worktable_top.png",
|
2015-06-13 20:08:35 +03:00
|
|
|
"xdecor_worktable_sides.png", "xdecor_worktable_sides.png",
|
2015-06-25 18:25:36 +03:00
|
|
|
"xdecor_worktable_front.png", "xdecor_worktable_front.png"
|
|
|
|
},
|
2015-08-08 19:29:53 +03:00
|
|
|
can_dig = worktable.dig,
|
2015-08-05 17:47:52 +03:00
|
|
|
on_construct = worktable.construct,
|
|
|
|
on_receive_fields = worktable.fields,
|
2015-08-06 19:18:27 +03:00
|
|
|
allow_metadata_inventory_put = worktable.put,
|
2015-08-12 23:54:26 +03:00
|
|
|
allow_metadata_inventory_move = function(_,_,_,_,_,_,_) return 0 end
|
2015-06-25 18:25:36 +03:00
|
|
|
})
|
2015-06-13 15:05:41 +03:00
|
|
|
|
2015-08-08 16:11:46 +03:00
|
|
|
local function description(m, w)
|
|
|
|
if m == "cloud" then return "" end
|
|
|
|
return m:gsub("%l", string.upper, 1).." "..w:gsub("%l", string.upper, 1)
|
|
|
|
end
|
2015-08-03 01:36:32 +03:00
|
|
|
|
2015-08-08 16:11:46 +03:00
|
|
|
local function groups(m)
|
|
|
|
if m:find("tree") or m:find("wood") or m == "cactus" then
|
|
|
|
return {choppy=3, not_in_creative_inventory=1}
|
2015-08-05 19:06:27 +03:00
|
|
|
end
|
2015-08-08 16:11:46 +03:00
|
|
|
return {cracky=3, not_in_creative_inventory=1}
|
|
|
|
end
|
2015-08-05 19:06:27 +03:00
|
|
|
|
2015-08-08 16:11:46 +03:00
|
|
|
local function shady(w)
|
|
|
|
if w:find("stair") or w == "slab" then return false end
|
|
|
|
return true
|
|
|
|
end
|
2015-08-05 19:06:27 +03:00
|
|
|
|
2015-08-08 16:11:46 +03:00
|
|
|
for n = 1, #def do
|
|
|
|
for m = 1, #material do
|
|
|
|
local w, x = def[n], material[m]
|
|
|
|
local nodename = "default:"..x
|
|
|
|
local ndef = minetest.registered_nodes[nodename]
|
|
|
|
if not ndef then break end
|
2015-08-06 16:26:13 +03:00
|
|
|
|
2015-08-08 16:11:46 +03:00
|
|
|
xdecor.register(w[1].."_"..x, {
|
|
|
|
description = description(x, w[1]),
|
2015-08-03 01:36:32 +03:00
|
|
|
light_source = ndef.light_source,
|
|
|
|
sounds = ndef.sounds,
|
|
|
|
tiles = ndef.tiles,
|
2015-08-08 16:11:46 +03:00
|
|
|
groups = groups(x),
|
2015-08-19 14:54:37 +03:00
|
|
|
node_box = {type = "fixed", fixed = w[2]},
|
2015-08-06 16:26:13 +03:00
|
|
|
sunlight_propagates = shady(w[1]),
|
2015-08-03 01:36:32 +03:00
|
|
|
on_place = minetest.rotate_node
|
|
|
|
})
|
|
|
|
end
|
2015-06-11 23:06:54 +03:00
|
|
|
end
|
|
|
|
|
2015-07-31 16:12:42 +03:00
|
|
|
minetest.register_abm({
|
2015-06-13 20:08:35 +03:00
|
|
|
nodenames = {"xdecor:worktable"},
|
2015-08-02 12:32:02 +03:00
|
|
|
interval = 3, chance = 1,
|
2015-08-12 21:49:07 +03:00
|
|
|
action = function(pos, _, _, _)
|
2015-06-11 23:06:54 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2015-07-31 16:42:40 +03:00
|
|
|
local tool = inv:get_stack("tool", 1)
|
|
|
|
local hammer = inv:get_stack("hammer", 1)
|
|
|
|
local wear = tool:get_wear()
|
2015-06-25 18:25:36 +03:00
|
|
|
|
2015-08-03 01:36:32 +03:00
|
|
|
if tool:is_empty() or hammer:is_empty() or wear == 0 then return end
|
2015-06-25 18:25:36 +03:00
|
|
|
|
2015-08-12 21:01:31 +03:00
|
|
|
tool:add_wear(-500) -- Tool's repairing factor (0-65535 -- 0 = new condition).
|
|
|
|
hammer:add_wear(250) -- Hammer's wearing factor (0-65535 -- 0 = new condition).
|
2015-06-11 23:06:54 +03:00
|
|
|
|
2015-07-31 16:42:40 +03:00
|
|
|
inv:set_stack("tool", 1, tool)
|
|
|
|
inv:set_stack("hammer", 1, hammer)
|
2015-06-11 23:06:54 +03:00
|
|
|
end
|
|
|
|
})
|