Style cleanup and simplify node defs fetching in worktable

pull/5/head
jp 2015-08-01 18:30:01 +02:00
parent 994cf97fe4
commit 5d8db6a8ef
3 changed files with 47 additions and 105 deletions

View File

@ -29,7 +29,7 @@ local default_inventory_formspecs = {
"list[context;main;0,0.3;8,4;]"..
"list[current_player;main;0,4.85;8,1;]"..
"list[current_player;main;0,6.08;8,3;8]"..
default.get_hotbar_bg(0,4.85),
default.get_hotbar_bg(0, 4.85)
}
local function get_formspec_by_size(size)
@ -42,11 +42,11 @@ function xdecor.register(name, def)
def.paramtype = def.paramtype or "light"
def.sounds = def.sounds or default.node_sound_defaults()
if not (def.drawtype == "glasslike_framed"
or def.drawtype == "glasslike_framed_optional"
or def.drawtype == "plantlike"
or def.drawtype == "signlike"
or def.drawtype == "normal") then
if not (def.drawtype == "glasslike_framed" or
def.drawtype == "glasslike_framed_optional" or
def.drawtype == "plantlike" or
def.drawtype == "signlike" or
def.drawtype == "normal") then
def.paramtype2 = def.paramtype2 or "facedir"
end

View File

@ -4,7 +4,7 @@ screwdriver = screwdriver or {}
minetest.register_entity("xdecor:f_item", {
hp_max = 1,
visual = "wielditem",
visual_size = {x=.33,y=.33},
visual_size = {x=.33, y=.33},
collisionbox = {0, 0, 0, 0, 0, 0},
physical = false,
textures = {"air"},
@ -16,7 +16,7 @@ minetest.register_entity("xdecor:f_item", {
tmp.texture = nil
else
if staticdata ~= nil and staticdata ~= "" then
local data = staticdata:split(';')
local data = staticdata:split(";")
if data and data[1] and data[2] then
self.nodename = data[1]
self.texture = data[2]
@ -29,7 +29,7 @@ minetest.register_entity("xdecor:f_item", {
end,
get_staticdata = function(self)
if self.nodename ~= nil and self.texture ~= nil then
return self.nodename .. ';' .. self.texture
return self.nodename..";"..self.texture
end
return ""
end
@ -58,18 +58,17 @@ facedir[3] = {x=-1, y=0, z=0}
local update_item = function(pos, node)
remove_item(pos, node)
local meta = minetest.get_meta(pos)
local str_item = meta:get_string("item")
if meta:get_string("item") ~= "" then
if str_item ~= "" then
local posad = facedir[node.param2]
if not posad then return end
pos.x = pos.x + posad.x * 6.5/16
pos.y = pos.y + posad.y * 6.5/16
pos.z = pos.z + posad.z * 6.5/16
if not posad then
return
end
pos.x = pos.x + posad.x*6.5/16
pos.y = pos.y + posad.y*6.5/16
pos.z = pos.z + posad.z*6.5/16
tmp.nodename = node.name
tmp.texture = ItemStack(meta:get_string("item")):get_name()
tmp.texture = ItemStack(str_item):get_name()
local e = minetest.add_entity(pos, "xdecor:f_item")
local yaw = math.pi*2 - node.param2 * math.pi/2
@ -89,6 +88,7 @@ end
xdecor.register("frame", {
description = "Item frame",
groups = {snappy=3},
sounds = xdecor.wood,
on_rotate = screwdriver.disallow,
node_box = {
type = "fixed",
@ -101,14 +101,12 @@ xdecor.register("frame", {
inventory_image = "xdecor_frame.png",
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", "Item frame (owned by "..placer:get_player_name()..")")
local name = placer:get_player_name()
meta:set_string("owner", name)
meta:set_string("infotext", "Item frame (owned by "..name..")")
end,
on_rightclick = function(pos, node, clicker, itemstack)
if not itemstack then
return
end
if not itemstack then return end
local meta = minetest.get_meta(pos)
if clicker:get_player_name() == meta:get_string("owner") then
drop_item(pos, node)
@ -134,12 +132,10 @@ xdecor.register("frame", {
minetest.register_abm({
nodenames = {"xdecor:frame"},
interval = 5,
interval = 10,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
if #minetest.get_objects_inside_radius(pos, 0.5) > 0 then
return
end
if #minetest.get_objects_inside_radius(pos, 0.5) > 0 then return end
update_item(pos, node)
end
})

View File

@ -5,33 +5,21 @@ local material = {
"cobble", "mossycobble", "desert_cobble",
"stone", "sandstone", "desert_stone", "obsidian",
"stonebrick", "sandstonebrick", "desert_stonebrick", "obsidianbrick",
"coalblock", "copperblock", "bronzeblock",
"goldblock", "steelblock", "diamondblock",
"clay", "ice", "meselamp",
"coalblock", "copperblock", "steelblock", "goldblock",
"bronzeblock", "mese", "diamondblock",
"brick", "clay", "ice", "meselamp",
"glass", "obsidian_glass"
}
local def = { -- Node name, yield, nodebox shape.
{ "nanoslab", "16",
{-0.5, -0.5, -0.5, 0, -0.4375, 0} },
{ "micropanel", "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", "1", {
{-0.5, -0.5, -0.5, 0.5, 0, 0.5},
{-0.5, 0, 0, 0, 0.5, 0.5} } },
{ "stair", "1", {
{-0.5, -0.5, -0.5, 0.5, 0, 0.5},
{-0.5, 0, 0, 0.5, 0.5, 0.5} } },
{ "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} } }
{ "nanoslab", "16", {-0.5, -0.5, -0.5, 0, -0.4375, 0} },
{ "micropanel", "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", "1", { {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, {-0.5, 0, 0, 0, 0.5, 0.5} } },
{ "stair", "1", { {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, {-0.5, 0, 0, 0.5, 0.5, 0.5} } },
{ "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} } }
}
local function xconstruct(pos)
@ -109,27 +97,20 @@ local function xput(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if listname == "output" then
return 0
end
if listname == "output" then return 0 end
if listname == "hammer" then
if stack:get_name() == "xdecor:hammer" then
return 1
else
return 0
end
if stack:get_name() == "xdecor:hammer" then return 1
else return 0 end
end
if listname == "tool" then
local tname = stack:get_name()
local tdef = minetest.registered_tools[tname]
local twear = stack:get_wear()
if tdef and twear > 0 then
return 1
else
return 0
end
if tdef and twear > 0 then return 1
else return 0 end
end
return stack:get_count()
end
@ -148,55 +129,20 @@ xdecor.register("worktable", {
allow_metadata_inventory_put = xput
})
local function light(mat)
if (mat == "meselamp") then
return 12
else
return 0
end
end
local function sound(mat)
if string.find(mat, "glass") or string.find(mat, "lamp") or
string.find(mat, "ice") then
return default.node_sound_glass_defaults()
elseif string.find(mat, "wood") or string.find(mat, "tree") then
return default.node_sound_wood_defaults()
else
return default.node_sound_stone_defaults()
end
end
local function name(mat)
if string.find(mat, "block") then
local newname = string.gsub(mat, "(block)", "_%1")
return "default_"..newname..".png"
elseif string.find(mat, "brick") then
local newname = string.gsub(mat, "(brick)", "_%1")
return "default_"..newname..".png"
elseif string.find(mat, "tree") then
local newname = string.gsub(mat, "(tree)", "%1_top")
return "default_"..newname..".png"
else
return "default_"..mat..".png"
end
end
for m=1, #material do
local v = material[m]
local light = light(v)
local sound = sound(v)
local tile = name(v)
for n=1, #def do
local w = def[n]
local nodename = "default:"..v
local ndef = minetest.registered_nodes[nodename]
xdecor.register(w[1].."_"..v, {
description = string.sub(string.upper(w[1]), 0, 1)..
string.sub(w[1], 2),
light_source = light,
sounds = sound,
tiles = {tile},
groups = {snappy=2, cracky=3, not_in_creative_inventory=1},
light_source = ndef.light_source,
sounds = ndef.sounds,
tiles = ndef.tiles,
groups = {snappy=3, not_in_creative_inventory=1},
node_box = {
type = "fixed",
fixed = w[3]