sliding.lua 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. local doors = {
  2. {"my_future_doors:door2a","my_future_doors:door2b","my_future_doors:door2c","my_future_doors:door2d","2","Steel"},
  3. {"my_future_doors:door3a","my_future_doors:door3b","my_future_doors:door3c","my_future_doors:door3d","3","Squared"},
  4. {"my_future_doors:door4a","my_future_doors:door4b","my_future_doors:door4c","my_future_doors:door4d","4","Dark"},
  5. {"my_future_doors:door6a","my_future_doors:door6b","my_future_doors:door6c","my_future_doors:door6d","6","Points"},
  6. {"my_future_doors:door7a","my_future_doors:door7b","my_future_doors:door7c","my_future_doors:door7d","7","Snow Flake"},
  7. {"my_future_doors:door8a","my_future_doors:door8b","my_future_doors:door8c","my_future_doors:door8d","8","Blue Steel"},
  8. {"my_future_doors:door9a","my_future_doors:door9b","my_future_doors:door9c","my_future_doors:door9d","9","Tan Steel"},
  9. }
  10. local recipes = {
  11. {{"default:steel_ingot", "default:steelblock", ""},
  12. {"default:steel_ingot", "default:steel_ingot", ""},
  13. {"default:steelblock", "default:steel_ingot", ""}},
  14. {{"default:steel_ingot","default:steel_ingot", ""},
  15. {"default:steel_ingot", "default:steel_ingot", ""},
  16. {"default:steelblock", "default:steelblock", ""}},
  17. {{"default:steel_ingot","default:steel_ingot", ""},
  18. {"default:steel_ingot", "default:steel_ingot", "dye:black"},
  19. {"default:steelblock", "default:steelblock", ""}},
  20. {{"default:steel_ingot","default:steel_ingot", ""},
  21. {"default:steelblock", "default:steelblock", ""},
  22. {"default:steel_ingot", "default:steel_ingot", ""}},
  23. {{"default:steel_ingot", "default:steelblock", ""},
  24. {"default:steel_ingot", "default:steel_ingot", ""},
  25. { "default:steel_ingot", "default:steelblock",""}},
  26. {{"default:steel_ingot", "default:steelblock", ""},
  27. {"default:steel_ingot", "default:steel_ingot", "dye:blue"},
  28. { "default:steel_ingot", "default:steelblock",""}},
  29. {{"default:steel_ingot", "default:steelblock", ""},
  30. {"default:steel_ingot", "default:steel_ingot", "dye:brown"},
  31. { "default:steel_ingot", "default:steelblock",""}},
  32. }
  33. for i in ipairs (doors) do
  34. local doora = doors[i][1]
  35. local doorb = doors[i][2]
  36. local doorc = doors[i][3]
  37. local doord = doors[i][4]
  38. local num = doors[i][5]
  39. local des = doors[i][6]
  40. local recipe = recipes[i]
  41. local function onplace(itemstack, placer, pointed_thing)
  42. local pos1 = pointed_thing.above
  43. local pos2 = {x=pos1.x, y=pos1.y, z=pos1.z}
  44. pos2.y = pos2.y+1
  45. if
  46. not minetest.registered_nodes[minetest.get_node(pos1).name].buildable_to or
  47. not minetest.registered_nodes[minetest.get_node(pos2).name].buildable_to or
  48. not placer or
  49. not placer:is_player() then
  50. return
  51. end
  52. local pt = pointed_thing.above
  53. local pt2 = {x=pt.x, y=pt.y, z=pt.z}
  54. pt2.y = pt2.y+1
  55. local p2 = minetest.dir_to_facedir(placer:get_look_dir())
  56. local pt3 = {x=pt.x, y=pt.y, z=pt.z}
  57. local p4 = 0
  58. if p2 == 0 then
  59. pt3.x = pt3.x-1
  60. p4 = 2
  61. elseif p2 == 1 then
  62. pt3.z = pt3.z+1
  63. p4 = 3
  64. elseif p2 == 2 then
  65. pt3.x = pt3.x+1
  66. p4 = 0
  67. elseif p2 == 3 then
  68. pt3.z = pt3.z-1
  69. p4 = 1
  70. end
  71. if minetest.get_node(pt3).name == doora then
  72. minetest.set_node(pt, {name=doora, param2=p4})
  73. minetest.set_node(pt2, {name=doorb, param2=p4})
  74. else
  75. minetest.set_node(pt, {name=doora, param2=p2})
  76. minetest.set_node(pt2, {name=doorb, param2=p2})
  77. end
  78. itemstack: take_item()
  79. return itemstack
  80. end
  81. local function afterdestruct(pos, oldnode)
  82. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name="air"})
  83. end
  84. local function rightclick(pos, node, player, itemstack, pointed_thing)
  85. local timer = minetest.get_node_timer(pos)
  86. local a = minetest.get_node({x=pos.x, y=pos.y, z=pos.z-1})
  87. local b = minetest.get_node({x=pos.x, y=pos.y, z=pos.z+1})
  88. local c = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z})
  89. local d = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z})
  90. minetest.set_node(pos, {name=doorc, param2=node.param2})
  91. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=doord, param2=node.param2})
  92. if a.name == doora then
  93. minetest.set_node({x=pos.x, y=pos.y, z=pos.z-1}, {name=doorc, param2=a.param2})
  94. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z-1}, {name=doord, param2=a.param2})
  95. end
  96. if b.name == doora then
  97. minetest.set_node({x=pos.x, y=pos.y, z=pos.z+1}, {name=doorc, param2=b.param2})
  98. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z+1}, {name=doord, param2=b.param2})
  99. end
  100. if c.name == doora then
  101. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z}, {name=doorc, param2=c.param2})
  102. minetest.set_node({x=pos.x+1,y=pos.y+1,z=pos.z}, {name=doord, param2=c.param2})
  103. end
  104. if d.name == doora then
  105. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=doorc, param2=d.param2})
  106. minetest.set_node({x=pos.x-1,y=pos.y+1,z=pos.z}, {name=doord, param2=d.param2})
  107. end
  108. timer:start(3)
  109. end
  110. local function afterplace(pos, placer, itemstack, pointed_thing)
  111. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name=doord,param2=nodeu.param2})
  112. end
  113. local function ontimer(pos, elapsed)
  114. local node = minetest.get_node(pos)
  115. local a = minetest.get_node({x=pos.x, y=pos.y, z=pos.z-1})
  116. local b = minetest.get_node({x=pos.x, y=pos.y, z=pos.z+1})
  117. local c = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z})
  118. local d = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z})
  119. minetest.set_node(pos, {name=doora, param2=node.param2})
  120. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=doorb, param2=node.param2})
  121. if a.name == doorc then
  122. minetest.set_node({x=pos.x, y=pos.y, z=pos.z-1}, {name=doora, param2=a.param2})
  123. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z-1}, {name=doorb, param2=a.param2})
  124. end
  125. if b.name == doorc then
  126. minetest.set_node({x=pos.x, y=pos.y, z=pos.z+1}, {name=doora, param2=b.param2})
  127. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z+1}, {name=doorb, param2=b.param2})
  128. end
  129. if c.name == doorc then
  130. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z}, {name=doora, param2=c.param2})
  131. minetest.set_node({x=pos.x+1,y=pos.y+1,z=pos.z}, {name=doorb, param2=c.param2})
  132. end
  133. if d.name == doorc then
  134. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=doora, param2=d.param2})
  135. minetest.set_node({x=pos.x-1,y=pos.y+1,z=pos.z}, {name=doorb, param2=d.param2})
  136. end
  137. end
  138. minetest.register_node(doora, {
  139. description = des.." Sliding Door",
  140. inventory_image = "myndoors_door"..num.."a_inv.png",
  141. wield_image = "myndoors_door"..num.."a_inv.png",
  142. tiles = {
  143. "myndoors_door"..num.."a_edge.png",
  144. "myndoors_door"..num.."a_edge.png",
  145. "myndoors_door"..num.."a_edge.png",
  146. "myndoors_door"..num.."a_edge.png",
  147. "myndoors_door"..num.."a_bottom.png",
  148. "myndoors_door"..num.."a_bottom.png^[transformFX"
  149. },
  150. drawtype = "nodebox",
  151. paramtype = "light",
  152. paramtype2 = "facedir",
  153. groups = {cracky = 3},
  154. node_box = {
  155. type = "fixed",
  156. fixed = {
  157. {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.0625}
  158. }
  159. },
  160. selection_box = {
  161. type = "fixed",
  162. fixed = {
  163. {-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625}
  164. }
  165. },
  166. on_place = onplace,
  167. after_destruct = afterdestruct,
  168. on_rightclick = rightclick,
  169. })
  170. minetest.register_node(doorb, {
  171. tiles = {
  172. "myndoors_door"..num.."a_edge.png",
  173. "myndoors_door"..num.."a_edge.png",
  174. "myndoors_door"..num.."a_edge.png",
  175. "myndoors_door"..num.."a_edge.png",
  176. "myndoors_door"..num.."a_bottom.png^[transformFY",
  177. "myndoors_door"..num.."a_bottom.png^[transformFX^[transformFY"
  178. },
  179. drawtype = "nodebox",
  180. paramtype = "light",
  181. paramtype2 = "facedir",
  182. groups = {cracky = 1},
  183. node_box = {
  184. type = "fixed",
  185. fixed = {
  186. {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.0625}
  187. }
  188. },
  189. selection_box = {
  190. type = "fixed",
  191. fixed = {
  192. {0, 0, 0, 0, 0, 0},
  193. }
  194. },
  195. })minetest.register_node(doorc, {
  196. tiles = {
  197. "myndoors_door"..num.."a_edge.png",
  198. "myndoors_door"..num.."a_edge.png",
  199. "myndoors_door"..num.."a_edge.png",
  200. "myndoors_door"..num.."a_edge.png",
  201. "myndoors_door"..num.."a_bottomo.png",
  202. "myndoors_door"..num.."a_bottomo.png^[transformFX"
  203. },
  204. drawtype = "nodebox",
  205. paramtype = "light",
  206. paramtype2 = "facedir",
  207. drop = doora,
  208. groups = {cracky = 1},
  209. node_box = {
  210. type = "fixed",
  211. fixed = {
  212. {-0.5, -0.5, -0.0625, -0.25, 0.5, 0.0625},
  213. }
  214. },
  215. selection_box = {
  216. type = "fixed",
  217. fixed = {
  218. {-0.5, -0.5, -0.0625, -0.25, 1.5, 0.0625},
  219. }
  220. },
  221. after_place_node = afterplace,
  222. after_destruct = afterdestruct,
  223. on_timer = ontimer,
  224. })
  225. minetest.register_node(doord, {
  226. tiles = {
  227. "myndoors_door"..num.."a_edge.png",
  228. "myndoors_door"..num.."a_edge.png",
  229. "myndoors_door"..num.."a_edge.png",
  230. "myndoors_door"..num.."a_edge.png",
  231. "myndoors_door"..num.."a_bottomo.png^[transformFY",
  232. "myndoors_door"..num.."a_bottomo.png^[transformFX^[transformFY"
  233. },
  234. drawtype = "nodebox",
  235. paramtype = "light",
  236. paramtype2 = "facedir",
  237. groups = {cracky = 1},
  238. node_box = {
  239. type = "fixed",
  240. fixed = {
  241. {-0.5, -0.5, -0.0625, -0.25, 0.5, 0.0625},
  242. }
  243. },
  244. selection_box = {
  245. type = "fixed",
  246. fixed = {
  247. {0, 0, 0, 0, 0, 0},
  248. }
  249. },
  250. })
  251. minetest.register_craft({
  252. output = "my_future_doors:door"..num.."a 2",
  253. recipe = recipe
  254. })
  255. end