2014-07-05 22:45:46 +02:00
|
|
|
|
2016-03-17 08:40:30 +01:00
|
|
|
local function is_pane(pos)
|
|
|
|
return minetest.get_item_group(minetest.get_node(pos).name, "pane") > 0
|
2014-04-17 20:42:30 +02:00
|
|
|
end
|
|
|
|
|
2016-03-17 08:40:30 +01:00
|
|
|
local function connects_dir(pos, name, dir)
|
|
|
|
local aside = vector.add(pos, minetest.facedir_to_dir(dir))
|
|
|
|
if is_pane(aside) then
|
|
|
|
return true
|
2014-07-07 03:49:47 +02:00
|
|
|
end
|
2016-03-17 08:40:30 +01:00
|
|
|
|
|
|
|
local connects_to = minetest.registered_nodes[name].connects_to
|
|
|
|
if not connects_to then
|
|
|
|
return false
|
2014-07-07 03:49:47 +02:00
|
|
|
end
|
2016-03-17 08:40:30 +01:00
|
|
|
local list = minetest.find_nodes_in_area(aside, aside, connects_to)
|
|
|
|
|
|
|
|
if #list > 0 then
|
|
|
|
return true
|
2014-07-07 03:49:47 +02:00
|
|
|
end
|
2016-03-17 08:40:30 +01:00
|
|
|
|
|
|
|
return false
|
2014-04-17 20:42:30 +02:00
|
|
|
end
|
|
|
|
|
2016-03-17 08:40:30 +01:00
|
|
|
local function swap(pos, node, name, param2)
|
|
|
|
if node.name == name and node.param2 == param2 then
|
2014-09-16 17:11:54 +02:00
|
|
|
return
|
|
|
|
end
|
2016-03-17 08:40:30 +01:00
|
|
|
|
|
|
|
minetest.set_node(pos, {name = name, param2 = param2})
|
2014-04-17 20:42:30 +02:00
|
|
|
end
|
|
|
|
|
2016-03-17 08:40:30 +01:00
|
|
|
local function update_pane(pos)
|
|
|
|
if not is_pane(pos) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local name = node.name
|
|
|
|
if name:sub(-5) == "_flat" then
|
|
|
|
name = name:sub(1, -6)
|
|
|
|
end
|
2015-08-31 18:35:59 +02:00
|
|
|
|
2016-03-17 08:40:30 +01:00
|
|
|
local any = node.param2
|
|
|
|
local c = {}
|
|
|
|
local count = 0
|
|
|
|
for dir = 0, 3 do
|
|
|
|
c[dir] = connects_dir(pos, name, dir)
|
|
|
|
if c[dir] then
|
|
|
|
any = dir
|
|
|
|
count = count + 1
|
2014-07-07 03:49:47 +02:00
|
|
|
end
|
2016-03-17 08:40:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if count == 0 then
|
|
|
|
swap(pos, node, name .. "_flat", any)
|
|
|
|
elseif count == 1 then
|
|
|
|
swap(pos, node, name .. "_flat", (any + 1) % 4)
|
|
|
|
elseif count == 2 then
|
|
|
|
if (c[0] and c[2]) or (c[1] and c[3]) then
|
|
|
|
swap(pos, node, name .. "_flat", (any + 1) % 4)
|
|
|
|
else
|
|
|
|
swap(pos, node, name, 0)
|
2014-07-07 03:49:47 +02:00
|
|
|
end
|
2016-03-17 08:40:30 +01:00
|
|
|
else
|
|
|
|
swap(pos, node, name, 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_placenode(function(pos, node)
|
|
|
|
if minetest.get_item_group(node, "pane") then
|
|
|
|
update_pane(pos)
|
|
|
|
end
|
|
|
|
for i = 0, 3 do
|
|
|
|
local dir = minetest.facedir_to_dir(i)
|
|
|
|
update_pane(vector.add(pos, dir))
|
2014-07-07 03:49:47 +02:00
|
|
|
end
|
2016-03-17 08:40:30 +01:00
|
|
|
end)
|
2014-04-17 20:42:30 +02:00
|
|
|
|
2016-03-17 08:40:30 +01:00
|
|
|
minetest.register_on_dignode(function(pos)
|
|
|
|
for i = 0, 3 do
|
|
|
|
local dir = minetest.facedir_to_dir(i)
|
|
|
|
update_pane(vector.add(pos, dir))
|
2015-08-31 18:35:59 +02:00
|
|
|
end
|
2016-03-17 08:40:30 +01:00
|
|
|
end)
|
2015-08-31 18:35:59 +02:00
|
|
|
|
2016-03-17 08:40:30 +01:00
|
|
|
xpanes = {}
|
|
|
|
function xpanes.register_pane(name, def)
|
|
|
|
for i = 1, 15 do
|
|
|
|
minetest.register_alias("xpanes:" .. name .. "_" .. i, "xpanes:" .. name .. "_flat")
|
2014-09-16 17:11:54 +02:00
|
|
|
end
|
|
|
|
|
2016-03-17 08:40:30 +01:00
|
|
|
local flatgroups = table.copy(def.groups)
|
|
|
|
flatgroups.pane = 1
|
|
|
|
minetest.register_node(":xpanes:" .. name .. "_flat", {
|
|
|
|
description = def.description,
|
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
|
|
|
is_ground_content = false,
|
|
|
|
sunlight_propagates = true,
|
|
|
|
inventory_image = def.inventory_image,
|
|
|
|
wield_image = def.wield_image,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
tiles = {def.textures[3], def.textures[3], def.textures[1]},
|
|
|
|
groups = flatgroups,
|
|
|
|
drop = "xpanes:" .. name .. "_flat",
|
|
|
|
sounds = def.sounds,
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
|
|
|
|
},
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
|
|
|
|
},
|
|
|
|
connect_sides = { "left", "right" },
|
|
|
|
})
|
|
|
|
|
|
|
|
local groups = table.copy(def.groups)
|
|
|
|
groups.pane = 1
|
|
|
|
groups.not_in_creative_inventory = 1
|
|
|
|
minetest.register_node(":xpanes:" .. name, {
|
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
|
|
|
is_ground_content = false,
|
|
|
|
sunlight_propagates = true,
|
|
|
|
description = def.description,
|
|
|
|
tiles = {def.textures[3], def.textures[3], def.textures[1]},
|
|
|
|
groups = groups,
|
|
|
|
drop = "xpanes:" .. name .. "_flat",
|
|
|
|
sounds = def.sounds,
|
|
|
|
node_box = {
|
|
|
|
type = "connected",
|
|
|
|
fixed = {{-1/32, -1/2, -1/32, 1/32, 1/2, 1/32}},
|
|
|
|
connect_front = {{-1/32, -1/2, -1/2, 1/32, 1/2, -1/32}},
|
|
|
|
connect_left = {{-1/2, -1/2, -1/32, -1/32, 1/2, 1/32}},
|
|
|
|
connect_back = {{-1/32, -1/2, 1/32, 1/32, 1/2, 1/2}},
|
|
|
|
connect_right = {{1/32, -1/2, -1/32, 1/2, 1/2, 1/32}},
|
|
|
|
},
|
|
|
|
connects_to = {"group:pane", "group:stone", "group:glass", "group:wood", "group:tree"},
|
|
|
|
})
|
2014-04-17 20:42:30 +02:00
|
|
|
|
2014-07-07 03:49:47 +02:00
|
|
|
minetest.register_craft({
|
2016-03-17 08:40:30 +01:00
|
|
|
output = "xpanes:" .. name .. "_flat 16",
|
2014-07-07 03:49:47 +02:00
|
|
|
recipe = def.recipe
|
|
|
|
})
|
2014-04-17 20:42:30 +02:00
|
|
|
end
|
|
|
|
|
2014-07-05 22:45:46 +02:00
|
|
|
xpanes.register_pane("pane", {
|
2014-07-07 03:49:47 +02:00
|
|
|
description = "Glass Pane",
|
|
|
|
textures = {"default_glass.png","xpanes_pane_half.png","xpanes_white.png"},
|
|
|
|
inventory_image = "default_glass.png",
|
|
|
|
wield_image = "default_glass.png",
|
|
|
|
sounds = default.node_sound_glass_defaults(),
|
2016-03-17 08:40:30 +01:00
|
|
|
groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3},
|
2014-07-07 03:49:47 +02:00
|
|
|
recipe = {
|
2015-08-31 18:35:59 +02:00
|
|
|
{"default:glass", "default:glass", "default:glass"},
|
|
|
|
{"default:glass", "default:glass", "default:glass"}
|
2014-04-17 20:42:30 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2014-07-05 22:45:46 +02:00
|
|
|
xpanes.register_pane("bar", {
|
2014-07-07 03:49:47 +02:00
|
|
|
description = "Iron bar",
|
2016-10-31 22:20:26 +01:00
|
|
|
textures = {"xpanes_bar.png","xpanes_bar.png","xpanes_bar_top.png"},
|
2014-07-07 03:49:47 +02:00
|
|
|
inventory_image = "xpanes_bar.png",
|
|
|
|
wield_image = "xpanes_bar.png",
|
2016-03-17 08:40:30 +01:00
|
|
|
groups = {cracky=2},
|
2016-10-20 01:34:22 +02:00
|
|
|
sounds = default.node_sound_metal_defaults(),
|
2014-07-07 03:49:47 +02:00
|
|
|
recipe = {
|
2015-08-31 18:35:59 +02:00
|
|
|
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
|
|
|
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
|
2014-04-17 20:42:30 +02:00
|
|
|
}
|
|
|
|
})
|
2014-07-07 03:49:47 +02:00
|
|
|
|
2016-03-17 08:40:30 +01:00
|
|
|
minetest.register_lbm({
|
|
|
|
name = "xpanes:gen2",
|
|
|
|
nodenames = {"group:pane"},
|
|
|
|
action = function(pos, node)
|
|
|
|
update_pane(pos)
|
|
|
|
for i = 0, 3 do
|
|
|
|
local dir = minetest.facedir_to_dir(i)
|
|
|
|
update_pane(vector.add(pos, dir))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|