Advertisement
Guest User

Untitled

a guest
Aug 16th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1.  
  2.  
  3. --------------------------------------------------------------------------------
  4.  
  5. local WALLMX = 3
  6. local WALLMZ = 5
  7. local WALLPX = 2
  8. local WALLPZ = 4
  9.  
  10. --------------------------------------------------------------------------------
  11.  
  12. minetest.register_alias('door_steel', 'moredoors:door_steel')
  13. minetest.register_alias('door_cobble', 'moredoors:door_cobble')
  14.  
  15. minetest.register_node( 'moredoors:door_steel', {
  16. description = 'Steel Door',
  17. drawtype = 'signlike',
  18. tile_images = { 'door_steel.png' },
  19. inventory_image = 'door_steel.png',
  20. wield_image = 'door_steel.png',
  21. paramtype2 = 'wallmounted',
  22. selection_box = { type = 'wallmounted' },
  23. groups = { choppy=2, dig_immediate=2 },
  24. })
  25.  
  26. minetest.register_craft( {
  27. output = 'moredoors:door_steel',
  28. recipe = {
  29. { 'default:steel', 'default:steel' },
  30. { 'default:steel', 'default:steel' },
  31. { 'default:steel', 'default:steel' },
  32. },
  33. })
  34.  
  35.  
  36. minetest.register_node( 'moredoors:door_cobble', {
  37. Description = 'Cobble door',
  38. drawtype = 'signlike',
  39. tile_images = { 'door_cobble.png' },
  40. inventory_image = 'door_cobble.png',
  41. paramtype = 'light',
  42. paramtype2 = 'wallmounted',
  43. walkable = true,
  44. selection_box = { type = "wallmounted", },
  45. groups = { choppy=2, dig_immediate=2 },
  46. legacy_wallmounted = true,
  47. drop = 'moredoors:door_cobble',
  48. })
  49.  
  50. minetest.register_craft( {
  51. output = 'moredoors:door_cobble',
  52. recipe = {
  53. { 'default:cobble', 'default:cooble' },
  54. { 'default:cobble', 'default:cobble' },
  55. { 'default:cobble', 'default:cobble' },
  56. },
  57. })
  58.  
  59.  
  60. --------------------------------------------------------------------------------
  61.  
  62. local round = function( n )
  63. if n >= 0 then
  64. return math.floor( n + 0.5 )
  65. else
  66. return math.ceil( n - 0.5 )
  67. end
  68. end
  69.  
  70. local on_door_placed = function( pos, node, placer )
  71. if node.name ~= 'moredoors:door_steel' then return end
  72.  
  73. upos = { x = pos.x, y = pos.y - 1, z = pos.z }
  74. apos = { x = pos.x, y = pos.y + 1, z = pos.z }
  75. und = minetest.env:get_node( upos )
  76. abv = minetest.env:get_node( apos )
  77.  
  78. dir = placer:get_look_dir()
  79.  
  80. if round( dir.x ) == 1 then
  81. newparam = WALLMX
  82. elseif round( dir.x ) == -1 then
  83. newparam = WALLPX
  84. elseif round( dir.z ) == 1 then
  85. newparam = WALLMZ
  86. elseif round( dir.z ) == -1 then
  87. newparam = WALLPZ
  88. end
  89.  
  90. if und.name == 'air' then
  91. minetest.env:add_node( pos, { name = 'moredoors:door_steel', param2 = newparam } )
  92. minetest.env:add_node( upos, { name = 'moredoors:door_steel', param2 = newparam } )
  93. elseif abv.name == 'air' then
  94. minetest.env:add_node( pos, { name = 'moredoors:door_steel', param2 = newparam } )
  95. minetest.env:add_node( apos, { name = 'moredoors:door_steel', param2 = newparam } )
  96. else
  97. minetest.env:remove_node( pos )
  98. placer:get_inventory():add_item( "main", 'moredoors:door_steel' )
  99. minetest.chat_send_player( placer:get_player_name(), 'not enough space' )
  100. end
  101. end
  102.  
  103. local on_door_punched = function( pos, node, puncher )
  104. if string.find( node.name, 'moredoors:door_steel' ) == nil then return end
  105.  
  106. upos = { x = pos.x, y = pos.y - 1, z = pos.z }
  107. apos = { x = pos.x, y = pos.y + 1, z = pos.z }
  108.  
  109. if string.find( node.name, '_c', -2 ) ~= nil then
  110. if node.param2 == WALLPX then
  111. newparam = WALLMZ
  112. elseif node.param2 == WALLMZ then
  113. newparam = WALLMX
  114. elseif node.param2 == WALLMX then
  115. newparam = WALLPZ
  116. elseif node.param2 == WALLPZ then
  117. newparam = WALLPX
  118. end
  119. elseif string.find( node.name, '_o', -2 ) ~= nil then
  120. if node.param2 == WALLMZ then
  121. newparam = WALLPX
  122. elseif node.param2 == WALLMX then
  123. newparam = WALLMZ
  124. elseif node.param2 == WALLPZ then
  125. newparam = WALLMX
  126. elseif node.param2 == WALLPX then
  127. newparam = WALLPZ
  128. end
  129. end
  130.  
  131. local round = function( n )
  132. if n >= 0 then
  133. return math.floor( n + 0.5 )
  134. else
  135. return math.ceil( n - 0.5 )
  136. end
  137. end
  138.  
  139. local on_door_placed = function( pos, node, placer )
  140. if node.name ~= 'moredoors:door_cobble' then return end
  141.  
  142. upos = { x = pos.x, y = pos.y - 1, z = pos.z }
  143. apos = { x = pos.x, y = pos.y + 1, z = pos.z }
  144. und = minetest.env:get_node( upos )
  145. abv = minetest.env:get_node( apos )
  146.  
  147. dir = placer:get_look_dir()
  148.  
  149. if round( dir.x ) == 1 then
  150. newparam = WALLMX
  151. elseif round( dir.x ) == -1 then
  152. newparam = WALLPX
  153. elseif round( dir.z ) == 1 then
  154. newparam = WALLMZ
  155. elseif round( dir.z ) == -1 then
  156. newparam = WALLPZ
  157. end
  158.  
  159. if und.name == 'air' then
  160. minetest.env:add_node( pos, { name = 'moredoors:door_cobble', param2 = newparam } )
  161. minetest.env:add_node( upos, { name = 'moredoors:door_cobble', param2 = newparam } )
  162. elseif abv.name == 'air' then
  163. minetest.env:add_node( pos, { name = 'moredoors:door_cobble', param2 = newparam } )
  164. minetest.env:add_node( apos, { name = 'moredoors:door_cobble', param2 = newparam } )
  165. else
  166. minetest.env:remove_node( pos )
  167. placer:get_inventory():add_item( "main", 'moredoors:door_cobble' )
  168. minetest.chat_send_player( placer:get_player_name(), 'not enough space' )
  169. end
  170. end
  171.  
  172. local on_door_punched = function( pos, node, puncher )
  173. if string.find( node.name, 'moredoors:door_cobble' ) == nil then return end
  174.  
  175. upos = { x = pos.x, y = pos.y - 1, z = pos.z }
  176. apos = { x = pos.x, y = pos.y + 1, z = pos.z }
  177.  
  178. if string.find( node.name, '_c', -2 ) ~= nil then
  179. if node.param2 == WALLPX then
  180. newparam = WALLMZ
  181. elseif node.param2 == WALLMZ then
  182. newparam = WALLMX
  183. elseif node.param2 == WALLMX then
  184. newparam = WALLPZ
  185. elseif node.param2 == WALLPZ then
  186. newparam = WALLPX
  187. end
  188. elseif string.find( node.name, '_o', -2 ) ~= nil then
  189. if node.param2 == WALLMZ then
  190. newparam = WALLPX
  191. elseif node.param2 == WALLMX then
  192. newparam = WALLMZ
  193. elseif node.param2 == WALLPZ then
  194. newparam = WALLMX
  195. elseif node.param2 == WALLPX then
  196. newparam = WALLPZ
  197. end
  198. end
  199.  
  200. --------------------------------------------------------------------------------
  201.  
  202. minetest.register_on_placenode( on_door_placed )
  203. minetest.register_on_punchnode( on_door_punched )
  204. minetest.register_on_dignode( on_door_digged )
  205.  
  206. --------------------------------------------------------------------------------
  207. --Print ("moredoors Loaded")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement