Clean-up (once again) work table code

This commit is contained in:
jp 2015-08-02 20:55:19 +02:00
parent 5ee2a6da90
commit 1ba92e60b1
2 changed files with 26 additions and 29 deletions

View File

@ -94,7 +94,6 @@ local tools = {
{"shovel", "crumbly"} {"shovel", "crumbly"}
} }
local materials = {"steel", "bronze", "mese", "diamond"} local materials = {"steel", "bronze", "mese", "diamond"}
local groups = {"cracky", "crumbly", "choppy"}
for _, t in pairs(tools) do for _, t in pairs(tools) do
for _, m in pairs(materials) do for _, m in pairs(materials) do
@ -142,7 +141,7 @@ for _, m in pairs(materials) do
} }
}) })
--- Axe --- --- Axes ---
minetest.register_tool("xdecor:enchanted_axe_"..m.."_durable", { minetest.register_tool("xdecor:enchanted_axe_"..m.."_durable", {
description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Axe (Durable)", description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Axe (Durable)",

View File

@ -91,22 +91,23 @@ end
local function xput(pos, listname, index, stack, player) local function xput(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local stackname = stack:get_name()
if listname == "output" then return 0 end if listname == "output" then return 0 end
if listname == "input" then
if string.find(stack:get_name(), "default:") then
return stack:get_count()
else return 0 end
end
if listname == "hammer" then if listname == "hammer" then
if stack:get_name() == "xdecor:hammer" then return 1 if not (stackname == "xdecor:hammer") then return 0 end
else return 0 end
end end
if listname == "tool" then if listname == "tool" then
local tname = stack:get_name() local tdef = minetest.registered_tools[stackname]
local tdef = minetest.registered_tools[tname]
local twear = stack:get_wear() local twear = stack:get_wear()
if tdef and twear > 0 then return 1 if not (tdef and twear > 0) then return 0 end
else return 0 end
end end
return stack:get_count()
end end
xdecor.register("worktable", { xdecor.register("worktable", {
@ -124,28 +125,25 @@ xdecor.register("worktable", {
allow_metadata_inventory_put = xput allow_metadata_inventory_put = xput
}) })
for m=1, #material do for _, m in pairs(material) do
local v = material[m]
for n=1, #def do for n=1, #def do
local w = def[n] local w = def[n]
local nodename = "default:"..v local nodename = "default:"..m
local ndef = minetest.registered_nodes[nodename] local ndef = minetest.registered_nodes[nodename]
if not ndef then return end
if ndef then xdecor.register(w[1].."_"..m, {
xdecor.register(w[1].."_"..v, { description = string.sub(string.upper(w[1]), 0, 1)..string.sub(w[1], 2),
description = string.sub(string.upper(w[1]), 0, 1).. light_source = ndef.light_source,
string.sub(w[1], 2), sounds = ndef.sounds,
light_source = ndef.light_source, tiles = ndef.tiles,
sounds = ndef.sounds, groups = {snappy=3, not_in_creative_inventory=1},
tiles = ndef.tiles, node_box = {
groups = {snappy=3, not_in_creative_inventory=1}, type = "fixed",
node_box = { fixed = w[3]
type = "fixed", },
fixed = w[3] on_place = minetest.rotate_node
}, })
on_place = minetest.rotate_node
})
end
end end
end end