2015-04-07 09:46:55 -07:00
|
|
|
-- xPanes mod by xyz
|
|
|
|
function pane(node, desc, dropitem, recipeitem)
|
|
|
|
local function rshift(x, by)
|
|
|
|
return math.floor(x / 2 ^ by)
|
|
|
|
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},
|
|
|
|
}
|
|
|
|
|
|
|
|
local function update_pane(pos)
|
2015-05-05 04:01:09 -07:00
|
|
|
if minetest.get_node(pos).name:find("xpanes:pane_"..node) == nil then
|
2015-04-07 09:46:55 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local sum = 0
|
|
|
|
for i = 1, 4 do
|
2015-05-05 04:01:09 -07:00
|
|
|
local node = minetest.get_node({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z})
|
2015-04-07 09:46:55 -07:00
|
|
|
if minetest.registered_nodes[node.name].walkable ~= false then
|
|
|
|
if string.find(node.name, "fence") == nil then
|
|
|
|
if string.find(node.name, "mesecons") == nil then
|
|
|
|
sum = sum + 2 ^ (i - 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if sum == 0 then
|
|
|
|
sum = 15
|
|
|
|
end
|
2015-05-05 04:01:09 -07:00
|
|
|
minetest.add_node(pos, {name = "xpanes:pane_"..node.."_"..sum})
|
2015-04-07 09:46:55 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
local function update_nearby(pos)
|
|
|
|
for i = 1,4 do
|
|
|
|
update_pane({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local half_blocks = {
|
|
|
|
{0, -0.5, -0.06, 0.5, 0.5, 0.06},
|
|
|
|
{-0.06, -0.5, 0, 0.06, 0.5, 0.5},
|
|
|
|
{-0.5, -0.5, -0.06, 0, 0.5, 0.06},
|
|
|
|
{-0.06, -0.5, -0.5, 0.06, 0.5, 0}
|
|
|
|
}
|
|
|
|
|
|
|
|
local full_blocks = {
|
|
|
|
{-0.5, -0.5, -0.06, 0.5, 0.5, 0.06},
|
|
|
|
{-0.06, -0.5, -0.5, 0.06, 0.5, 0.5}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i = 1, 15 do
|
|
|
|
local need = {}
|
|
|
|
local cnt = 0
|
|
|
|
for j = 1, 4 do
|
|
|
|
if rshift(i, j - 1) % 2 == 1 then
|
|
|
|
need[j] = true
|
|
|
|
cnt = cnt + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local take = {}
|
|
|
|
if need[1] == true and need[3] == true then
|
|
|
|
need[1] = nil
|
|
|
|
need[3] = nil
|
|
|
|
table.insert(take, full_blocks[1])
|
|
|
|
end
|
|
|
|
if need[2] == true and need[4] == true then
|
|
|
|
need[2] = nil
|
|
|
|
need[4] = nil
|
|
|
|
table.insert(take, full_blocks[2])
|
|
|
|
end
|
|
|
|
for k in pairs(need) do
|
|
|
|
table.insert(take, half_blocks[k])
|
|
|
|
end
|
|
|
|
local texture = "xpanes_pane_"..node..".png"
|
|
|
|
if cnt == 1 then
|
|
|
|
texture = "xpanes_pane_half_"..node..".png"
|
|
|
|
end
|
|
|
|
minetest.register_node("xpanes:pane_"..node.."_"..i, {
|
|
|
|
drawtype = "nodebox",
|
2016-01-13 16:11:56 -08:00
|
|
|
tiles = {"xpanes_top_"..node..".png", "xpanes_top_"..node..".png", texture},
|
2015-04-07 09:46:55 -07:00
|
|
|
paramtype = "light",
|
|
|
|
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
|
|
|
|
drop = dropitem,
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = take
|
|
|
|
},
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = take
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("xpanes:pane_"..node, {
|
|
|
|
description = desc,
|
2016-01-13 16:11:56 -08:00
|
|
|
tiles = {"xpanes_space.png"},
|
2015-04-07 09:46:55 -07:00
|
|
|
inventory_image = "xpanes_pane_"..node..".png",
|
|
|
|
wield_image = "xpanes_pane_"..node..".png",
|
|
|
|
node_placement_prediction = "",
|
|
|
|
on_construct = update_pane,
|
|
|
|
drop = "",
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_on_placenode(update_nearby)
|
|
|
|
minetest.register_on_dignode(update_nearby)
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = 'xpanes:pane_'..node..' 16',
|
|
|
|
recipe = {
|
|
|
|
{recipeitem, recipeitem, recipeitem},
|
|
|
|
{recipeitem, recipeitem, recipeitem}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
pane("glass", "Glass Pane", "", "default:glass")
|
2015-05-05 12:57:19 -07:00
|
|
|
pane("iron", "Iron Bars", "xpanes:pane_iron", "default:steel_ingot")
|
|
|
|
|
|
|
|
|