2017-02-17 22:34:08 +03:00
|
|
|
mcl_walls = {}
|
|
|
|
|
2015-06-29 20:55:56 +03:00
|
|
|
local function rshift(x, by)
|
2015-07-04 16:32:26 +03:00
|
|
|
return math.floor(x / 2 ^ by)
|
2015-06-29 20:55:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local directions = {
|
2015-07-04 16:32:26 +03:00
|
|
|
{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 = 0, y = -1, z = 0},
|
2015-06-29 20:55:56 +03:00
|
|
|
}
|
|
|
|
|
2015-07-04 16:32:26 +03:00
|
|
|
local function update_wall(pos)
|
2017-01-11 20:21:46 +03:00
|
|
|
local thisnode = minetest.get_node(pos)
|
2015-07-04 16:32:26 +03:00
|
|
|
|
2017-01-27 20:15:36 +03:00
|
|
|
if minetest.get_item_group(thisnode.name, "wall") == 0 then
|
2015-06-29 20:55:56 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-07-04 16:32:26 +03:00
|
|
|
-- Get the node's base name, including the underscore since we will need it
|
2017-01-27 20:15:36 +03:00
|
|
|
local colonpos = thisnode.name:find(":")
|
|
|
|
local underscorepos
|
2017-02-17 22:34:08 +03:00
|
|
|
local itemname, basename, modname
|
2017-01-27 20:15:36 +03:00
|
|
|
if colonpos ~= nil then
|
|
|
|
itemname = thisnode.name:sub(colonpos+1)
|
2017-02-17 22:34:08 +03:00
|
|
|
modname = thisnode.name:sub(1, colonpos-1)
|
2017-01-27 20:15:36 +03:00
|
|
|
end
|
|
|
|
underscorepos = itemname:find("_")
|
|
|
|
if underscorepos == nil then -- New wall
|
2015-07-04 16:32:26 +03:00
|
|
|
basename = thisnode.name .. "_"
|
|
|
|
else -- Already placed wall
|
2017-02-17 22:34:08 +03:00
|
|
|
basename = modname .. ":" .. itemname:sub(1, underscorepos)
|
2015-07-04 16:32:26 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local sum = 0
|
|
|
|
|
|
|
|
-- Neighbouring walkable nodes
|
|
|
|
for i = 1, 4 do
|
|
|
|
local dir = directions[i]
|
2017-01-11 20:21:46 +03:00
|
|
|
local node = minetest.get_node({x = pos.x + dir.x, y = pos.y + dir.y, z = pos.z + dir.z})
|
2015-07-04 16:32:26 +03:00
|
|
|
if minetest.registered_nodes[node.name].walkable then
|
|
|
|
sum = sum + 2 ^ (i - 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Torches or walkable nodes above the wall
|
2017-01-11 20:21:46 +03:00
|
|
|
local upnode = minetest.get_node({x = pos.x, y = pos.y+1, z = pos.z})
|
2015-07-04 16:32:26 +03:00
|
|
|
if sum == 5 or sum == 10 then
|
2017-02-10 16:41:36 +03:00
|
|
|
if minetest.registered_nodes[upnode.name].walkable or upnode.name == "mcl_torches:floor" then
|
2015-07-04 16:32:26 +03:00
|
|
|
sum = sum + 11
|
|
|
|
end
|
|
|
|
end
|
2015-06-29 20:55:56 +03:00
|
|
|
|
2015-07-04 16:32:26 +03:00
|
|
|
--[[if sum == 0 then
|
|
|
|
sum = 15
|
|
|
|
end]]
|
|
|
|
|
2017-01-11 20:21:46 +03:00
|
|
|
minetest.add_node(pos, {name = basename..sum})
|
2015-06-29 20:55:56 +03:00
|
|
|
end
|
|
|
|
|
2017-01-24 04:31:49 +03:00
|
|
|
local function update_wall_global(pos)
|
2015-07-04 16:32:26 +03:00
|
|
|
for i = 1,5 do
|
|
|
|
local dir = directions[i]
|
|
|
|
update_wall({x = pos.x + dir.x, y = pos.y + dir.y, z = pos.z + dir.z})
|
|
|
|
end
|
2015-06-29 20:55:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local half_blocks = {
|
|
|
|
{4/16, -0.5, -3/16, 0.5, 5/16, 3/16},
|
|
|
|
{-3/16, -0.5, 4/16, 3/16, 5/16, 0.5},
|
|
|
|
{-0.5, -0.5, -3/16, -4/16, 5/16, 3/16},
|
|
|
|
{-3/16, -0.5, -0.5, 3/16, 5/16, -4/16}
|
|
|
|
}
|
|
|
|
|
|
|
|
local pillar = {-4/16, -0.5, -4/16, 4/16, 0.5, 4/16}
|
|
|
|
|
|
|
|
local full_blocks = {
|
|
|
|
{-0.5, -0.5, -3/16, 0.5, 5/16, 3/16},
|
|
|
|
{-3/16, -0.5, -0.5, 3/16, 5/16, 0.5}
|
|
|
|
}
|
|
|
|
|
2017-01-27 20:15:36 +03:00
|
|
|
--[[ Adds a new wall type.
|
2017-02-21 19:14:15 +03:00
|
|
|
* nodename: Itemstring of base node to add. Must not contain an underscore
|
|
|
|
* description: Item description (tooltip), visible to user
|
2017-02-21 20:04:50 +03:00
|
|
|
* craft_material: Material for the default crafting recipe (optional)
|
2017-02-17 22:52:19 +03:00
|
|
|
* tiles: Wall textures table
|
2017-02-21 19:32:48 +03:00
|
|
|
* inventory_image: Inventory image (optional)
|
2017-02-21 19:14:15 +03:00
|
|
|
* groups: Base group memberships (optional, default is {cracky=3})
|
2017-02-21 19:20:58 +03:00
|
|
|
* sounds: Sound table (optional, default is stone)
|
2017-02-21 19:14:15 +03:00
|
|
|
]]
|
2017-02-21 20:04:50 +03:00
|
|
|
function mcl_walls.register_wall(nodename, description, craft_material, tiles, inventory_image, groups, sounds)
|
2017-02-21 19:14:15 +03:00
|
|
|
|
|
|
|
local base_groups = groups
|
|
|
|
if not base_groups then
|
|
|
|
base_groups = {cracky=3}
|
|
|
|
end
|
|
|
|
base_groups.wall = 1
|
|
|
|
|
|
|
|
internal_groups = table.copy(base_groups)
|
|
|
|
internal_groups.not_in_creative_inventory = 1
|
|
|
|
|
|
|
|
main_node_groups = table.copy(base_groups)
|
|
|
|
main_node_groups.deco_block = 1
|
|
|
|
|
2017-02-22 18:03:59 +03:00
|
|
|
-- TODO: Stop hardcoding blast resistance
|
|
|
|
|
2017-02-21 19:20:58 +03:00
|
|
|
if not sounds then
|
|
|
|
sounds = mcl_sounds.node_sound_stone_defaults()
|
|
|
|
end
|
|
|
|
|
2015-07-04 16:32:26 +03:00
|
|
|
for i = 0, 15 do
|
|
|
|
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(nodename.."_"..i, {
|
|
|
|
collision_box = {
|
|
|
|
type = 'fixed',
|
2017-01-17 04:10:29 +03:00
|
|
|
fixed = {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
|
2015-07-04 16:32:26 +03:00
|
|
|
},
|
|
|
|
drawtype = "nodebox",
|
2017-01-05 00:36:51 +03:00
|
|
|
is_ground_content = false,
|
2017-02-17 22:52:19 +03:00
|
|
|
tiles = tiles,
|
2015-07-04 16:32:26 +03:00
|
|
|
paramtype = "light",
|
2017-02-21 19:14:15 +03:00
|
|
|
groups = internal_groups,
|
2015-07-04 16:32:26 +03:00
|
|
|
drop = nodename,
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = take
|
|
|
|
},
|
2017-02-21 19:20:58 +03:00
|
|
|
sounds = sounds,
|
2017-02-22 18:03:59 +03:00
|
|
|
_mcl_blast_resistance = 30,
|
2015-07-04 16:32:26 +03:00
|
|
|
})
|
|
|
|
end
|
2015-06-29 20:55:56 +03:00
|
|
|
|
2015-07-04 16:32:26 +03:00
|
|
|
minetest.register_node(nodename.."_16", {
|
|
|
|
drawtype = "nodebox",
|
|
|
|
collision_box = {
|
|
|
|
type = 'fixed',
|
2017-01-17 04:10:29 +03:00
|
|
|
fixed = {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
|
2015-07-04 16:32:26 +03:00
|
|
|
},
|
2017-02-17 22:52:19 +03:00
|
|
|
tiles = tiles,
|
2015-07-04 16:32:26 +03:00
|
|
|
paramtype = "light",
|
2017-01-05 00:36:51 +03:00
|
|
|
is_ground_content = false,
|
2017-02-21 19:14:15 +03:00
|
|
|
groups = internal_groups,
|
2015-07-04 16:32:26 +03:00
|
|
|
drop = nodename,
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {pillar, full_blocks[1]}
|
|
|
|
},
|
2017-02-21 19:20:58 +03:00
|
|
|
sounds = sounds,
|
2017-02-22 18:03:59 +03:00
|
|
|
_mcl_blast_resistance = 30,
|
2015-07-04 16:32:26 +03:00
|
|
|
})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
2015-07-04 16:32:26 +03:00
|
|
|
minetest.register_node(nodename.."_21", {
|
|
|
|
drawtype = "nodebox",
|
|
|
|
collision_box = {
|
|
|
|
type = 'fixed',
|
2017-01-17 04:10:29 +03:00
|
|
|
fixed = {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
|
2015-07-04 16:32:26 +03:00
|
|
|
},
|
2017-02-17 22:52:19 +03:00
|
|
|
tiles = tiles,
|
2015-07-04 16:32:26 +03:00
|
|
|
paramtype = "light",
|
2017-01-05 00:36:51 +03:00
|
|
|
is_ground_content = false,
|
2017-02-21 19:14:15 +03:00
|
|
|
groups = internal_groups,
|
2015-07-04 16:32:26 +03:00
|
|
|
drop = nodename,
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {pillar, full_blocks[2]}
|
|
|
|
},
|
2017-02-21 19:20:58 +03:00
|
|
|
sounds = sounds,
|
2017-02-22 18:03:59 +03:00
|
|
|
_mcl_blast_resistance = 30,
|
2015-07-04 16:32:26 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Inventory item
|
|
|
|
minetest.register_node(nodename, {
|
2017-02-21 19:14:15 +03:00
|
|
|
description = description,
|
2015-07-04 16:32:26 +03:00
|
|
|
paramtype = "light",
|
2017-01-05 00:36:51 +03:00
|
|
|
is_ground_content = false,
|
2017-02-21 19:14:15 +03:00
|
|
|
groups = main_node_groups,
|
2017-02-17 22:52:19 +03:00
|
|
|
tiles = tiles,
|
2017-02-21 19:32:48 +03:00
|
|
|
inventory_image = inventory_image,
|
2015-07-04 16:32:26 +03:00
|
|
|
stack_max = 64,
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = pillar
|
|
|
|
},
|
2015-06-29 20:55:56 +03:00
|
|
|
collision_box = {
|
2015-07-04 16:32:26 +03:00
|
|
|
type = 'fixed',
|
2017-01-17 04:10:29 +03:00
|
|
|
fixed = {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
|
2015-06-29 20:55:56 +03:00
|
|
|
},
|
2015-07-04 16:32:26 +03:00
|
|
|
collisionbox = {-0.2, 0, -0.2, 0.2, 1.4, 0.2},
|
2017-01-17 04:08:41 +03:00
|
|
|
on_construct = update_wall,
|
2017-02-21 19:20:58 +03:00
|
|
|
sounds = sounds,
|
2017-02-22 18:03:59 +03:00
|
|
|
_mcl_blast_resistance = 30,
|
2015-07-04 16:32:26 +03:00
|
|
|
})
|
2017-02-21 20:04:50 +03:00
|
|
|
if craft_material then
|
|
|
|
minetest.register_craft({
|
|
|
|
output = nodename .. " 6",
|
|
|
|
recipe = {
|
|
|
|
{craft_material, craft_material, craft_material},
|
|
|
|
{craft_material, craft_material, craft_material},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
2015-06-29 20:55:56 +03:00
|
|
|
end
|
|
|
|
|
2015-07-04 16:32:26 +03:00
|
|
|
-- Cobblestone wall
|
2017-02-21 20:04:50 +03:00
|
|
|
mcl_walls.register_wall("mcl_walls:cobble", "Cobblestone Wall", "mcl_core:cobble", {"default_cobble.png"}, "mcl_walls_cobble.png")
|
2015-06-29 20:55:56 +03:00
|
|
|
|
2015-07-04 16:32:26 +03:00
|
|
|
-- Mossy wall
|
2015-06-29 20:55:56 +03:00
|
|
|
|
2017-02-21 20:04:50 +03:00
|
|
|
mcl_walls.register_wall("mcl_walls:mossycobble", "Mossy Cobblestone Wall", "mcl_core:mossycobble", {"default_mossycobble.png"}, "mcl_walls_mossycobble.png")
|
2015-06-29 20:55:56 +03:00
|
|
|
|
|
|
|
minetest.register_on_placenode(update_wall_global)
|
2017-01-05 00:36:51 +03:00
|
|
|
minetest.register_on_dignode(update_wall_global)
|