Style cleanup and simplify node defs fetching in worktable
This commit is contained in:
parent
994cf97fe4
commit
5d8db6a8ef
@ -29,7 +29,7 @@ local default_inventory_formspecs = {
|
|||||||
"list[context;main;0,0.3;8,4;]"..
|
"list[context;main;0,0.3;8,4;]"..
|
||||||
"list[current_player;main;0,4.85;8,1;]"..
|
"list[current_player;main;0,4.85;8,1;]"..
|
||||||
"list[current_player;main;0,6.08;8,3;8]"..
|
"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)
|
local function get_formspec_by_size(size)
|
||||||
@ -42,11 +42,11 @@ function xdecor.register(name, def)
|
|||||||
def.paramtype = def.paramtype or "light"
|
def.paramtype = def.paramtype or "light"
|
||||||
def.sounds = def.sounds or default.node_sound_defaults()
|
def.sounds = def.sounds or default.node_sound_defaults()
|
||||||
|
|
||||||
if not (def.drawtype == "glasslike_framed"
|
if not (def.drawtype == "glasslike_framed" or
|
||||||
or def.drawtype == "glasslike_framed_optional"
|
def.drawtype == "glasslike_framed_optional" or
|
||||||
or def.drawtype == "plantlike"
|
def.drawtype == "plantlike" or
|
||||||
or def.drawtype == "signlike"
|
def.drawtype == "signlike" or
|
||||||
or def.drawtype == "normal") then
|
def.drawtype == "normal") then
|
||||||
def.paramtype2 = def.paramtype2 or "facedir"
|
def.paramtype2 = def.paramtype2 or "facedir"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ screwdriver = screwdriver or {}
|
|||||||
minetest.register_entity("xdecor:f_item", {
|
minetest.register_entity("xdecor:f_item", {
|
||||||
hp_max = 1,
|
hp_max = 1,
|
||||||
visual = "wielditem",
|
visual = "wielditem",
|
||||||
visual_size = {x=.33,y=.33},
|
visual_size = {x=.33, y=.33},
|
||||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||||
physical = false,
|
physical = false,
|
||||||
textures = {"air"},
|
textures = {"air"},
|
||||||
@ -16,7 +16,7 @@ minetest.register_entity("xdecor:f_item", {
|
|||||||
tmp.texture = nil
|
tmp.texture = nil
|
||||||
else
|
else
|
||||||
if staticdata ~= nil and staticdata ~= "" then
|
if staticdata ~= nil and staticdata ~= "" then
|
||||||
local data = staticdata:split(';')
|
local data = staticdata:split(";")
|
||||||
if data and data[1] and data[2] then
|
if data and data[1] and data[2] then
|
||||||
self.nodename = data[1]
|
self.nodename = data[1]
|
||||||
self.texture = data[2]
|
self.texture = data[2]
|
||||||
@ -29,7 +29,7 @@ minetest.register_entity("xdecor:f_item", {
|
|||||||
end,
|
end,
|
||||||
get_staticdata = function(self)
|
get_staticdata = function(self)
|
||||||
if self.nodename ~= nil and self.texture ~= nil then
|
if self.nodename ~= nil and self.texture ~= nil then
|
||||||
return self.nodename .. ';' .. self.texture
|
return self.nodename..";"..self.texture
|
||||||
end
|
end
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
@ -58,18 +58,17 @@ facedir[3] = {x=-1, y=0, z=0}
|
|||||||
local update_item = function(pos, node)
|
local update_item = function(pos, node)
|
||||||
remove_item(pos, node)
|
remove_item(pos, node)
|
||||||
local meta = minetest.get_meta(pos)
|
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]
|
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.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 e = minetest.add_entity(pos, "xdecor:f_item")
|
||||||
local yaw = math.pi*2 - node.param2 * math.pi/2
|
local yaw = math.pi*2 - node.param2 * math.pi/2
|
||||||
@ -89,6 +88,7 @@ end
|
|||||||
xdecor.register("frame", {
|
xdecor.register("frame", {
|
||||||
description = "Item frame",
|
description = "Item frame",
|
||||||
groups = {snappy=3},
|
groups = {snappy=3},
|
||||||
|
sounds = xdecor.wood,
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
@ -101,14 +101,12 @@ xdecor.register("frame", {
|
|||||||
inventory_image = "xdecor_frame.png",
|
inventory_image = "xdecor_frame.png",
|
||||||
after_place_node = function(pos, placer, itemstack)
|
after_place_node = function(pos, placer, itemstack)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("owner", placer:get_player_name())
|
local name = placer:get_player_name()
|
||||||
meta:set_string("infotext", "Item frame (owned by "..placer:get_player_name()..")")
|
meta:set_string("owner", name)
|
||||||
|
meta:set_string("infotext", "Item frame (owned by "..name..")")
|
||||||
end,
|
end,
|
||||||
on_rightclick = function(pos, node, clicker, itemstack)
|
on_rightclick = function(pos, node, clicker, itemstack)
|
||||||
if not itemstack then
|
if not itemstack then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if clicker:get_player_name() == meta:get_string("owner") then
|
if clicker:get_player_name() == meta:get_string("owner") then
|
||||||
drop_item(pos, node)
|
drop_item(pos, node)
|
||||||
@ -134,12 +132,10 @@ xdecor.register("frame", {
|
|||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"xdecor:frame"},
|
nodenames = {"xdecor:frame"},
|
||||||
interval = 5,
|
interval = 10,
|
||||||
chance = 1,
|
chance = 1,
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
if #minetest.get_objects_inside_radius(pos, 0.5) > 0 then
|
if #minetest.get_objects_inside_radius(pos, 0.5) > 0 then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
update_item(pos, node)
|
update_item(pos, node)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
102
worktable.lua
102
worktable.lua
@ -5,33 +5,21 @@ local material = {
|
|||||||
"cobble", "mossycobble", "desert_cobble",
|
"cobble", "mossycobble", "desert_cobble",
|
||||||
"stone", "sandstone", "desert_stone", "obsidian",
|
"stone", "sandstone", "desert_stone", "obsidian",
|
||||||
"stonebrick", "sandstonebrick", "desert_stonebrick", "obsidianbrick",
|
"stonebrick", "sandstonebrick", "desert_stonebrick", "obsidianbrick",
|
||||||
"coalblock", "copperblock", "bronzeblock",
|
"coalblock", "copperblock", "steelblock", "goldblock",
|
||||||
"goldblock", "steelblock", "diamondblock",
|
"bronzeblock", "mese", "diamondblock",
|
||||||
"clay", "ice", "meselamp",
|
"brick", "clay", "ice", "meselamp",
|
||||||
"glass", "obsidian_glass"
|
"glass", "obsidian_glass"
|
||||||
}
|
}
|
||||||
|
|
||||||
local def = { -- Node name, yield, nodebox shape.
|
local def = { -- Node name, yield, nodebox shape.
|
||||||
{ "nanoslab", "16",
|
{ "nanoslab", "16", {-0.5, -0.5, -0.5, 0, -0.4375, 0} },
|
||||||
{-0.5, -0.5, -0.5, 0, -0.4375, 0} },
|
{ "micropanel", "16", {-0.5, -0.5, -0.5, 0.5, -0.4375, 0} },
|
||||||
{ "micropanel", "16",
|
{ "microslab", "8", {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5} },
|
||||||
{-0.5, -0.5, -0.5, 0.5, -0.4375, 0} },
|
{ "panel", "4", {-0.5, -0.5, -0.5, 0.5, 0, 0} },
|
||||||
{ "microslab", "8",
|
{ "slab", "2", {-0.5, -0.5, -0.5, 0.5, 0, 0.5} },
|
||||||
{-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5} },
|
{ "outerstair", "1", { {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, {-0.5, 0, 0, 0, 0.5, 0.5} } },
|
||||||
{ "panel", "4",
|
{ "stair", "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.5, -0.5, 0.5, 0, 0} },
|
{ "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} } }
|
||||||
{ "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)
|
local function xconstruct(pos)
|
||||||
@ -109,27 +97,20 @@ 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()
|
||||||
|
|
||||||
if listname == "output" then
|
if listname == "output" then return 0 end
|
||||||
return 0
|
|
||||||
end
|
|
||||||
if listname == "hammer" then
|
if listname == "hammer" then
|
||||||
if stack:get_name() == "xdecor:hammer" then
|
if stack:get_name() == "xdecor:hammer" then return 1
|
||||||
return 1
|
else return 0 end
|
||||||
else
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if listname == "tool" then
|
if listname == "tool" then
|
||||||
local tname = stack:get_name()
|
local tname = stack:get_name()
|
||||||
local tdef = minetest.registered_tools[tname]
|
local tdef = minetest.registered_tools[tname]
|
||||||
local twear = stack:get_wear()
|
local twear = stack:get_wear()
|
||||||
|
|
||||||
if tdef and twear > 0 then
|
if tdef and twear > 0 then return 1
|
||||||
return 1
|
else return 0 end
|
||||||
else
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -148,55 +129,20 @@ xdecor.register("worktable", {
|
|||||||
allow_metadata_inventory_put = xput
|
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
|
for m=1, #material do
|
||||||
local v = material[m]
|
local v = material[m]
|
||||||
local light = light(v)
|
|
||||||
local sound = sound(v)
|
|
||||||
local tile = name(v)
|
|
||||||
|
|
||||||
for n=1, #def do
|
for n=1, #def do
|
||||||
local w = def[n]
|
local w = def[n]
|
||||||
|
local nodename = "default:"..v
|
||||||
|
local ndef = minetest.registered_nodes[nodename]
|
||||||
|
|
||||||
xdecor.register(w[1].."_"..v, {
|
xdecor.register(w[1].."_"..v, {
|
||||||
description = string.sub(string.upper(w[1]), 0, 1)..
|
description = string.sub(string.upper(w[1]), 0, 1)..
|
||||||
string.sub(w[1], 2),
|
string.sub(w[1], 2),
|
||||||
light_source = light,
|
light_source = ndef.light_source,
|
||||||
sounds = sound,
|
sounds = ndef.sounds,
|
||||||
tiles = {tile},
|
tiles = ndef.tiles,
|
||||||
groups = {snappy=2, cracky=3, not_in_creative_inventory=1},
|
groups = {snappy=3, not_in_creative_inventory=1},
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = w[3]
|
fixed = w[3]
|
||||||
|
Loading…
Reference in New Issue
Block a user