commit
159aab16df
1 changed files with 144 additions and 262 deletions
|
@ -1,60 +1,63 @@
|
||||||
local function rshift(x, by)
|
local function rshift(x, by)
|
||||||
return math.floor(x / 2 ^ by)
|
return math.floor(x / 2 ^ by)
|
||||||
end
|
end
|
||||||
|
|
||||||
local directions = {
|
local directions = {
|
||||||
{x = 1, y = 0, z = 0},
|
{x = 1, y = 0, z = 0},
|
||||||
{x = 0, y = 0, z = 1},
|
{x = 0, y = 0, z = 1},
|
||||||
{x = -1, y = 0, z = 0},
|
{x = -1, y = 0, z = 0},
|
||||||
{x = 0, y = 0, z = -1},
|
{x = 0, y = 0, z = -1},
|
||||||
{x = 0, y = -1, z = 0},
|
{x = 0, y = -1, z = 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_wall(pos)
|
local function update_wall(pos)
|
||||||
local typewall = 0
|
local thisnode = minetest.env:get_node(pos)
|
||||||
|
|
||||||
if minetest.env:get_node(pos).name:find("wallet:wall") == 1 then
|
if thisnode.name:find("wallet:wall") ~= 1 and
|
||||||
typewall = typewall + 1
|
thisnode.name:find("wallet:wallmossy") ~= 1 then
|
||||||
end
|
-- Not a wall
|
||||||
if minetest.env:get_node(pos).name:find("wallet:wallmossy") == 1 then
|
|
||||||
typewall = typewall + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if typewall == 0 then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sum = 0
|
|
||||||
for i = 1, 4 do
|
|
||||||
local node = minetest.env:get_node({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z})
|
|
||||||
if minetest.registered_nodes[node.name].walkable then
|
|
||||||
sum = sum + 2 ^ (i - 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local node = minetest.env:get_node({x = pos.x, y = pos.y+1, z = pos.z})
|
-- Get the node's base name, including the underscore since we will need it
|
||||||
if sum == 5 or sum == 10 then
|
local basename = thisnode.name:find("_")
|
||||||
if minetest.registered_nodes[node.name].walkable or node.name == "torches:floor" then
|
if basename == nil then -- New wall
|
||||||
sum = sum + 11
|
basename = thisnode.name .. "_"
|
||||||
end
|
else -- Already placed wall
|
||||||
end
|
basename = thisnode.name:sub(1, basename)
|
||||||
|
end
|
||||||
|
|
||||||
if sum == 0 then
|
local sum = 0
|
||||||
sum = 15
|
|
||||||
end
|
-- Neighbouring walkable nodes
|
||||||
|
for i = 1, 4 do
|
||||||
if typewall == 1 then
|
local dir = directions[i]
|
||||||
minetest.env:add_node(pos, {name = "wallet:wall_"..sum})
|
local node = minetest.env:get_node({x = pos.x + dir.x, y = pos.y + dir.y, z = pos.z + dir.z})
|
||||||
else
|
if minetest.registered_nodes[node.name].walkable then
|
||||||
minetest.env:add_node(pos, {name = "wallet:wallmossy_"..sum})
|
sum = sum + 2 ^ (i - 1)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Torches or walkable nodes above the wall
|
||||||
|
local upnode = minetest.env:get_node({x = pos.x, y = pos.y+1, z = pos.z})
|
||||||
|
if sum == 5 or sum == 10 then
|
||||||
|
if minetest.registered_nodes[upnode.name].walkable or upnode.name == "torches:floor" then
|
||||||
|
sum = sum + 11
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[if sum == 0 then
|
||||||
|
sum = 15
|
||||||
|
end]]
|
||||||
|
|
||||||
|
minetest.env:add_node(pos, {name = basename..sum})
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_wall_global(pos)
|
function update_wall_global(pos)
|
||||||
for i = 1,5 do
|
for i = 1,5 do
|
||||||
update_wall({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z})
|
local dir = directions[i]
|
||||||
end
|
update_wall({x = pos.x + dir.x, y = pos.y + dir.y, z = pos.z + dir.z})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local half_blocks = {
|
local half_blocks = {
|
||||||
|
@ -71,238 +74,118 @@ local full_blocks = {
|
||||||
{-3/16, -0.5, -0.5, 3/16, 5/16, 0.5}
|
{-3/16, -0.5, -0.5, 3/16, 5/16, 0.5}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i = 0, 15 do
|
local function register_wall(nodename, name, texture, invtex)
|
||||||
local need = {}
|
for i = 0, 15 do
|
||||||
local need_pillar = false
|
local need = {}
|
||||||
for j = 1, 4 do
|
local need_pillar = false
|
||||||
if rshift(i, j - 1) % 2 == 1 then
|
for j = 1, 4 do
|
||||||
need[j] = true
|
if rshift(i, j - 1) % 2 == 1 then
|
||||||
end
|
need[j] = true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local take = {}
|
local take = {}
|
||||||
if need[1] == true and need[3] == true then
|
if need[1] == true and need[3] == true then
|
||||||
need[1] = nil
|
need[1] = nil
|
||||||
need[3] = nil
|
need[3] = nil
|
||||||
table.insert(take, full_blocks[1])
|
table.insert(take, full_blocks[1])
|
||||||
end
|
end
|
||||||
if need[2] == true and need[4] == true then
|
if need[2] == true and need[4] == true then
|
||||||
need[2] = nil
|
need[2] = nil
|
||||||
need[4] = nil
|
need[4] = nil
|
||||||
table.insert(take, full_blocks[2])
|
table.insert(take, full_blocks[2])
|
||||||
end
|
end
|
||||||
for k in pairs(need) do
|
for k in pairs(need) do
|
||||||
table.insert(take, half_blocks[k])
|
table.insert(take, half_blocks[k])
|
||||||
need_pillar = true
|
need_pillar = true
|
||||||
end
|
end
|
||||||
if i == 15 or i == 0 then need_pillar = true end
|
if i == 15 or i == 0 then need_pillar = true end
|
||||||
if need_pillar then table.insert(take, pillar) end
|
if need_pillar then table.insert(take, pillar) end
|
||||||
|
|
||||||
minetest.register_node("wallet:wall_"..i, {
|
minetest.register_node(nodename.."_"..i, {
|
||||||
|
collision_box = {
|
||||||
|
type = 'fixed',
|
||||||
|
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
||||||
|
},
|
||||||
|
drawtype = "nodebox",
|
||||||
|
tile_images = {texture},
|
||||||
|
paramtype = "light",
|
||||||
|
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
||||||
|
drop = nodename,
|
||||||
|
node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = take
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_node(nodename.."_16", {
|
||||||
|
drawtype = "nodebox",
|
||||||
collision_box = {
|
collision_box = {
|
||||||
type = 'fixed',
|
type = 'fixed',
|
||||||
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
||||||
},
|
},
|
||||||
drawtype = "nodebox",
|
tile_images = {texture},
|
||||||
tile_images = {"default_cobble.png"},
|
paramtype = "light",
|
||||||
paramtype = "light",
|
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
||||||
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
drop = nodename,
|
||||||
drop = "wallet:wall",
|
node_box = {
|
||||||
node_box = {
|
type = "fixed",
|
||||||
type = "fixed",
|
fixed = {pillar, full_blocks[1]}
|
||||||
fixed = take
|
},
|
||||||
},
|
})
|
||||||
})
|
|
||||||
|
minetest.register_node(nodename.."_21", {
|
||||||
|
drawtype = "nodebox",
|
||||||
|
collision_box = {
|
||||||
|
type = 'fixed',
|
||||||
|
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
||||||
|
},
|
||||||
|
tile_images = {texture},
|
||||||
|
paramtype = "light",
|
||||||
|
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
||||||
|
drop = nodename,
|
||||||
|
node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {pillar, full_blocks[2]}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Inventory item
|
||||||
|
minetest.register_node(nodename, {
|
||||||
|
description = name,
|
||||||
|
paramtype = "light",
|
||||||
|
tile_images = {texture},
|
||||||
|
inventory_image = invtex,
|
||||||
|
stack_max = 64,
|
||||||
|
drawtype = "nodebox",
|
||||||
|
node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = pillar
|
||||||
|
},
|
||||||
|
collision_box = {
|
||||||
|
type = 'fixed',
|
||||||
|
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
||||||
|
},
|
||||||
|
collisionbox = {-0.2, 0, -0.2, 0.2, 1.4, 0.2},
|
||||||
|
on_construct = update_wall
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("wallet:wall_0", {
|
-- Cobblestone wall
|
||||||
drawtype = "nodebox",
|
|
||||||
collision_box = {
|
|
||||||
type = 'fixed',
|
|
||||||
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
|
||||||
},
|
|
||||||
tile_images = {"default_cobble.png"},
|
|
||||||
paramtype = "light",
|
|
||||||
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
|
||||||
drop = "wallet:wall",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = pillar
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("wallet:wall_16", {
|
|
||||||
drawtype = "nodebox",
|
|
||||||
collision_box = {
|
|
||||||
type = 'fixed',
|
|
||||||
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
|
||||||
},
|
|
||||||
tile_images = {"default_cobble.png"},
|
|
||||||
paramtype = "light",
|
|
||||||
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
|
||||||
drop = "wallet:wall",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {pillar, full_blocks[1]}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("wallet:wall_21", {
|
|
||||||
drawtype = "nodebox",
|
|
||||||
collision_box = {
|
|
||||||
type = 'fixed',
|
|
||||||
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
|
||||||
},
|
|
||||||
tile_images = {"default_cobble.png"},
|
|
||||||
paramtype = "light",
|
|
||||||
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
|
||||||
drop = "wallet:wall",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {pillar, full_blocks[2]}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("wallet:wall", {
|
|
||||||
description = "Cobblestone Wall",
|
|
||||||
paramtype = "light",
|
|
||||||
tile_images = {"default_cobble.png"},
|
|
||||||
inventory_image = "cobblestone_wallet.png",
|
|
||||||
stack_max = 64,
|
|
||||||
drawtype = "nodebox",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = pillar
|
|
||||||
},
|
|
||||||
collision_box = {
|
|
||||||
type = 'fixed',
|
|
||||||
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
|
||||||
},
|
|
||||||
collisionbox = {-0.2, 0, -0.2, 0.2, 1.4, 0.2},
|
|
||||||
on_construct = update_wall
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
register_wall("wallet:wall", "Cobblestone Wall", "default_cobble.png", "cobblestone_wallet.png")
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'wallet:wall 6',
|
output = 'wallet:wall 6',
|
||||||
recipe = {
|
recipe = {
|
||||||
{'default:cobble', 'default:cobble', 'default:cobble'},
|
{'default:cobble', 'default:cobble', 'default:cobble'},
|
||||||
{'default:cobble', 'default:cobble', 'default:cobble'}
|
{'default:cobble', 'default:cobble', 'default:cobble'}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Mossy wallet
|
-- Mossy wall
|
||||||
|
|
||||||
for i = 0, 15 do
|
register_wall("wallet:wallmossy", "Mossy Cobblestone Wall", "default_mossycobble.png", "cobblestonemossy_wallet.png")
|
||||||
local need = {}
|
|
||||||
local need_pillar = false
|
|
||||||
for j = 1, 4 do
|
|
||||||
if rshift(i, j - 1) % 2 == 1 then
|
|
||||||
need[j] = true
|
|
||||||
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])
|
|
||||||
need_pillar = true
|
|
||||||
end
|
|
||||||
if i == 15 or i == 0 then need_pillar = true end
|
|
||||||
if need_pillar then table.insert(take, pillar) end
|
|
||||||
|
|
||||||
minetest.register_node("wallet:wallmossy_"..i, {
|
|
||||||
drawtype = "nodebox",
|
|
||||||
collision_box = {
|
|
||||||
type = 'fixed',
|
|
||||||
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
|
||||||
},
|
|
||||||
tile_images = {"default_mossycobble.png"},
|
|
||||||
paramtype = "light",
|
|
||||||
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
|
||||||
drop = "wallet:wallmossy",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = take
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_node("wallet:wallmossy_0", {
|
|
||||||
drawtype = "nodebox",
|
|
||||||
collision_box = {
|
|
||||||
type = 'fixed',
|
|
||||||
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
|
||||||
},
|
|
||||||
tile_images = {"default_mossycobble.png"},
|
|
||||||
paramtype = "light",
|
|
||||||
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
|
||||||
drop = "wallet:wallmossy",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = pillar
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("wallet:wallmossy_16", {
|
|
||||||
drawtype = "nodebox",
|
|
||||||
collision_box = {
|
|
||||||
type = 'fixed',
|
|
||||||
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
|
||||||
},
|
|
||||||
tile_images = {"default_mossycobble.png"},
|
|
||||||
paramtype = "light",
|
|
||||||
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
|
||||||
drop = "wallet:wallmossy",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {pillar, full_blocks[1]}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("wallet:wallmossy_21", {
|
|
||||||
drawtype = "nodebox",
|
|
||||||
collision_box = {
|
|
||||||
type = 'fixed',
|
|
||||||
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
|
||||||
},
|
|
||||||
tile_images = {"default_mossycobble.png"},
|
|
||||||
paramtype = "light",
|
|
||||||
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,fences=1},
|
|
||||||
drop = "wallet:wallmossy",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {pillar, full_blocks[2]}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("wallet:wallmossy", {
|
|
||||||
description = "Mossy Cobblestone Wall",
|
|
||||||
paramtype = "light",
|
|
||||||
collision_box = {
|
|
||||||
type = 'fixed',
|
|
||||||
fixed = {-4/16, -1, -4/16, 4/16, 1, 4/16}
|
|
||||||
},
|
|
||||||
tile_images = {"default_mossycobble.png"},
|
|
||||||
inventory_image = "cobblestonemossy_wallet.png",
|
|
||||||
stack_max = 64,
|
|
||||||
drawtype = "nodebox",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = pillar
|
|
||||||
},
|
|
||||||
collisionbox = {-0.2, 0, -0.2, 0.2, 1.4, 0.2},
|
|
||||||
on_construct = update_wall
|
|
||||||
})
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'wallet:wallmossy 6',
|
output = 'wallet:wallmossy 6',
|
||||||
recipe = {
|
recipe = {
|
||||||
|
@ -311,6 +194,5 @@ minetest.register_craft({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
minetest.register_on_placenode(update_wall_global)
|
minetest.register_on_placenode(update_wall_global)
|
||||||
minetest.register_on_dignode(update_wall_global)
|
minetest.register_on_dignode(update_wall_global)
|
Reference in a new issue