2015-07-03 07:57:09 +03:00
local init = os.clock ( )
2015-06-29 20:55:56 +03:00
2017-01-17 04:55:27 +03:00
-- Node box
2017-05-19 15:22:06 +03:00
local p = { - 2 / 16 , - 0.5 , - 2 / 16 , 2 / 16 , 0.5 , 2 / 16 }
local x1 = { - 0.5 , 4 / 16 , - 1 / 16 , - 2 / 16 , 7 / 16 , 1 / 16 } --oben(quer) -x
local x12 = { - 0.5 , - 2 / 16 , - 1 / 16 , - 2 / 16 , 1 / 16 , 1 / 16 } --unten(quer) -x
local x2 = { 2 / 16 , 4 / 16 , - 1 / 16 , 0.5 , 7 / 16 , 1 / 16 } --oben(quer) x
local x22 = { 2 / 16 , - 2 / 16 , - 1 / 16 , 0.5 , 1 / 16 , 1 / 16 } --unten(quer) x
local z1 = { - 1 / 16 , 4 / 16 , - 0.5 , 1 / 16 , 7 / 16 , - 2 / 16 } --oben(quer) -z
local z12 = { - 1 / 16 , - 2 / 16 , - 0.5 , 1 / 16 , 1 / 16 , - 2 / 16 } --unten(quer) -z
local z2 = { - 1 / 16 , 4 / 16 , 2 / 16 , 1 / 16 , 7 / 16 , 0.5 } --oben(quer) z
local z22 = { - 1 / 16 , - 2 / 16 , 2 / 16 , 1 / 16 , 1 / 16 , 0.5 } --unten(quer) z
2015-06-29 20:55:56 +03:00
2017-01-17 04:55:27 +03:00
-- Collision box
2017-05-19 15:22:06 +03:00
local cp = { - 2 / 16 , - 0.5 , - 2 / 16 , 2 / 16 , 1 , 2 / 16 }
local cx1 = { - 0.5 , - 2 / 16 , - 2 / 16 , - 2 / 16 , 1 , 2 / 16 } --unten(quer) -x
local cx2 = { 2 / 16 , - 2 / 16 , - 2 / 16 , 0.5 , 1 , 2 / 16 } --unten(quer) x
local cz1 = { - 2 / 16 , - 2 / 16 , - 0.5 , 2 / 16 , 1 , - 2 / 16 } --unten(quer) -z
local cz2 = { - 2 / 16 , - 2 / 16 , 2 / 16 , 2 / 16 , 1 , 0.5 } --unten(quer) z
2015-06-29 20:55:56 +03:00
2017-01-17 06:01:29 +03:00
mcl_fences = { }
2017-02-21 22:18:08 +03:00
2017-02-28 00:13:28 +03:00
mcl_fences.register_fence = function ( id , fence_name , texture , groups , hardness , blast_resistance , connects_to , sounds )
2017-03-01 04:04:55 +03:00
local cgroups = table.copy ( groups )
if cgroups == nil then cgroups = { } end
cgroups.fence = 1
cgroups.deco_block = 1
2017-03-17 07:19:38 +03:00
if connects_to == nil then
connects_to = { }
else
connects_to = table.copy ( connects_to )
end
2017-02-10 07:33:49 +03:00
local fence_id = minetest.get_current_modname ( ) .. " : " .. id
2017-01-17 06:01:29 +03:00
table.insert ( connects_to , " group:solid " )
2017-02-10 07:33:49 +03:00
table.insert ( connects_to , " group:fence_gate " )
table.insert ( connects_to , fence_id )
minetest.register_node ( fence_id , {
2017-01-17 06:01:29 +03:00
description = fence_name ,
2017-03-11 03:51:06 +03:00
_doc_items_longdesc = " Fences are structures which block the way. Fences will connect to each other and solid blocks. They cannot be jumped over with a simple jump. " ,
2017-01-17 06:01:29 +03:00
tiles = { texture } ,
2017-01-17 06:18:36 +03:00
inventory_image = " mcl_fences_fence_mask.png^ " .. texture .. " ^mcl_fences_fence_mask.png^[makealpha:255,126,126 " ,
wield_image = " mcl_fences_fence_mask.png^ " .. texture .. " ^mcl_fences_fence_mask.png^[makealpha:255,126,126 " ,
2017-01-17 06:01:29 +03:00
paramtype = " light " ,
is_ground_content = false ,
2017-03-01 04:04:55 +03:00
groups = cgroups ,
2017-01-17 06:01:29 +03:00
stack_max = 64 ,
sunlight_propagates = true ,
drawtype = " nodebox " ,
connect_sides = { " front " , " back " , " left " , " right " } ,
connects_to = connects_to ,
node_box = {
type = " connected " ,
fixed = { p } ,
connect_front = { z1 , z12 } ,
connect_back = { z2 , z22 , } ,
connect_left = { x1 , x12 } ,
connect_right = { x2 , x22 } ,
} ,
collision_box = {
type = " connected " ,
fixed = { cp } ,
connect_front = { cz1 } ,
connect_back = { cz2 , } ,
connect_left = { cx1 } ,
connect_right = { cx2 } ,
} ,
sounds = sounds ,
2017-02-28 00:13:28 +03:00
_mcl_blast_resistance = blast_resistance ,
_mcl_hardness = hardness ,
2017-01-17 06:01:29 +03:00
} )
2017-02-21 22:53:43 +03:00
return fence_id
2017-02-21 22:18:08 +03:00
end
2015-06-29 20:55:56 +03:00
2017-02-28 00:13:28 +03:00
mcl_fences.register_fence_gate = function ( id , fence_gate_name , texture , groups , hardness , blast_resistance , sounds , sound_open , sound_close , sound_gain_open , sound_gain_close )
2017-01-17 06:01:29 +03:00
local meta2
local state2 = 0
2015-06-29 20:55:56 +03:00
2017-01-17 06:01:29 +03:00
local function update_gate ( pos , node )
minetest.set_node ( pos , node )
end
2015-06-29 20:55:56 +03:00
2017-02-21 22:18:08 +03:00
local gate_id = minetest.get_current_modname ( ) .. " : " .. id .. " _gate "
2017-02-21 22:53:43 +03:00
local open_gate_id = gate_id .. " _open "
2017-02-22 05:57:12 +03:00
if not sound_open then
sound_open = " doors_fencegate_open "
end
if not sound_close then
sound_close = " doors_fencegate_close "
end
2017-02-23 17:41:46 +03:00
if not sound_gain_open then
sound_gain_open = 0.3
end
if not sound_gain_close then
sound_gain_close = 0.3
2017-02-22 05:57:12 +03:00
end
2017-01-17 06:01:29 +03:00
local function punch_gate ( pos , node )
meta2 = minetest.get_meta ( pos )
state2 = meta2 : get_int ( " state " )
local tmp_node2
2015-06-29 20:55:56 +03:00
if state2 == 1 then
state2 = 0
2017-07-23 23:25:25 +03:00
minetest.sound_play ( sound_close , { gain = sound_gain_close , max_hear_distance = 10 , pos = pos } )
2017-02-21 22:18:08 +03:00
tmp_node2 = { name = gate_id , param1 = node.param1 , param2 = node.param2 }
2015-06-29 20:55:56 +03:00
else
state2 = 1
2017-07-23 23:25:25 +03:00
minetest.sound_play ( sound_open , { gain = sound_gain_open , max_hear_distance = 10 , pos = pos } )
2017-02-21 22:53:43 +03:00
tmp_node2 = { name = open_gate_id , param1 = node.param1 , param2 = node.param2 }
2015-06-29 20:55:56 +03:00
end
update_gate ( pos , tmp_node2 )
meta2 : set_int ( " state " , state2 )
2017-01-17 06:01:29 +03:00
end
2015-06-29 20:55:56 +03:00
2017-03-01 04:04:55 +03:00
local cgroups = table.copy ( groups )
if cgroups == nil then cgroups = { } end
cgroups.fence_gate = 1
cgroups.deco_block = 1
2017-02-08 22:26:04 +03:00
2017-03-01 04:04:55 +03:00
cgroups.mesecon_effector_on = 1
cgroups.fence_gate = 1
2017-02-21 22:53:43 +03:00
minetest.register_node ( open_gate_id , {
2017-01-17 06:01:29 +03:00
tiles = { texture } ,
paramtype = " light " ,
paramtype2 = " facedir " ,
2017-01-17 06:18:36 +03:00
inventory_image = " mcl_fences_fence_gate_mask.png^ " .. texture .. " ^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126 " ,
wield_image = " mcl_fences_fence_gate_mask.png^ " .. texture .. " ^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126 " ,
2017-01-17 06:01:29 +03:00
is_ground_content = false ,
sunlight_propagates = true ,
2017-06-10 04:47:35 +03:00
walkable = false ,
2017-03-01 04:04:55 +03:00
groups = cgroups ,
2017-02-22 05:28:25 +03:00
drop = gate_id ,
2017-01-17 06:01:29 +03:00
drawtype = " nodebox " ,
node_box = {
type = " fixed " ,
fixed = {
2017-05-19 15:22:06 +03:00
{ - 0.5 , - 3 / 16 , - 1 / 16 , - 6 / 16 , 0.5 , 1 / 16 } , --links abschluss
{ 6 / 16 , - 3 / 16 , - 1 / 16 , 0.5 , 0.5 , 1 / 16 } , --rechts abschluss
{ - 0.5 , 4 / 16 , 1 / 16 , - 6 / 16 , 7 / 16 , 6 / 16 } , --oben-links(quer) x
{ - 0.5 , - 2 / 16 , 1 / 16 , - 6 / 16 , 1 / 16 , 6 / 16 } , --unten-links(quer) x
{ 6 / 16 , 4 / 16 , 1 / 16 , 0.5 , 7 / 16 , 0.5 } , --oben-rechts(quer) x
{ 6 / 16 , - 2 / 16 , 1 / 16 , 0.5 , 1 / 16 , 0.5 } , --unten-rechts(quer) x
{ - 0.5 , - 2 / 16 , 6 / 16 , - 6 / 16 , 7 / 16 , 0.5 } , --mitte links
{ 6 / 16 , 1 / 16 , 0.5 , 0.5 , 4 / 16 , 6 / 16 } , --mitte rechts
2015-06-29 20:55:56 +03:00
}
2017-01-17 06:01:29 +03:00
} ,
selection_box = {
type = " fixed " ,
fixed = {
2017-05-19 15:22:06 +03:00
{ - 0.5 , - 3 / 16 , - 1 / 16 , 0.5 , 0.5 , 1 / 16 } , --gate
2017-01-17 06:01:29 +03:00
}
} ,
on_rightclick = function ( pos , node , clicker )
punch_gate ( pos , node )
end ,
mesecons = { effector = {
action_on = ( function ( pos , node )
punch_gate ( pos , node )
end ) ,
} } ,
2017-01-17 06:19:37 +03:00
sounds = sounds ,
2017-02-28 00:13:28 +03:00
_mcl_blast_resistance = blast_resistance ,
_mcl_hardness = hardness ,
2017-01-17 06:01:29 +03:00
} )
2015-06-29 20:55:56 +03:00
2017-03-01 04:04:55 +03:00
local cgroups_closed = table.copy ( cgroups )
cgroups_closed.mesecon_effector_on = nil
cgroups_closed.mesecon_effector_off = nil
2017-02-21 22:18:08 +03:00
minetest.register_node ( gate_id , {
2017-01-17 06:01:29 +03:00
description = fence_gate_name ,
2017-03-11 03:51:06 +03:00
_doc_items_longdesc = " Fence gates can be opened or closed and can't be jumped over. Fences will connect nicely to fence gates. " ,
_doc_items_usagehelp = " Right-click the fence gate to open or close it. " ,
2017-01-17 06:01:29 +03:00
tiles = { texture } ,
2017-01-17 06:18:36 +03:00
inventory_image = " mcl_fences_fence_gate_mask.png^ " .. texture .. " ^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126 " ,
wield_image = " mcl_fences_fence_gate_mask.png^ " .. texture .. " ^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126 " ,
2017-01-17 06:01:29 +03:00
paramtype = " light " ,
is_ground_content = false ,
stack_max = 64 ,
paramtype2 = " facedir " ,
sunlight_propagates = true ,
walkable = true ,
2017-03-01 04:04:55 +03:00
groups = cgroups_closed ,
2017-01-17 06:01:29 +03:00
drawtype = " nodebox " ,
node_box = {
type = " fixed " ,
fixed = {
2017-05-19 15:22:06 +03:00
{ - 0.5 , - 3 / 16 , - 1 / 16 , - 6 / 16 , 0.5 , 1 / 16 } , --links abschluss
{ 6 / 16 , - 3 / 16 , - 1 / 16 , 0.5 , 0.5 , 1 / 16 } , --rechts abschluss
{ - 2 / 16 , - 2 / 16 , - 1 / 16 , 0 , 7 / 16 , 1 / 16 } , --mitte links
{ 0 , - 2 / 16 , - 1 / 16 , 2 / 16 , 7 / 16 , 1 / 16 } , --mitte rechts
{ - 0.5 , 4 / 16 , - 1 / 16 , - 2 / 16 , 7 / 16 , 1 / 16 } , --oben(quer) -z
{ - 0.5 , - 2 / 16 , - 1 / 16 , - 2 / 16 , 1 / 16 , 1 / 16 } , --unten(quer) -z
{ 2 / 16 , 4 / 16 , - 1 / 16 , 0.5 , 7 / 16 , 1 / 16 } , --oben(quer) z
{ 2 / 16 , - 2 / 16 , - 1 / 16 , 0.5 , 1 / 16 , 1 / 16 } , --unten(quer) z
2015-06-29 20:55:56 +03:00
}
2017-01-17 06:01:29 +03:00
} ,
2017-01-20 20:31:24 +03:00
collision_box = {
type = " fixed " ,
fixed = {
2017-05-19 15:22:06 +03:00
{ - 0.5 , - 3 / 16 , - 2 / 16 , 0.5 , 1 , 2 / 16 } , --gate
2017-01-20 20:31:24 +03:00
}
} ,
2017-01-17 06:01:29 +03:00
selection_box = {
type = " fixed " ,
fixed = {
2017-05-19 15:22:06 +03:00
{ - 0.5 , - 3 / 16 , - 1 / 16 , 0.5 , 0.5 , 1 / 16 } , --gate
2015-06-29 20:55:56 +03:00
}
2017-01-17 06:01:29 +03:00
} ,
on_construct = function ( pos )
meta2 = minetest.get_meta ( pos )
meta2 : set_int ( " state " , 0 )
state2 = 0
end ,
mesecons = { effector = {
action_on = ( function ( pos , node )
punch_gate ( pos , node )
end ) ,
} } ,
on_rightclick = function ( pos , node , clicker )
punch_gate ( pos , node )
end ,
2017-01-17 06:19:37 +03:00
sounds = sounds ,
2017-02-28 00:13:28 +03:00
_mcl_blast_resistance = blast_resistance ,
_mcl_hardness = hardness ,
2017-01-17 06:01:29 +03:00
} )
2017-03-20 20:12:05 +03:00
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , gate_id , " nodes " , open_gate_id )
end
2017-02-21 22:53:43 +03:00
return gate_id , open_gate_id
2017-01-17 06:01:29 +03:00
end
2017-07-24 01:37:45 +03:00
mcl_fences.register_fence_and_fence_gate = function ( id , fence_name , fence_gate_name , texture_fence , groups , hardness , blast_resistance , connects_to , sounds , sound_open , sound_close , sound_gain_open , sound_gain_close , texture_fence_gate )
if texture_fence_gate == nil then
texture_fence_gate = texture_fence
end
local fence_id = mcl_fences.register_fence ( id , fence_name , texture_fence , groups , hardness , blast_resistance , connects_to , sounds )
local gate_id , open_gate_id = mcl_fences.register_fence_gate ( id , fence_gate_name , texture_fence_gate , groups , hardness , blast_resistance , sounds , sound_open , sound_close , sound_gain_open , sound_gain_close )
2017-02-21 22:53:43 +03:00
return fence_id , gate_id , open_gate_id
2017-02-21 22:18:08 +03:00
end
2017-02-27 03:28:55 +03:00
local wood_groups = { handy = 1 , axey = 1 , flammable = 2 , fence_wood = 1 }
2017-02-10 07:33:49 +03:00
local wood_connect = { " group:fence_wood " }
2017-02-11 20:46:23 +03:00
local wood_sounds = mcl_sounds.node_sound_wood_defaults ( )
2017-01-17 06:01:29 +03:00
local woods = {
2017-07-24 01:37:45 +03:00
{ " " , " Oak Fence " , " Oak Fence Gate " , " mcl_fences_fence_oak.png " , " mcl_fences_fence_gate_oak.png " , " mcl_core:wood " } ,
{ " spruce " , " Spruce Fence " , " Spruce Fence Gate " , " mcl_fences_fence_spruce.png " , " mcl_fences_fence_gate_spruce.png " , " mcl_core:sprucewood " } ,
{ " birch " , " Birch Fence " , " Birch Fence Gate " , " mcl_fences_fence_birch.png " , " mcl_fences_fence_gate_birch.png " , " mcl_core:birchwood " } ,
{ " jungle " , " Jungle Fence " , " Jungle Fence Gate " , " mcl_fences_fence_jungle.png " , " mcl_fences_fence_gate_jungle.png " , " mcl_core:junglewood " } ,
{ " dark_oak " , " Dark Oak Fence " , " Dark Oak Fence Gate " , " mcl_fences_fence_big_oak.png " , " mcl_fences_fence_gate_big_oak.png " , " mcl_core:darkwood " } ,
{ " acacia " , " Acacia Fence " , " Acacia Fence Gate " , " mcl_fences_fence_acacia.png " , " mcl_fences_fence_gate_acacia.png " , " mcl_core:acaciawood " } ,
2017-01-17 06:01:29 +03:00
}
for w = 1 , # woods do
local wood = woods [ w ]
local id , id_gate
if wood [ 1 ] == " " then
id = " fence "
id_gate = " fence_gate "
else
id = wood [ 1 ] .. " _fence "
id_gate = wood [ 1 ] .. " _fence_gate "
end
2017-02-28 00:13:28 +03:00
mcl_fences.register_fence_and_fence_gate ( id , wood [ 2 ] , wood [ 3 ] , wood [ 4 ] , wood_groups , 2 , 15 , wood_connect , wood_sounds )
2017-01-17 06:01:29 +03:00
minetest.register_craft ( {
output = ' mcl_fences: ' .. id .. ' 3 ' ,
recipe = {
2017-02-22 06:09:21 +03:00
{ wood [ 5 ] , ' mcl_core:stick ' , wood [ 5 ] } ,
{ wood [ 5 ] , ' mcl_core:stick ' , wood [ 5 ] } ,
2017-01-17 06:01:29 +03:00
}
} )
minetest.register_craft ( {
output = ' mcl_fences: ' .. id_gate ,
recipe = {
2017-02-22 06:09:21 +03:00
{ ' mcl_core:stick ' , wood [ 5 ] , ' mcl_core:stick ' } ,
{ ' mcl_core:stick ' , wood [ 5 ] , ' mcl_core:stick ' } ,
2017-01-17 06:01:29 +03:00
}
} )
end
2017-02-21 22:18:08 +03:00
2017-02-08 22:26:04 +03:00
-- Nether Brick Fence (without fence gate!)
2017-07-24 01:37:45 +03:00
mcl_fences.register_fence ( " nether_brick_fence " , " Nether Brick Fence " , " mcl_fences_fence_nether_brick.png " , { pickaxey = 1 , deco_block = 1 , fence_nether_brick = 1 } , 2 , 30 , { " group:fence_nether_brick " } , mcl_sounds.node_sound_stone_defaults ( ) )
2017-02-08 22:26:04 +03:00
minetest.register_craft ( {
output = ' mcl_fences:nether_brick_fence 6 ' ,
recipe = {
{ " mcl_nether:nether_brick " , " mcl_nether:nether_brick " , " mcl_nether:nether_brick " } ,
{ " mcl_nether:nether_brick " , " mcl_nether:nether_brick " , " mcl_nether:nether_brick " } ,
}
} )
2017-01-17 06:01:29 +03:00
minetest.register_craft ( {
type = " fuel " ,
recipe = " group:fence_wood " ,
burntime = 15 ,
2015-06-29 20:55:56 +03:00
} )
2015-07-03 07:57:09 +03:00
local time_to_load = os.clock ( ) - init
print ( string.format ( " [MOD] " .. minetest.get_current_modname ( ) .. " loaded in %.4f s " , time_to_load ) )
2017-01-17 06:01:29 +03:00