Convert spaces to tabs and add unknown node checks to xpanes

This commit is contained in:
ShadowNinja 2014-07-06 21:49:47 -04:00
parent 5e0c49345a
commit ca7f6bb97a
1 changed files with 150 additions and 139 deletions

View File

@ -11,15 +11,21 @@ local directions = {
{x = 0, y = 0, z = -1},
}
local function update_pane(pos,name)
if minetest.get_node(pos).name:find("xpanes:"..name) == nil then
local function update_pane(pos, name)
if not minetest.get_node(pos).name:find("^xpanes:"..name) then
return
end
local sum = 0
for i = 1, 4 do
local node = minetest.get_node({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z})
local pane_num = minetest.registered_nodes[node.name].groups.pane or 0
if (minetest.registered_nodes[node.name].walkable ~= false and minetest.registered_nodes[node.name].drawtype ~= "nodebox") or pane_num > 0 then
for i, dir in pairs(directions) do
local node = minetest.get_node({
x = pos.x + dir.x,
y = pos.y + dir.y,
z = pos.z + dir.z
})
local def = minetest.registered_nodes[node.name]
local pane_num = def and def.groups.pane or 0
if pane_num > 0 or not def or (def.walkable ~= false and
def.drawtype ~= "nodebox") then
sum = sum + 2 ^ (i - 1)
end
end
@ -29,42 +35,46 @@ local function update_pane(pos,name)
minetest.set_node(pos, {name = "xpanes:"..name.."_"..sum})
end
local function update_nearby(pos,n)
if n == nil then n = minetest.get_node(pos) end
if not n or not n.name then return end
local name = string.sub(n.name,8,10)
if name ~= "bar" then name = "pane" end
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}, name)
local function update_nearby(pos, node)
node = node or minetest.get_node(pos)
if node.name:sub(1, 7) ~= "xpanes:" then return end
local underscore_pos = node.name:find("_") or 0
local name = node.name:sub(8, underscore_pos - 1)
for i, dir in pairs(directions) do
update_pane({
x = pos.x + dir.x,
y = pos.y + dir.y,
z = pos.z + dir.z
}, name)
end
end
local half_blocks = {
local half_boxes = {
{0, -0.5, -1/32, 0.5, 0.5, 1/32},
{-1/32, -0.5, 0, 1/32, 0.5, 0.5},
{-0.5, -0.5, -1/32, 0, 0.5, 1/32},
{-1/32, -0.5, -0.5, 1/32, 0.5, 0}
}
local full_blocks = {
local full_boxes = {
{-0.5, -0.5, -1/32, 0.5, 0.5, 1/32},
{-1/32, -0.5, -0.5, 1/32, 0.5, 0.5}
}
local sb_half_blocks = {
local sb_half_boxes = {
{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 sb_full_blocks = {
local sb_full_boxes = {
{-0.5, -0.5, -0.06, 0.5, 0.5, 0.06},
{-0.06, -0.5, -0.5, 0.06, 0.5, 0.5}
}
--register panes and bars
function xpanes.register_pane(name, def)
for i = 1, 15 do
for i = 1, 15 do
local need = {}
local cnt = 0
for j = 1, 4 do
@ -78,18 +88,18 @@ for i = 1, 15 do
if need[1] == true and need[3] == true then
need[1] = nil
need[3] = nil
table.insert(take, full_blocks[1])
table.insert(take2, sb_full_blocks[1])
table.insert(take, full_boxes[1])
table.insert(take2, sb_full_boxes[1])
end
if need[2] == true and need[4] == true then
need[2] = nil
need[4] = nil
table.insert(take, full_blocks[2])
table.insert(take2, sb_full_blocks[2])
table.insert(take, full_boxes[2])
table.insert(take2, sb_full_boxes[2])
end
for k in pairs(need) do
table.insert(take, half_blocks[k])
table.insert(take2, sb_half_blocks[k])
table.insert(take, half_boxes[k])
table.insert(take2, sb_half_boxes[k])
end
local texture = def.textures[1]
if cnt == 1 then
@ -111,14 +121,14 @@ for i = 1, 15 do
fixed = take2
}
})
end
end
minetest.register_node("xpanes:"..name, def)
minetest.register_node("xpanes:"..name, def)
minetest.register_craft({
minetest.register_craft({
output = "xpanes:"..name.." 16",
recipe = def.recipe
})
})
end
minetest.register_on_placenode(update_nearby)
@ -139,7 +149,7 @@ xpanes.register_pane("pane", {
inventory_image = "default_glass.png",
wield_image = "default_glass.png",
sounds = default.node_sound_glass_defaults(),
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,pane=1},
groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3, pane=1},
on_construct = function(pos)
update_pane(pos, "pane")
end,
@ -163,7 +173,7 @@ xpanes.register_pane("bar", {
textures = {"xpanes_bar.png","xpanes_bar.png","xpanes_space.png"},
inventory_image = "xpanes_bar.png",
wield_image = "xpanes_bar.png",
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,pane=1},
groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3, pane=1},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
update_pane(pos, "bar")
@ -173,3 +183,4 @@ xpanes.register_pane("bar", {
{'default:glass', 'default:glass', 'default:glass'}
}
})