1 -- Minetest 0.4 mod: doors
2 -- See README.txt for licensing and other information.
3 --------------------------------------------------------------------------------
10 --------------------------------------------------------------------------------
12 minetest.register_alias('door', 'doors:door_wood')
13 minetest.register_alias('door_wood', 'doors:door_wood')
15 minetest.register_node( 'doors:door_wood', {
16 description = 'Wooden Door',
17 drawtype = 'signlike',
18 tile_images = { 'door_wood.png' },
19 inventory_image = 'door_wood.png',
20 wield_image = 'door_wood.png',
21 paramtype2 = 'wallmounted',
22 selection_box = { type = 'wallmounted' },
23 groups = { choppy=2, dig_immediate=2 },
26 minetest.register_craft( {
27 output = 'doors:door_wood',
29 { 'default:wood', 'default:wood' },
30 { 'default:wood', 'default:wood' },
31 { 'default:wood', 'default:wood' },
35 minetest.register_craft({
37 recipe = 'doors:door_wood',
41 minetest.register_node( 'doors:door_wood_a_c', {
42 Description = 'Top Closed Door',
43 drawtype = 'signlike',
44 tile_images = { 'door_wood_a.png' },
45 inventory_image = 'door_wood_a.png',
47 paramtype2 = 'wallmounted',
49 selection_box = { type = "wallmounted", },
50 groups = { choppy=2, dig_immediate=2 },
51 legacy_wallmounted = true,
52 drop = 'doors:door_wood',
55 minetest.register_node( 'doors:door_wood_b_c', {
56 Description = 'Bottom Closed Door',
57 drawtype = 'signlike',
58 tile_images = { 'door_wood_b.png' },
59 inventory_image = 'door_wood_b.png',
61 paramtype2 = 'wallmounted',
63 selection_box = { type = "wallmounted", },
64 groups = { choppy=2, dig_immediate=2 },
65 legacy_wallmounted = true,
66 drop = 'doors:door_wood',
69 minetest.register_node( 'doors:door_wood_a_o', {
70 Description = 'Top Open Door',
71 drawtype = 'signlike',
72 tile_images = { 'door_wood_a_r.png' },
73 inventory_image = 'door_wood_a_r.png',
75 paramtype2 = 'wallmounted',
77 selection_box = { type = "wallmounted", },
78 groups = { choppy=2, dig_immediate=2 },
79 legacy_wallmounted = true,
80 drop = 'doors:door_wood',
83 minetest.register_node( 'doors:door_wood_b_o', {
84 Description = 'Bottom Open Door',
85 drawtype = 'signlike',
86 tile_images = { 'door_wood_b_r.png' },
87 inventory_image = 'door_wood_b_r.png',
89 paramtype2 = 'wallmounted',
91 selection_box = { type = "wallmounted", },
92 groups = { choppy=2, dig_immediate=2 },
93 legacy_wallmounted = true,
94 drop = 'doors:door_wood',
97 --------------------------------------------------------------------------------
99 local round = function( n )
101 return math.floor( n + 0.5 )
103 return math.ceil( n - 0.5 )
107 local on_door_placed = function( pos, node, placer )
108 if node.name ~= 'doors:door_wood' then return end
110 upos = { x = pos.x, y = pos.y - 1, z = pos.z }
111 apos = { x = pos.x, y = pos.y + 1, z = pos.z }
112 und = minetest.env:get_node( upos )
113 abv = minetest.env:get_node( apos )
115 dir = placer:get_look_dir()
117 if round( dir.x ) == 1 then
119 elseif round( dir.x ) == -1 then
121 elseif round( dir.z ) == 1 then
123 elseif round( dir.z ) == -1 then
127 if und.name == 'air' then
128 minetest.env:add_node( pos, { name = 'doors:door_wood_a_c', param2 = newparam } )
129 minetest.env:add_node( upos, { name = 'doors:door_wood_b_c', param2 = newparam } )
130 elseif abv.name == 'air' then
131 minetest.env:add_node( pos, { name = 'doors:door_wood_b_c', param2 = newparam } )
132 minetest.env:add_node( apos, { name = 'doors:door_wood_a_c', param2 = newparam } )
134 minetest.env:remove_node( pos )
135 placer:get_inventory():add_item( "main", 'doors:door_wood' )
136 minetest.chat_send_player( placer:get_player_name(), 'not enough space' )
140 local on_door_punched = function( pos, node, puncher )
141 if string.find( node.name, 'doors:door_wood' ) == nil then return end
143 upos = { x = pos.x, y = pos.y - 1, z = pos.z }
144 apos = { x = pos.x, y = pos.y + 1, z = pos.z }
146 if string.find( node.name, '_c', -2 ) ~= nil then
147 if node.param2 == WALLPX then
149 elseif node.param2 == WALLMZ then
151 elseif node.param2 == WALLMX then
153 elseif node.param2 == WALLPZ then
156 elseif string.find( node.name, '_o', -2 ) ~= nil then
157 if node.param2 == WALLMZ then
159 elseif node.param2 == WALLMX then
161 elseif node.param2 == WALLPZ then
163 elseif node.param2 == WALLPX then
168 if ( node.name == 'doors:door_wood_a_c' ) then
169 minetest.env:add_node( pos, { name = 'doors:door_wood_a_o', param2 = newparam } )
170 minetest.env:add_node( upos, { name = 'doors:door_wood_b_o', param2 = newparam } )
172 elseif ( node.name == 'doors:door_wood_b_c' ) then
173 minetest.env:add_node( pos, { name = 'doors:door_wood_b_o', param2 = newparam } )
174 minetest.env:add_node( apos, { name = 'doors:door_wood_a_o', param2 = newparam } )
176 elseif ( node.name == 'doors:door_wood_a_o' ) then
177 minetest.env:add_node( pos, { name = 'doors:door_wood_a_c', param2 = newparam } )
178 minetest.env:add_node( upos, { name = 'doors:door_wood_b_c', param2 = newparam } )
180 elseif ( node.name == 'doors:door_wood_b_o' ) then
181 minetest.env:add_node( pos, { name = 'doors:door_wood_b_c', param2 = newparam } )
182 minetest.env:add_node( apos, { name = 'doors:door_wood_a_c', param2 = newparam } )
187 local on_door_digged = function( pos, node, digger )
188 upos = { x = pos.x, y = pos.y - 1, z = pos.z }
189 apos = { x = pos.x, y = pos.y + 1, z = pos.z }
191 if ( node.name == 'doors:door_wood_a_c' ) or ( node.name == 'doors:door_wood_a_o' ) then
192 minetest.env:remove_node( upos )
193 elseif ( node.name == 'doors:door_wood_b_c' ) or ( node.name == 'doors:door_wood_b_o' ) then
194 minetest.env:remove_node( apos )
198 --------------------------------------------------------------------------------
200 minetest.register_on_placenode( on_door_placed )
201 minetest.register_on_punchnode( on_door_punched )
202 minetest.register_on_dignode( on_door_digged )
204 --------------------------------------------------------------------------------