Workbench redo : more nodes and allow cutting all default nodes

pull/1/head
kilbith 2015-06-13 14:05:41 +02:00
parent f99645757b
commit fbc629a5bc
2 changed files with 125 additions and 90 deletions

BIN
textures/xdecor_wood.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

View File

@ -1,101 +1,136 @@
-- Repair Tool's code by Krock, modified by kilbith
local material = {
"cloud", -- only used for the formspec display
"wood", "junglewood", "pinewood", "stonebrick", "tree", "pinetree",
"stone", "sandstone", "desert_stone", "obsidian",
"stonebrick", "sandstonebrick", "desert_stonebrick", "obsidianbrick",
"copperblock", "bronzeblock", "goldblock", "steelblock", "diamondblock",
"meselamp", "glass", "obsidian_glass" }
local def = {
{"nanoslab", "32", {-0.5, -0.5, -0.5, 0, -0.4375, 0}},
{"microslab_half", "16", {-0.5, -0.5, -0.5, 0.5, -0.4375, 0}},
{"microslab", "8", {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}},
{"panel", "4", {-0.5, -0.5, -0.5, 0.5, 0, 0}},
{"slab", "2", {-0.5, -0.5, -0.5, 0.5, 0, 0.5}},
{"outerstair", "2", {{-0.5, -0.5, -0.5, 0.5, 0, 0.5}, {-0.5, 0, 0, 0, 0.5, 0.5}}},
{"stair", "2", {{-0.5, -0.5, -0.5, 0.5, 0, 0.5}, {-0.5, 0, 0, 0.5, 0.5, 0.5}}},
{"innerstair", "2", {{-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}}}
}
function xdecor.on_construct(pos)
local meta = minetest.get_meta(pos)
local nodespec = ""
for j=1, #def do
nodespec = nodespec..
"item_image_button["..(j-1)..",0.5;1,1;xdecor:"..def[j][1].."_cloud;"..def[j][1]..";]"
end
meta:set_string("formspec", "size[8,7;]"..fancy_gui..
"label[0,0;Cut your material into...]"..
nodespec..
"label[0,1.5;Input]"..
"list[current_name;input;0,2;1,1;]"..
"image[1,2;1,1;xdecor_saw.png]"..
"label[2,1.5;Output]"..
"list[current_name;output;2,2;1,1;]"..
"label[4.5,1.5;Damaged tool]"..
"list[current_name;src;5,2;1,1;]"..
"image[6,2;1,1;xdecor_hammer.png]"..
"label[6.8,1.5;Hammer]]"..
"list[current_name;fuel;7,2;1,1;]"..
"list[current_player;main;0,3.25;8,4;]")
meta:set_string("infotext", "Work Bench")
local inv = meta:get_inventory()
inv:set_size("output", 1)
inv:set_size("input", 1)
inv:set_size("src", 1)
inv:set_size("fuel", 1)
end
function xdecor.on_receive_fields(pos, formname, fields, sender)
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)
local shape = {}
local give = {}
local anz = 0
for _, m in ipairs(material) do
for _, n in ipairs(def) do
if (inputstack:get_name() == "default:"..m) and (outputstack:get_count() < 99) then
if fields[n[1]] then
anz = n[2]
shape = "xdecor:"..n[1].."_"..m
for i=0, anz-1 do
give[i+1] = inv:add_item("output", shape)
end
inputstack:take_item()
inv:set_stack("input", 1, inputstack)
end
end
end
end
end
function xdecor.can_dig(pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if not inv:is_empty("input") or not inv:is_empty("output")
or not inv:is_empty("fuel") or not inv:is_empty("src") then
return false end
return true
end
xdecor.register("workbench", {
description = "Work Bench", infotext = "Work Bench",
sounds = default.node_sound_wood_defaults(), groups = {snappy=3},
tiles = {"xdecor_workbench_top.png", "xdecor_workbench_top.png",
sounds = default.node_sound_wood_defaults(), groups = {snappy=3},
tiles = {"xdecor_workbench_top.png", "xdecor_workbench_top.png",
"xdecor_workbench_sides.png", "xdecor_workbench_sides.png",
"xdecor_workbench_front.png", "xdecor_workbench_front.png"},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[8,7;]"..fancy_gui..
"label[0,0;Cut your wood into...]"..
"label[0,1.5;Input]"..
"list[current_name;input;0,2;1,1;]"..
"image[1,2;1,1;xdecor_saw.png]"..
"label[2,1.5;Output]"..
"list[current_name;output;2,2;1,1;]"..
"label[5.5,0;Damaged tool]"..
"list[current_name;src;6,0.5;1,1;]"..
"image[4.35,1.1;1.5,1.5;xdecor_hammer.png]"..
"label[5.8,1.5;Hammer]]"..
"list[current_name;fuel;6,2;1,1;]"..
"item_image_button[0,0.5;1,1;xdecor:microslab_wood;microslab; ]"..
"item_image_button[1,0.5;1,1;xdecor:microslab_half_wood;microslabhalf; ]"..
"item_image_button[2,0.5;1,1;xdecor:microcube_wood;microcube; ]"..
"item_image_button[3,0.5;1,1;xdecor:panel_wood;panel; ]"..
"list[current_player;main;0,3.25;8,4;]")
meta:set_string("infotext", "Work Bench")
local inv = meta:get_inventory()
inv:set_size("output", 1)
inv:set_size("input", 1)
inv:set_size("src", 1)
inv:set_size("fuel", 1)
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local shape = {}
local anz = 0
on_construct = xdecor.on_construct,
on_receive_fields = xdecor.on_receive_fields,
can_dig = xdecor.can_dig })
if fields["microslab"] then
anz = "8"
shape = "xdecor:microslab_wood"
elseif fields["microslabhalf"] then
anz = "16"
shape = "xdecor:microslab_half_wood"
elseif fields["microcube"] then
anz = "8"
shape = "xdecor:microcube_wood"
elseif fields["panel"] then
anz = "4"
shape = "xdecor:panel_wood"
else return end
local inputstack = inv:get_stack("input", 1)
if (inputstack:get_name() == "default:wood") then
local give = {}
for i = 0, anz-1 do
give[i+1] = inv:add_item("output", shape)
end
inputstack:take_item()
inv:set_stack("input", 1, inputstack)
else return end
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if not inv:is_empty("input")
or not inv:is_empty("output")
or not inv:is_empty("fuel")
or not inv:is_empty("src") then
return false end
return true
end
})
local function register_wood_cut(name, desc, box, f_groups)
f_groups = {}
f_groups.snappy = 3
f_groups.not_in_creative_inventory = 1
xdecor.register(name.."_wood", {
description = "Wood "..desc,
tiles = {"default_wood.png"}, groups = f_groups,
sounds = default.node_sound_wood_defaults(),
node_box = { type = "fixed", fixed = box } }) end
wood = {}
wood.datas = {
{"microslab", "Microslab", {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}},
{"microslab_half", "Half Microslab", {-0.5, -0.5, -0.5, 0.5, -0.4375, 0}},
{"microcube", "Microcube", {-0.5, -0.5, -0.5, 0, 0, 0}},
{"panel", "Panel", {-0.5, -0.5, -0.5, 0.5, 0, 0}},
}
for _, item in pairs(wood.datas) do
register_wood_cut(unpack(item))
local function lightlvl(material)
if (material == "meselamp") then return 12 else return 0 end
end
local function stype(material)
if string.find(material, "glass") or string.find(material, "lamp") then
return default.node_sound_glass_defaults()
elseif string.find(material, "wood") or string.find(material, "tree") then
return default.node_sound_wood_defaults()
else
return default.node_sound_stone_defaults()
end
end
local function tnaming(material)
if string.find(material, "block") then
local newname = string.gsub(material, "(block)", "_%1")
return "default_"..newname..".png"
elseif string.find(material, "brick") then
local newname = string.gsub(material, "(brick)", "_%1")
return "default_"..newname..".png"
else return "default_"..material..".png" end
end
for _, m in ipairs(material) do
local light = lightlvl(m)
local sound = stype(m)
local tile = tnaming(m)
for _, n in ipairs(def) do
xdecor.register(n[1].."_"..m, {
description = n[1], light_source = light, sounds = sound,
tiles = {tile}, groups = {snappy=3, not_in_creative_inventory=1},
on_place = minetest.rotate_node, node_box = {type = "fixed", fixed = n[3]} })
end
end
-- Repair Tool's code by Krock, modified by kilbith
minetest.register_abm({
nodenames = {"xdecor:workbench"},
interval = 5, chance = 1,