1 local S
= minetest
.get_translator("mcl_walls")
5 local function rshift(x
, by
)
6 return math
.floor(x
/ 2 ^ by
)
10 {x
= 1, y
= 0, z
= 0},
11 {x
= 0, y
= 0, z
= 1},
12 {x
= -1, y
= 0, z
= 0},
13 {x
= 0, y
= 0, z
= -1},
14 {x
= 0, y
= -1, z
= 0},
17 local function connectable(itemstring
)
18 return (minetest
.get_item_group(itemstring
, "wall") == 1) or (minetest
.get_item_group(itemstring
, "solid") == 1)
21 local function update_wall(pos
)
22 local thisnode
= minetest
.get_node(pos
)
24 if minetest
.get_item_group(thisnode
.name
, "wall") == 0 then
28 -- Get the node's base name, including the underscore since we will need it
29 local colonpos
= thisnode
.name
:find(":")
31 local itemname
, basename
, modname
32 if colonpos
~= nil then
33 itemname
= thisnode
.name
:sub(colonpos
+1)
34 modname
= thisnode
.name
:sub(1, colonpos
-1)
36 underscorepos
= itemname
:find("_")
37 if underscorepos
== nil then -- New wall
38 basename
= thisnode
.name
.. "_"
39 else -- Already placed wall
40 basename
= modname
.. ":" .. itemname
:sub(1, underscorepos
)
45 -- Neighbouring walkable nodes
47 local dir
= directions
[i
]
48 local node
= minetest
.get_node({x
= pos
.x
+ dir
.x
, y
= pos
.y
+ dir
.y
, z
= pos
.z
+ dir
.z
})
49 if connectable(node
.name
) then
50 sum
= sum
+ 2 ^
(i
- 1)
54 -- Torches or walkable nodes above the wall
55 local upnode
= minetest
.get_node({x
= pos
.x
, y
= pos
.y
+1, z
= pos
.z
})
56 if sum
== 5 or sum
== 10 then
57 if (connectable(upnode
.name
)) or (minetest
.get_item_group(upnode
.name
, "torch") == 1) then
66 minetest
.add_node(pos
, {name
= basename
..sum
})
69 local function update_wall_global(pos
)
71 local dir
= directions
[i
]
72 update_wall({x
= pos
.x
+ dir
.x
, y
= pos
.y
+ dir
.y
, z
= pos
.z
+ dir
.z
})
77 {4/16, -0.5, -3/16, 0.5, 5/16, 3/16},
78 {-3/16, -0.5, 4/16, 3/16, 5/16, 0.5},
79 {-0.5, -0.5, -3/16, -4/16, 5/16, 3/16},
80 {-3/16, -0.5, -0.5, 3/16, 5/16, -4/16}
83 local pillar
= {-4/16, -0.5, -4/16, 4/16, 0.5, 4/16}
86 {-0.5, -0.5, -3/16, 0.5, 5/16, 3/16},
87 {-3/16, -0.5, -0.5, 3/16, 5/16, 0.5}
90 --[[ Adds a new wall type.
91 * nodename: Itemstring of base node to add. Must not contain an underscore
92 * description: Item description (tooltip), visible to user
93 * source: Source block to craft this thing, for graphics, tiles and crafting (optional)
94 * tiles: Wall textures table
95 * inventory_image: Inventory image (optional)
96 * groups: Base group memberships (optional, default is {pickaxey=1})
97 * sounds: Sound table (optional, default is stone)
99 function mcl_walls
.register_wall(nodename
, description
, source
, tiles
, inventory_image
, groups
, sounds
)
101 local base_groups
= groups
102 if not base_groups
then
103 base_groups
= {pickaxey
=1}
107 local internal_groups
= table.copy(base_groups
)
108 internal_groups
.not_in_creative_inventory
= 1
110 local main_node_groups
= table.copy(base_groups
)
111 main_node_groups
.deco_block
= 1
113 -- TODO: Stop hardcoding blast resistance
116 sounds
= mcl_sounds
.node_sound_stone_defaults()
119 if (not tiles
) and source
then
120 if minetest
.registered_nodes
[source
] then
121 tiles
= minetest
.registered_nodes
[source
].tiles
127 local need_pillar
= false
129 if rshift(i
, j
- 1) % 2 == 1 then
135 if need
[1] == true and need
[3] == true then
138 table.insert(take
, full_blocks
[1])
140 if need
[2] == true and need
[4] == true then
143 table.insert(take
, full_blocks
[2])
145 for k
in pairs(need
) do
146 table.insert(take
, half_blocks
[k
])
149 if i
== 15 or i
== 0 then need_pillar
= true end
150 if need_pillar
then table.insert(take
, pillar
) end
152 minetest
.register_node(nodename
.."_"..i
, {
155 fixed
= {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
157 drawtype
= "nodebox",
158 is_ground_content
= false,
161 sunlight_propagates
= true,
162 groups
= internal_groups
,
169 _mcl_blast_resistance
= 6,
173 -- Add entry alias for the Help
174 if minetest
.get_modpath("doc") then
175 doc
.add_entry_alias("nodes", nodename
, "nodes", nodename
.."_"..i
)
179 minetest
.register_node(nodename
.."_16", {
180 drawtype
= "nodebox",
183 fixed
= {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
187 sunlight_propagates
= true,
188 is_ground_content
= false,
189 groups
= internal_groups
,
193 fixed
= {pillar
, full_blocks
[1]}
196 _mcl_blast_resistance
= 6,
199 -- Add entry alias for the Help
200 if minetest
.get_modpath("doc") then
201 doc
.add_entry_alias("nodes", nodename
, "nodes", nodename
.."_16")
204 minetest
.register_node(nodename
.."_21", {
205 drawtype
= "nodebox",
208 fixed
= {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
212 sunlight_propagates
= true,
213 is_ground_content
= false,
214 groups
= internal_groups
,
218 fixed
= {pillar
, full_blocks
[2]}
221 _mcl_blast_resistance
= 6,
224 -- Add entry alias for the Help
225 if minetest
.get_modpath("doc") then
226 doc
.add_entry_alias("nodes", nodename
, "nodes", nodename
.."_21")
230 minetest
.register_node(nodename
, {
231 description
= description
,
232 _doc_items_longdesc
= S("A piece of wall. It cannot be jumped over with a simple jump. When multiple of these are placed to next to each other, they will automatically build a nice wall structure."),
234 sunlight_propagates
= true,
235 is_ground_content
= false,
236 groups
= main_node_groups
,
238 inventory_image
= inventory_image
,
240 drawtype
= "nodebox",
247 fixed
= {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
249 collisionbox
= {-0.2, 0, -0.2, 0.2, 1.4, 0.2},
250 on_construct
= update_wall
,
252 _mcl_blast_resistance
= 6,
256 minetest
.register_craft({
257 output
= nodename
.. " 6",
259 {source
, source
, source
},
260 {source
, source
, source
},
266 dofile(minetest
.get_modpath("mcl_walls") .. "/register.lua")
268 minetest
.register_on_placenode(update_wall_global
)
269 minetest
.register_on_dignode(update_wall_global
)