Cleaning of xwall
This commit is contained in:
parent
7edbaa3af4
commit
dc49a06701
2
init.lua
2
init.lua
@ -1,3 +1,4 @@
|
||||
--local t = os.clock()
|
||||
xdecor = {}
|
||||
local modpath = minetest.get_modpath("xdecor")
|
||||
|
||||
@ -15,4 +16,5 @@ dofile(modpath.."/nodes.lua")
|
||||
dofile(modpath.."/sitting.lua")
|
||||
dofile(modpath.."/worktable.lua")
|
||||
dofile(modpath.."/xwall.lua")
|
||||
--print(string.format("xdecor loaded in %.2f ms", (os.clock()-t)*1000))
|
||||
|
||||
|
@ -367,7 +367,7 @@ xdecor.register("painting_1", {
|
||||
wall_bottom = {-0.4375, -0.5, -0.3125, 0.4375, -0.4375, 0.3125},
|
||||
wall_side = {-0.5, -0.3125, -0.4375, -0.4375, 0.3125, 0.4375}
|
||||
},
|
||||
after_place_node = function(pos, _, _, _)
|
||||
on_construct = function(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
minetest.set_node(pos, {name="xdecor:painting_"..math.random(1,4), param2=node.param2})
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ xdecor.register("chair", {
|
||||
{-0.3125, -0.125, -0.3125, 0.3125, 0, 0.1875}}
|
||||
},
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
||||
for _, p in pairs(objs) do
|
||||
if p:get_player_name() ~= clicker:get_player_name() then return end
|
||||
end
|
||||
@ -56,7 +56,7 @@ xdecor.register("chair", {
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
local pname = player:get_player_name()
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
||||
|
||||
for _, p in pairs(objs) do
|
||||
if not player or not player:is_player() or
|
||||
@ -77,7 +77,7 @@ xdecor.register("cushion", {
|
||||
on_place = minetest.rotate_node,
|
||||
node_box = xdecor.nodebox.slab_y(-0.5, 0.5),
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
||||
for _, p in pairs(objs) do
|
||||
if p:get_player_name() ~= clicker:get_player_name() then return end
|
||||
end
|
||||
@ -87,7 +87,7 @@ xdecor.register("cushion", {
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
local pname = player:get_player_name()
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
||||
|
||||
for _, p in pairs(objs) do
|
||||
if not player or not player:is_player() or
|
||||
|
88
xwall.lua
88
xwall.lua
@ -20,8 +20,8 @@ for i = 1, #profiles do
|
||||
end
|
||||
|
||||
local directions = {
|
||||
{x = 1, y = 0, z = 0}, {x = 0, y = 0, z = 1},
|
||||
{x = -1, y = 0, z = 0}, {x = 0, y = 0, z = -1}
|
||||
{x=1, y=0, z=0}, {x=0, y=0, z=1},
|
||||
{x=-1, y=0, z=0}, {x=0, y=0, z=-1}
|
||||
}
|
||||
|
||||
function xwall.update_one_node(pos, name, digged)
|
||||
@ -72,34 +72,6 @@ function xwall.update(pos, name, active, has_been_digged)
|
||||
end
|
||||
end
|
||||
|
||||
function xwall.register(name, def, node_box_data)
|
||||
for k, v in pairs(node_box_data) do
|
||||
def.drawtype = "nodebox"
|
||||
def.paramtype = "light"
|
||||
def.paramtype2 = "facedir"
|
||||
def.drop = name.."_ln"
|
||||
def.node_box = {type = "fixed", fixed = node_box_data[k]}
|
||||
|
||||
if not def.tiles then def.tiles = def.textures end
|
||||
if not def.groups then
|
||||
def.groups = {xwall=1, cracky=3}
|
||||
else def.groups.xwall = 1 end
|
||||
|
||||
local newdef = table.copy(def)
|
||||
if k == "ln" then
|
||||
newdef.on_construct = function(pos)
|
||||
return xwall.update(pos, name.."_ln", true, nil)
|
||||
end
|
||||
else newdef.groups.not_in_creative_inventory = 1 end
|
||||
|
||||
newdef.after_dig_node = function(pos, _, _, _)
|
||||
return xwall.update(pos, name.."_ln", true, true)
|
||||
end
|
||||
|
||||
minetest.register_node(name.."_"..k, newdef)
|
||||
end
|
||||
end
|
||||
|
||||
function xwall.construct_node_box_data(node_box_list, center_node_box_list, node_box_line)
|
||||
local res = {}
|
||||
res.c0, res.c1, res.c2, res.c3, res.c4 = {}, {}, {}, {}, {}
|
||||
@ -134,32 +106,56 @@ function xwall.construct_node_box_data(node_box_list, center_node_box_list, node
|
||||
res.c4[#res.c4+1] = v
|
||||
end
|
||||
|
||||
if #res.c0 < 1 then res.c0 = nil end
|
||||
if #res.c0 < 1 then
|
||||
res.c0 = nil
|
||||
end
|
||||
|
||||
res.ln = node_box_line
|
||||
return res
|
||||
end
|
||||
|
||||
function xwall.register_wall(name, tiles, def)
|
||||
function xwall.register_wall(name, tiles)
|
||||
local groups, def = {}, {}
|
||||
local node_box_data = xwall.construct_node_box_data(
|
||||
{{-.1875,-.6875,0,.1875,.3125,.5}},{{-.25,-.6875,-.25,.25,.5,.25}},
|
||||
{{-.1875,-.6875,0,.1875,.3125,.5}},
|
||||
{{-.25,-.6875,-.25,.25,.5,.25}},
|
||||
{{-.1875,-.6875,-.5,.1875,.3125,.5}}
|
||||
)
|
||||
|
||||
if def then return end
|
||||
def = {
|
||||
description = string.sub(name:gsub("%l", string.upper, 7), 8, -6).." Wall",
|
||||
textures = {tiles, tiles, tiles, tiles},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
groups = {cracky=3, stone=1, pane=1},
|
||||
sunlight_propagates = true,
|
||||
on_rotate = screwdriver.disallow,
|
||||
collision_box = {
|
||||
type = "fixed",
|
||||
fixed = {-.5, -.5, -.25, .5, 1, .25}
|
||||
local function group(k)
|
||||
groups = {xwall=1, cracky=3}
|
||||
if k ~= "ln" then
|
||||
groups.not_in_creative_inventory=1
|
||||
end
|
||||
return groups
|
||||
end
|
||||
|
||||
for k, v in pairs(node_box_data) do
|
||||
def = {
|
||||
description = name:match("[%w_]+:(%a+)"):gsub("^%l", string.upper).." Wall",
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
tiles = {tiles},
|
||||
drop = name.."_ln",
|
||||
node_box = {type = "fixed", fixed = node_box_data[k]},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
groups = group(k),
|
||||
sunlight_propagates = true,
|
||||
on_rotate = screwdriver.disallow,
|
||||
collision_box = {
|
||||
type = "fixed",
|
||||
fixed = {-.5, -.5, -.25, .5, 1, .25}
|
||||
},
|
||||
on_construct = function(pos)
|
||||
return xwall.update(pos, name.."_ln", true, nil)
|
||||
end,
|
||||
after_dig_node = function(pos, _, _, _)
|
||||
return xwall.update(pos, name.."_ln", true, true)
|
||||
end
|
||||
}
|
||||
}
|
||||
xwall.register(name, def, node_box_data)
|
||||
minetest.register_node(name.."_"..k, def)
|
||||
end
|
||||
end
|
||||
|
||||
xwall.register_wall("xdecor:cobble_wall", "default_cobble.png")
|
||||
|
Loading…
Reference in New Issue
Block a user