2021-05-29 14:12:33 +00:00
local modname = minetest.get_current_modname ( )
local modpath = minetest.get_modpath ( modname )
local S = minetest.get_translator ( modname )
2019-03-07 23:46:35 +00:00
2017-02-17 19:34:08 +00:00
mcl_walls = { }
2015-06-29 17:55:56 +00:00
local function rshift ( x , by )
2015-07-04 13:32:26 +00:00
return math.floor ( x / 2 ^ by )
2015-06-29 17:55:56 +00:00
end
local directions = {
2015-07-04 13:32:26 +00: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 17:55:56 +00:00
}
2020-03-24 18:28:22 +00:00
local function connectable ( itemstring )
return ( minetest.get_item_group ( itemstring , " wall " ) == 1 ) or ( minetest.get_item_group ( itemstring , " solid " ) == 1 )
end
2015-07-04 13:32:26 +00:00
local function update_wall ( pos )
2017-01-11 17:21:46 +00:00
local thisnode = minetest.get_node ( pos )
2015-07-04 13:32:26 +00:00
2017-01-27 17:15:36 +00:00
if minetest.get_item_group ( thisnode.name , " wall " ) == 0 then
2015-06-29 17:55:56 +00:00
return
end
2015-07-04 13:32:26 +00:00
-- Get the node's base name, including the underscore since we will need it
2017-01-27 17:15:36 +00:00
local colonpos = thisnode.name : find ( " : " )
local underscorepos
2017-02-17 19:34:08 +00:00
local itemname , basename , modname
2021-05-29 14:12:33 +00:00
if colonpos then
2017-01-27 17:15:36 +00:00
itemname = thisnode.name : sub ( colonpos + 1 )
2017-02-17 19:34:08 +00:00
modname = thisnode.name : sub ( 1 , colonpos - 1 )
2017-01-27 17:15:36 +00:00
end
underscorepos = itemname : find ( " _ " )
if underscorepos == nil then -- New wall
2015-07-04 13:32:26 +00:00
basename = thisnode.name .. " _ "
else -- Already placed wall
2017-02-17 19:34:08 +00:00
basename = modname .. " : " .. itemname : sub ( 1 , underscorepos )
2015-07-04 13:32:26 +00:00
end
local sum = 0
-- Neighbouring walkable nodes
for i = 1 , 4 do
local dir = directions [ i ]
2017-01-11 17:21:46 +00:00
local node = minetest.get_node ( { x = pos.x + dir.x , y = pos.y + dir.y , z = pos.z + dir.z } )
2020-03-24 18:28:22 +00:00
if connectable ( node.name ) then
2015-07-04 13:32:26 +00:00
sum = sum + 2 ^ ( i - 1 )
end
end
-- Torches or walkable nodes above the wall
2017-01-11 17:21:46 +00:00
local upnode = minetest.get_node ( { x = pos.x , y = pos.y + 1 , z = pos.z } )
2015-07-04 13:32:26 +00:00
if sum == 5 or sum == 10 then
2020-03-24 18:28:22 +00:00
if ( connectable ( upnode.name ) ) or ( minetest.get_item_group ( upnode.name , " torch " ) == 1 ) then
2015-07-04 13:32:26 +00:00
sum = sum + 11
end
end
2015-06-29 17:55:56 +00:00
2015-07-04 13:32:26 +00:00
--[[if sum == 0 then
sum = 15
end ] ]
2017-01-11 17:21:46 +00:00
minetest.add_node ( pos , { name = basename .. sum } )
2015-06-29 17:55:56 +00:00
end
2017-01-24 01:31:49 +00:00
local function update_wall_global ( pos )
2015-07-04 13:32:26 +00: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 17:55:56 +00: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 17:15:36 +00:00
--[[ Adds a new wall type.
2017-02-21 16:14:15 +00:00
* nodename : Itemstring of base node to add . Must not contain an underscore
* description : Item description ( tooltip ) , visible to user
2018-12-03 16:30:09 +00:00
* source : Source block to craft this thing , for graphics , tiles and crafting ( optional )
2017-02-17 19:52:19 +00:00
* tiles : Wall textures table
2017-02-21 16:32:48 +00:00
* inventory_image : Inventory image ( optional )
2017-02-27 16:41:20 +00:00
* groups : Base group memberships ( optional , default is { pickaxey = 1 } )
2017-02-21 16:20:58 +00:00
* sounds : Sound table ( optional , default is stone )
2023-09-17 14:14:36 +00:00
* hardness : Hardness of node ( optional , default matches ` source ` node or fallback value 2 )
* blast_resistance : Blast resistance of node ( optional , default matches ` source ` node or fallback value 6 )
2017-02-21 16:14:15 +00:00
] ]
2023-09-17 14:14:36 +00:00
function mcl_walls . register_wall ( nodename , description , source , tiles , inventory_image , groups , sounds , hardness , blast_resistance )
2017-02-21 16:14:15 +00:00
local base_groups = groups
if not base_groups then
2017-02-27 16:41:20 +00:00
base_groups = { pickaxey = 1 }
2017-02-21 16:14:15 +00:00
end
base_groups.wall = 1
2017-02-23 14:08:52 +00:00
local internal_groups = table.copy ( base_groups )
2017-02-21 16:14:15 +00:00
internal_groups.not_in_creative_inventory = 1
2017-02-23 14:08:52 +00:00
local main_node_groups = table.copy ( base_groups )
2017-02-21 16:14:15 +00:00
main_node_groups.deco_block = 1
2023-09-17 14:14:36 +00:00
if source then
-- Default values from `source` node
if not hardness then
hardness = minetest.registered_nodes [ source ] . _mcl_hardness
end
if not blast_resistance then
blast_resistance = minetest.registered_nodes [ source ] . _mcl_blast_resistance
end
if not sounds then
sounds = minetest.registered_nodes [ source ] . sounds
end
if not tiles then
if minetest.registered_nodes [ source ] then
tiles = minetest.registered_nodes [ source ] . tiles
end
end
else
-- Fallback in case no `source` given
if not hardness then
hardness = 2
end
if not blast_resistance then
blast_resistance = 6
2018-12-03 16:30:09 +00:00
end
end
2015-07-04 13:32:26 +00: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 = {
2021-05-29 14:12:33 +00:00
type = " fixed " ,
2017-01-17 01:10:29 +00:00
fixed = { - 4 / 16 , - 0.5 , - 4 / 16 , 4 / 16 , 1 , 4 / 16 }
2015-07-04 13:32:26 +00:00
} ,
drawtype = " nodebox " ,
2017-01-04 21:36:51 +00:00
is_ground_content = false ,
2017-02-17 19:52:19 +00:00
tiles = tiles ,
2021-02-18 13:00:17 +00:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " opaque " or false ,
2015-07-04 13:32:26 +00:00
paramtype = " light " ,
2017-03-20 18:11:51 +00:00
sunlight_propagates = true ,
2017-02-21 16:14:15 +00:00
groups = internal_groups ,
2015-07-04 13:32:26 +00:00
drop = nodename ,
node_box = {
type = " fixed " ,
fixed = take
} ,
2017-02-21 16:20:58 +00:00
sounds = sounds ,
2023-09-17 11:47:18 +00:00
_mcl_blast_resistance = blast_resistance ,
_mcl_hardness = hardness ,
2015-07-04 13:32:26 +00:00
} )
2017-03-20 17:12:05 +00:00
-- Add entry alias for the Help
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , nodename , " nodes " , nodename .. " _ " .. i )
end
2015-07-04 13:32:26 +00:00
end
2015-06-29 17:55:56 +00:00
2015-07-04 13:32:26 +00:00
minetest.register_node ( nodename .. " _16 " , {
drawtype = " nodebox " ,
collision_box = {
2021-05-29 14:12:33 +00:00
type = " fixed " ,
2017-01-17 01:10:29 +00:00
fixed = { - 4 / 16 , - 0.5 , - 4 / 16 , 4 / 16 , 1 , 4 / 16 }
2015-07-04 13:32:26 +00:00
} ,
2017-02-17 19:52:19 +00:00
tiles = tiles ,
2021-02-18 13:00:17 +00:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " opaque " or false ,
2015-07-04 13:32:26 +00:00
paramtype = " light " ,
2017-03-20 18:11:51 +00:00
sunlight_propagates = true ,
2017-01-04 21:36:51 +00:00
is_ground_content = false ,
2017-02-21 16:14:15 +00:00
groups = internal_groups ,
2015-07-04 13:32:26 +00:00
drop = nodename ,
node_box = {
type = " fixed " ,
fixed = { pillar , full_blocks [ 1 ] }
} ,
2017-02-21 16:20:58 +00:00
sounds = sounds ,
2023-09-17 11:47:18 +00:00
_mcl_blast_resistance = blast_resistance ,
_mcl_hardness = hardness ,
2015-07-04 13:32:26 +00:00
} )
2017-03-20 17:12:05 +00:00
-- Add entry alias for the Help
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , nodename , " nodes " , nodename .. " _16 " )
end
2015-06-29 17:55:56 +00:00
2015-07-04 13:32:26 +00:00
minetest.register_node ( nodename .. " _21 " , {
drawtype = " nodebox " ,
collision_box = {
2021-05-29 14:12:33 +00:00
type = " fixed " ,
2017-01-17 01:10:29 +00:00
fixed = { - 4 / 16 , - 0.5 , - 4 / 16 , 4 / 16 , 1 , 4 / 16 }
2015-07-04 13:32:26 +00:00
} ,
2017-02-17 19:52:19 +00:00
tiles = tiles ,
2021-02-18 13:00:17 +00:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " opaque " or false ,
2015-07-04 13:32:26 +00:00
paramtype = " light " ,
2017-03-20 18:11:51 +00:00
sunlight_propagates = true ,
2017-01-04 21:36:51 +00:00
is_ground_content = false ,
2017-02-21 16:14:15 +00:00
groups = internal_groups ,
2015-07-04 13:32:26 +00:00
drop = nodename ,
node_box = {
type = " fixed " ,
fixed = { pillar , full_blocks [ 2 ] }
} ,
2017-02-21 16:20:58 +00:00
sounds = sounds ,
2023-09-17 11:47:18 +00:00
_mcl_blast_resistance = blast_resistance ,
_mcl_hardness = hardness ,
2015-07-04 13:32:26 +00:00
} )
2017-03-20 17:12:05 +00:00
-- Add entry alias for the Help
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , nodename , " nodes " , nodename .. " _21 " )
end
2015-07-04 13:32:26 +00:00
-- Inventory item
minetest.register_node ( nodename , {
2017-02-21 16:14:15 +00:00
description = description ,
2019-03-07 23:46:35 +00:00
_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. " ) ,
2015-07-04 13:32:26 +00:00
paramtype = " light " ,
2017-03-20 18:11:51 +00:00
sunlight_propagates = true ,
2017-01-04 21:36:51 +00:00
is_ground_content = false ,
2017-02-21 16:14:15 +00:00
groups = main_node_groups ,
2017-02-17 19:52:19 +00:00
tiles = tiles ,
2021-02-18 13:00:17 +00:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " opaque " or false ,
2017-02-21 16:32:48 +00:00
inventory_image = inventory_image ,
2015-07-04 13:32:26 +00:00
stack_max = 64 ,
drawtype = " nodebox " ,
node_box = {
type = " fixed " ,
fixed = pillar
} ,
2015-06-29 17:55:56 +00:00
collision_box = {
2021-05-29 14:12:33 +00:00
type = " fixed " ,
2017-01-17 01:10:29 +00:00
fixed = { - 4 / 16 , - 0.5 , - 4 / 16 , 4 / 16 , 1 , 4 / 16 }
2015-06-29 17:55:56 +00:00
} ,
2015-07-04 13:32:26 +00:00
collisionbox = { - 0.2 , 0 , - 0.2 , 0.2 , 1.4 , 0.2 } ,
2017-01-17 01:08:41 +00:00
on_construct = update_wall ,
2017-02-21 16:20:58 +00:00
sounds = sounds ,
2023-09-17 11:47:18 +00:00
_mcl_blast_resistance = blast_resistance ,
_mcl_hardness = hardness ,
2015-07-04 13:32:26 +00:00
} )
2018-12-03 16:30:09 +00:00
if source then
2017-02-21 17:04:50 +00:00
minetest.register_craft ( {
output = nodename .. " 6 " ,
recipe = {
2018-12-03 16:30:09 +00:00
{ source , source , source } ,
{ source , source , source } ,
2017-02-21 17:04:50 +00:00
}
} )
2023-11-13 20:16:05 +00:00
mcl_stonecutter.register_recipe ( source , nodename )
2017-02-21 17:04:50 +00:00
end
2015-06-29 17:55:56 +00:00
end
2021-05-29 14:12:33 +00:00
dofile ( modpath .. " /register.lua " )
2015-06-29 17:55:56 +00:00
minetest.register_on_placenode ( update_wall_global )
2017-01-04 21:36:51 +00:00
minetest.register_on_dignode ( update_wall_global )