2021-05-29 16:12:33 +02:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2019-03-24 10:31:58 +01:00
local mod_doc = minetest.get_modpath ( " doc " )
2017-01-09 13:39:36 +01:00
local function is_pane ( pos )
return minetest.get_item_group ( minetest.get_node ( pos ) . name , " pane " ) > 0
end
local function connects_dir ( pos , name , dir )
local aside = vector.add ( pos , minetest.facedir_to_dir ( dir ) )
if is_pane ( aside ) then
return true
2015-06-29 19:55:56 +02:00
end
2017-01-09 13:39:36 +01:00
local connects_to = minetest.registered_nodes [ name ] . connects_to
if not connects_to then
return false
end
local list = minetest.find_nodes_in_area ( aside , aside , connects_to )
2015-06-29 19:55:56 +02:00
2017-01-09 13:39:36 +01:00
if # list > 0 then
return true
end
return false
end
local function swap ( pos , node , name , param2 )
if node.name == name and node.param2 == param2 then
return
end
minetest.set_node ( pos , { name = name , param2 = param2 } )
end
local function update_pane ( pos )
if not is_pane ( pos ) then
return
end
local node = minetest.get_node ( pos )
local name = node.name
if name : sub ( - 5 ) == " _flat " then
name = name : sub ( 1 , - 6 )
end
local any = node.param2
local c = { }
local count = 0
for dir = 0 , 3 do
c [ dir ] = connects_dir ( pos , name , dir )
if c [ dir ] then
any = dir
count = count + 1
2015-06-29 19:55:56 +02:00
end
end
2017-01-09 13:39:36 +01:00
if count == 0 then
swap ( pos , node , name .. " _flat " , any )
elseif count == 1 then
swap ( pos , node , name .. " _flat " , ( any + 1 ) % 4 )
elseif count == 2 then
if ( c [ 0 ] and c [ 2 ] ) or ( c [ 1 ] and c [ 3 ] ) then
swap ( pos , node , name .. " _flat " , ( any + 1 ) % 4 )
else
swap ( pos , node , name , 0 )
2015-06-29 19:55:56 +02:00
end
2017-01-09 13:39:36 +01:00
else
swap ( pos , node , name , 0 )
2015-06-29 19:55:56 +02:00
end
2017-01-09 13:39:36 +01:00
end
2015-06-29 19:55:56 +02:00
2017-01-09 13:39:36 +01:00
minetest.register_on_placenode ( function ( pos , node )
2022-09-12 00:52:19 +02:00
if minetest.get_item_group ( node.name , " pane " ) <= 0 then return end
update_pane ( pos )
2017-01-09 13:39:36 +01:00
for i = 0 , 3 do
local dir = minetest.facedir_to_dir ( i )
update_pane ( vector.add ( pos , dir ) )
end
end )
2015-06-29 19:55:56 +02:00
2022-09-12 00:52:19 +02:00
minetest.register_on_dignode ( function ( pos , node )
if minetest.get_item_group ( node.name , " pane " ) <= 0 then return end
2017-01-09 13:39:36 +01:00
for i = 0 , 3 do
local dir = minetest.facedir_to_dir ( i )
update_pane ( vector.add ( pos , dir ) )
end
end )
2015-06-29 19:55:56 +02:00
2017-01-09 13:39:36 +01:00
xpanes = { }
function xpanes . register_pane ( name , def )
2015-06-29 19:55:56 +02:00
for i = 1 , 15 do
2017-01-09 13:39:36 +01:00
minetest.register_alias ( " xpanes: " .. name .. " _ " .. i , " xpanes: " .. name .. " _flat " )
2015-06-29 19:55:56 +02:00
end
2017-01-09 13:39:36 +01:00
local flatgroups = table.copy ( def.groups )
2017-02-21 23:41:44 +01:00
local drop = def.drop
if not drop then
drop = " xpanes: " .. name .. " _flat "
end
2017-01-09 13:39:36 +01:00
flatgroups.pane = 1
2017-01-20 04:54:09 +01:00
flatgroups.deco_block = 1
2017-01-09 13:39:36 +01:00
minetest.register_node ( " :xpanes: " .. name .. " _flat " , {
description = def.description ,
2017-03-11 16:56:37 +01:00
_doc_items_create_entry = def._doc_items_create_entry ,
_doc_items_entry_name = def._doc_items_entry_name ,
_doc_items_longdesc = def._doc_items_longdesc ,
_doc_items_usagehelp = def._doc_items_usagehelp ,
2017-01-09 13:39:36 +01:00
drawtype = " nodebox " ,
2015-06-29 19:55:56 +02:00
paramtype = " light " ,
2017-01-09 13:39:36 +01:00
is_ground_content = false ,
sunlight_propagates = true ,
inventory_image = def.inventory_image ,
wield_image = def.wield_image ,
paramtype2 = " facedir " ,
2017-07-26 22:39:16 +02:00
tiles = { def.textures [ 3 ] , def.textures [ 2 ] , def.textures [ 1 ] } ,
2017-02-13 15:52:16 +01:00
use_texture_alpha = def.use_texture_alpha ,
2017-01-09 13:39:36 +01:00
groups = flatgroups ,
2017-02-21 23:41:44 +01:00
drop = drop ,
2017-01-09 13:39:36 +01:00
sounds = def.sounds ,
node_box = {
type = " fixed " ,
fixed = { { - 1 / 2 , - 1 / 2 , - 1 / 32 , 1 / 2 , 1 / 2 , 1 / 32 } } ,
} ,
selection_box = {
type = " fixed " ,
fixed = { { - 1 / 2 , - 1 / 2 , - 1 / 32 , 1 / 2 , 1 / 2 , 1 / 32 } } ,
} ,
connect_sides = { " left " , " right " } ,
2017-02-27 18:32:35 +01:00
_mcl_blast_resistance = def._mcl_blast_resistance ,
_mcl_hardness = def._mcl_hardness ,
2021-01-17 10:41:13 +01:00
_mcl_silk_touch_drop = def._mcl_silk_touch_drop and { " xpanes: " .. name .. " _flat " } ,
2015-06-29 19:55:56 +02:00
} )
2017-01-09 13:39:36 +01:00
local groups = table.copy ( def.groups )
groups.pane = 1
groups.not_in_creative_inventory = 1
minetest.register_node ( " :xpanes: " .. name , {
drawtype = " nodebox " ,
paramtype = " light " ,
is_ground_content = false ,
sunlight_propagates = true ,
2017-03-02 19:53:53 +01:00
_doc_items_create_entry = false ,
2017-07-26 22:39:16 +02:00
tiles = { def.textures [ 3 ] , def.textures [ 2 ] , def.textures [ 1 ] } ,
2017-02-13 15:52:16 +01:00
use_texture_alpha = def.use_texture_alpha ,
2017-01-09 13:39:36 +01:00
groups = groups ,
2021-04-16 13:35:03 +02:00
drop = drop ,
2017-01-09 13:39:36 +01:00
sounds = def.sounds ,
node_box = {
type = " connected " ,
fixed = { { - 1 / 32 , - 1 / 2 , - 1 / 32 , 1 / 32 , 1 / 2 , 1 / 32 } } ,
connect_front = { { - 1 / 32 , - 1 / 2 , - 1 / 2 , 1 / 32 , 1 / 2 , - 1 / 32 } } ,
connect_left = { { - 1 / 2 , - 1 / 2 , - 1 / 32 , - 1 / 32 , 1 / 2 , 1 / 32 } } ,
connect_back = { { - 1 / 32 , - 1 / 2 , 1 / 32 , 1 / 32 , 1 / 2 , 1 / 2 } } ,
connect_right = { { 1 / 32 , - 1 / 2 , - 1 / 32 , 1 / 2 , 1 / 2 , 1 / 32 } } ,
} ,
connects_to = { " group:pane " , " group:stone " , " group:glass " , " group:wood " , " group:tree " } ,
2017-02-27 18:32:35 +01:00
_mcl_blast_resistance = def._mcl_blast_resistance ,
_mcl_hardness = def._mcl_hardness ,
2021-01-17 10:41:13 +01:00
_mcl_silk_touch_drop = def._mcl_silk_touch_drop and { " xpanes: " .. name .. " _flat " } ,
2017-01-09 13:39:36 +01:00
} )
2015-06-29 19:55:56 +02:00
minetest.register_craft ( {
2017-01-09 13:39:36 +01:00
output = " xpanes: " .. name .. " _flat 16 " ,
recipe = def.recipe
} )
2017-03-20 18:12:05 +01:00
2019-03-24 10:31:58 +01:00
if mod_doc and def._doc_items_create_entry ~= false then
2017-03-20 18:12:05 +01:00
doc.add_entry_alias ( " nodes " , " xpanes: " .. name .. " _flat " , " nodes " , " xpanes: " .. name )
end
2017-01-09 13:39:36 +01:00
end
2019-03-24 10:51:45 +01:00
local canonical_color = " yellow "
2017-07-17 18:14:11 +02:00
-- Register glass pane (stained and unstained)
2021-05-25 12:52:25 +02:00
local function pane ( description , node , append )
2019-03-24 10:31:58 +01:00
local texture1 , longdesc , entry_name , create_entry
local is_canonical = true
2017-07-17 18:14:11 +02:00
-- Special case: Default (unstained) glass texture
if append == " _natural " then
texture1 = " default_glass.png "
2019-03-24 10:40:07 +01:00
longdesc = S ( " Glass panes are thin layers of glass which neatly connect to their neighbors as you build them. " )
2017-07-17 18:14:11 +02:00
else
2019-03-24 10:31:58 +01:00
if append ~= " _ " .. canonical_color then
is_canonical = false
create_entry = false
else
2019-03-24 10:40:07 +01:00
longdesc = S ( " Stained glass panes are thin layers of stained glass which neatly connect to their neighbors as you build them. They come in many different colors. " )
2019-03-24 10:31:58 +01:00
entry_name = S ( " Stained Glass Pane " )
end
2017-07-17 18:14:11 +02:00
texture1 = " mcl_core_glass " .. append .. " .png "
end
2017-01-09 13:39:36 +01:00
xpanes.register_pane ( " pane " .. append , {
description = description ,
2019-03-24 10:31:58 +01:00
_doc_items_create_entry = create_entry ,
_doc_items_entry_name = entry_name ,
_doc_items_longdesc = longdesc ,
2017-07-26 22:39:16 +02:00
textures = { texture1 , texture1 , " xpanes_top_glass " .. append .. " .png " } ,
2021-02-18 10:39:19 +01:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " blend " or true ,
2017-07-17 18:14:11 +02:00
inventory_image = texture1 ,
wield_image = texture1 ,
2017-02-11 18:46:23 +01:00
sounds = mcl_sounds.node_sound_glass_defaults ( ) ,
2017-03-11 05:34:58 +01:00
groups = { handy = 1 , material_glass = 1 } ,
2015-06-29 19:55:56 +02:00
recipe = {
2017-01-09 13:39:36 +01:00
{ node , node , node } ,
{ node , node , node } ,
2017-02-21 23:41:44 +01:00
} ,
drop = " " ,
2020-04-17 21:40:13 +02:00
_mcl_blast_resistance = 0.3 ,
2017-02-27 18:32:35 +01:00
_mcl_hardness = 0.3 ,
2020-11-02 19:09:23 +01:00
_mcl_silk_touch_drop = true ,
2015-06-29 19:55:56 +02:00
} )
2019-03-24 10:31:58 +01:00
if mod_doc and not is_canonical then
doc.add_entry_alias ( " nodes " , " xpanes:pane_ " .. canonical_color .. " _flat " , " nodes " , " xpanes:pane " .. append )
doc.add_entry_alias ( " nodes " , " xpanes:pane_ " .. canonical_color .. " _flat " , " nodes " , " xpanes:pane " .. append .. " _flat " )
end
2015-06-29 19:55:56 +02:00
end
2017-01-09 13:39:36 +01:00
2017-07-17 18:14:11 +02:00
-- Iron Bars
2017-01-09 13:39:36 +01:00
xpanes.register_pane ( " bar " , {
2019-03-08 00:46:35 +01:00
description = S ( " Iron Bars " ) ,
_doc_items_longdesc = S ( " Iron bars neatly connect to their neighbors as you build them. " ) ,
2017-07-26 22:39:16 +02:00
textures = { " xpanes_pane_iron.png " , " xpanes_pane_iron.png " , " xpanes_top_iron.png " } ,
2017-01-09 13:39:36 +01:00
inventory_image = " xpanes_pane_iron.png " ,
wield_image = " xpanes_pane_iron.png " ,
2017-02-27 18:32:35 +01:00
groups = { pickaxey = 1 } ,
2017-02-11 18:46:23 +01:00
sounds = mcl_sounds.node_sound_metal_defaults ( ) ,
2021-02-18 14:00:17 +01:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " clip " or true ,
2017-01-09 13:39:36 +01:00
recipe = {
2017-02-11 21:14:40 +01:00
{ " mcl_core:iron_ingot " , " mcl_core:iron_ingot " , " mcl_core:iron_ingot " } ,
{ " mcl_core:iron_ingot " , " mcl_core:iron_ingot " , " mcl_core:iron_ingot " } ,
2017-02-27 18:32:35 +01:00
} ,
2020-04-17 21:40:13 +02:00
_mcl_blast_resistance = 6 ,
2017-02-27 18:32:35 +01:00
_mcl_hardness = 5 ,
2017-01-09 13:39:36 +01:00
} )
2017-07-17 18:14:11 +02:00
-- Glass Pane
2019-03-08 00:46:35 +01:00
pane ( S ( " Glass Pane " ) , " mcl_core:glass " , " _natural " ) -- triggers special case
2017-07-17 18:14:11 +02:00
-- Stained Glass Pane
2019-03-08 00:46:35 +01:00
pane ( S ( " Red Stained Glass Pane " ) , " mcl_core:glass_red " , " _red " )
pane ( S ( " Green Stained Glass Pane " ) , " mcl_core:glass_green " , " _green " )
pane ( S ( " Blue Stained Glass Pane " ) , " mcl_core:glass_blue " , " _blue " )
pane ( S ( " Light Blue Stained Glass Pane " ) , " mcl_core:glass_light_blue " , " _light_blue " )
pane ( S ( " Black Stained Glass Pane " ) , " mcl_core:glass_black " , " _black " )
pane ( S ( " White Stained Glass Pane " ) , " mcl_core:glass_white " , " _white " )
pane ( S ( " Yellow Stained Glass Pane " ) , " mcl_core:glass_yellow " , " _yellow " )
pane ( S ( " Brown Stained Glass Pane " ) , " mcl_core:glass_brown " , " _brown " )
pane ( S ( " Orange Stained Glass Pane " ) , " mcl_core:glass_orange " , " _orange " )
pane ( S ( " Pink Stained Glass Pane " ) , " mcl_core:glass_pink " , " _pink " )
pane ( S ( " Grey Stained Glass Pane " ) , " mcl_core:glass_gray " , " _gray " )
pane ( S ( " Lime Stained Glass Pane " ) , " mcl_core:glass_lime " , " _lime " )
pane ( S ( " Light Grey Stained Glass Pane " ) , " mcl_core:glass_silver " , " _silver " )
pane ( S ( " Magenta Stained Glass Pane " ) , " mcl_core:glass_magenta " , " _magenta " )
pane ( S ( " Purple Stained Glass Pane " ) , " mcl_core:glass_purple " , " _purple " )
pane ( S ( " Cyan Stained Glass Pane " ) , " mcl_core:glass_cyan " , " _cyan " )