3 local function rshift(x
, by
)
4 return math
.floor(x
/ 2 ^ by
)
10 {x
= -1, y
= 0, z
= 0},
11 {x
= 0, y
= 0, z
= -1},
12 {x
= 0, y
= -1, z
= 0},
15 local function update_wall(pos
)
16 local thisnode
= minetest
.get_node(pos
)
18 if minetest
.get_item_group(thisnode
.name
, "wall") == 0 then
22 -- Get the node's base name, including the underscore since we will need it
23 local colonpos
= thisnode
.name
:find(":")
25 local itemname
, basename
, modname
26 if colonpos
~= nil then
27 itemname
= thisnode
.name
:sub(colonpos
+1)
28 modname
= thisnode
.name
:sub(1, colonpos
-1)
30 underscorepos
= itemname
:find("_")
31 if underscorepos
== nil then -- New wall
32 basename
= thisnode
.name
.. "_"
33 else -- Already placed wall
34 basename
= modname
.. ":" .. itemname
:sub(1, underscorepos
)
39 -- Neighbouring walkable nodes
41 local dir
= directions
[i
]
42 local node
= minetest
.get_node({x
= pos
.x
+ dir
.x
, y
= pos
.y
+ dir
.y
, z
= pos
.z
+ dir
.z
})
43 local def
= minetest
.registered_nodes
[node
.name
]
44 if def
and def
.walkable
then
45 sum
= sum
+ 2 ^
(i
- 1)
49 -- Torches or walkable nodes above the wall
50 local upnode
= minetest
.get_node({x
= pos
.x
, y
= pos
.y
+1, z
= pos
.z
})
51 if sum
== 5 or sum
== 10 then
52 local def
= minetest
.registered_nodes
[upnode
.name
]
53 if (def
and def
.walkable
) or upnode
.name
== "mcl_torches:torch" then
62 minetest
.add_node(pos
, {name
= basename
..sum
})
65 local function update_wall_global(pos
)
67 local dir
= directions
[i
]
68 update_wall({x
= pos
.x
+ dir
.x
, y
= pos
.y
+ dir
.y
, z
= pos
.z
+ dir
.z
})
73 {4/16, -0.5, -3/16, 0.5, 5/16, 3/16},
74 {-3/16, -0.5, 4/16, 3/16, 5/16, 0.5},
75 {-0.5, -0.5, -3/16, -4/16, 5/16, 3/16},
76 {-3/16, -0.5, -0.5, 3/16, 5/16, -4/16}
79 local pillar
= {-4/16, -0.5, -4/16, 4/16, 0.5, 4/16}
82 {-0.5, -0.5, -3/16, 0.5, 5/16, 3/16},
83 {-3/16, -0.5, -0.5, 3/16, 5/16, 0.5}
86 --[[ Adds a new wall type.
87 * nodename: Itemstring of base node to add. Must not contain an underscore
88 * description: Item description (tooltip), visible to user
89 * craft_material: Material for the default crafting recipe (optional)
90 * tiles: Wall textures table
91 * inventory_image: Inventory image (optional)
92 * groups: Base group memberships (optional, default is {pickaxey=1})
93 * sounds: Sound table (optional, default is stone)
95 function mcl_walls
.register_wall(nodename
, description
, craft_material
, tiles
, inventory_image
, groups
, sounds
)
97 local base_groups
= groups
98 if not base_groups
then
99 base_groups
= {pickaxey
=1}
103 local internal_groups
= table.copy(base_groups
)
104 internal_groups
.not_in_creative_inventory
= 1
106 local main_node_groups
= table.copy(base_groups
)
107 main_node_groups
.deco_block
= 1
109 -- TODO: Stop hardcoding blast resistance
112 sounds
= mcl_sounds
.node_sound_stone_defaults()
117 local need_pillar
= false
119 if rshift(i
, j
- 1) % 2 == 1 then
125 if need
[1] == true and need
[3] == true then
128 table.insert(take
, full_blocks
[1])
130 if need
[2] == true and need
[4] == true then
133 table.insert(take
, full_blocks
[2])
135 for k
in pairs(need
) do
136 table.insert(take
, half_blocks
[k
])
139 if i
== 15 or i
== 0 then need_pillar
= true end
140 if need_pillar
then table.insert(take
, pillar
) end
142 minetest
.register_node(nodename
.."_"..i
, {
145 fixed
= {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
147 drawtype
= "nodebox",
148 is_ground_content
= false,
151 sunlight_propagates
= true,
152 groups
= internal_groups
,
159 _mcl_blast_resistance
= 30,
163 -- Add entry alias for the Help
164 if minetest
.get_modpath("doc") then
165 doc
.add_entry_alias("nodes", nodename
, "nodes", nodename
.."_"..i
)
169 minetest
.register_node(nodename
.."_16", {
170 drawtype
= "nodebox",
173 fixed
= {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
177 sunlight_propagates
= true,
178 is_ground_content
= false,
179 groups
= internal_groups
,
183 fixed
= {pillar
, full_blocks
[1]}
186 _mcl_blast_resistance
= 30,
189 -- Add entry alias for the Help
190 if minetest
.get_modpath("doc") then
191 doc
.add_entry_alias("nodes", nodename
, "nodes", nodename
.."_16")
194 minetest
.register_node(nodename
.."_21", {
195 drawtype
= "nodebox",
198 fixed
= {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
202 sunlight_propagates
= true,
203 is_ground_content
= false,
204 groups
= internal_groups
,
208 fixed
= {pillar
, full_blocks
[2]}
211 _mcl_blast_resistance
= 30,
214 -- Add entry alias for the Help
215 if minetest
.get_modpath("doc") then
216 doc
.add_entry_alias("nodes", nodename
, "nodes", nodename
.."_21")
220 minetest
.register_node(nodename
, {
221 description
= description
,
222 _doc_items_longdesc
= "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.",
224 sunlight_propagates
= true,
225 is_ground_content
= false,
226 groups
= main_node_groups
,
228 inventory_image
= inventory_image
,
230 drawtype
= "nodebox",
237 fixed
= {-4/16, -0.5, -4/16, 4/16, 1, 4/16}
239 collisionbox
= {-0.2, 0, -0.2, 0.2, 1.4, 0.2},
240 on_construct
= update_wall
,
242 _mcl_blast_resistance
= 30,
245 if craft_material
then
246 minetest
.register_craft({
247 output
= nodename
.. " 6",
249 {craft_material
, craft_material
, craft_material
},
250 {craft_material
, craft_material
, craft_material
},
257 mcl_walls
.register_wall("mcl_walls:cobble", "Cobblestone Wall", "mcl_core:cobble", {"default_cobble.png"})
261 mcl_walls
.register_wall("mcl_walls:mossycobble", "Mossy Cobblestone Wall", "mcl_core:mossycobble", {"default_mossycobble.png"})
263 minetest
.register_on_placenode(update_wall_global
)
264 minetest
.register_on_dignode(update_wall_global
)