Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.67 KB | None | 0 0
  1. -- mydoors mod by don
  2. -- DO WHAT YOU WANT TO PUBLIC LICENSE
  3. -- or abbreviated DWYWPL
  4.  
  5. -- December 2nd 2015
  6. -- License Copyright (C) 2015 Michael Tomaino (PlatinumArts@gmail.com)
  7. -- www.sandboxgamemaker.com/DWYWPL/
  8.  
  9. -- DO WHAT YOU WANT TO PUBLIC LICENSE
  10. -- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  11.  
  12. -- 1. You are allowed to do whatever you want to with what content is using this license.
  13. -- 2. This content is provided 'as-is', without any express or implied warranty. In no event
  14. -- will the authors be held liable for any damages arising from the use of this content.
  15.  
  16.  
  17. -- This table now uses named parameters and more convenient variables names
  18. local doors = {
  19. -- DOOM door {closed, closed top, opened, opened top, texture number, main ingredient, sound}
  20. {base_name = "Doom", base_ingredient = "doors:door_obsidian_glass", sound = "scifi_nodes_door_mechanic"},
  21. -- Black door
  22. {base_name = "black", base_ingredient = "doors:door_steel", sound = "scifi_nodes_door_mechanic"},
  23. -- White door
  24. {base_name = "white", base_ingredient = "doors:door_glass", sound = "scifi_nodes_door_normal"},
  25. -- Green door
  26. {base_name = "green", base_ingredient = "doors:door_wood", sound = "scifi_nodes_door_mechanic"},
  27. {base_name = "blue", base_ingredient = "default:steel_block", sound = "scifi_nodes_door_normal"}
  28. }
  29.  
  30. for _, current_door in ipairs(doors) do
  31.  
  32. local closed = "scifi_nodes:"..current_door.base_name.."_door_closed"
  33. local closed_top = "scifi_nodes:"..current_door.base_name.."_door_closed_top"
  34. local opened = "scifi_nodes:"..current_door.base_name.."_door_opened"
  35. local opened_top = "scifi_nodes:"..current_door.base_name.."_door_opened_top"
  36. local base_name = current_door.base_name
  37. local base_ingredient = current_door.base_ingredient
  38. local sound = current_door.sound
  39.  
  40. minetest.register_craft({
  41. output = closed .. " 2",
  42. recipe = {
  43. {"scifi_nodes:white2", base_ingredient, "scifi_nodes:white2"},
  44. {"scifi_nodes:black", base_ingredient, "scifi_nodes:black"}
  45. }
  46. })
  47.  
  48.  
  49. function onplace(itemstack, placer, pointed_thing)
  50. local pos1 = pointed_thing.above
  51. local pos2 = {x=pos1.x, y=pos1.y, z=pos1.z}
  52. pos2.y = pos2.y+1
  53. if
  54.  
  55. not minetest.registered_nodes[minetest.get_node(pos1).name].buildable_to or
  56. not minetest.registered_nodes[minetest.get_node(pos2).name].buildable_to or
  57. not placer or
  58. not placer:is_player() or
  59. minetest.is_protected(pos1, placer:get_player_name()) or
  60. minetest.is_protected(pos2, placer:get_player_name()) then
  61. return
  62. end
  63. local pt = pointed_thing.above
  64. local pt2 = {x=pt.x, y=pt.y, z=pt.z}
  65. pt2.y = pt2.y+1
  66. local p2 = minetest.dir_to_facedir(placer:get_look_dir())
  67. local pt3 = {x=pt.x, y=pt.y, z=pt.z}
  68. local p4 = 0
  69. if p2 == 0 then
  70. pt3.x = pt3.x-1
  71. p4 = 2
  72. elseif p2 == 1 then
  73. pt3.z = pt3.z+1
  74. p4 = 3
  75. elseif p2 == 2 then
  76. pt3.x = pt3.x+1
  77. p4 = 0
  78. elseif p2 == 3 then
  79. pt3.z = pt3.z-1
  80. p4 = 1
  81. end
  82. if minetest.get_node(pt3).name == closed then
  83. minetest.set_node(pt, {name=closed, param2=p4})
  84. minetest.set_node(pt2, {name=closed_top, param2=p4})
  85. else
  86. minetest.set_node(pt, {name=closed, param2=p2})
  87. minetest.set_node(pt2, {name=closed_top, param2=p2})
  88. end
  89. itemstack:take_item(1)
  90.  
  91. return itemstack;
  92. end
  93.  
  94. function afterdestruct(pos, oldnode)
  95. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name="air"})
  96. end
  97.  
  98. function rightclick(pos, node, player, itemstack, pointed_thing)
  99. -- play sound
  100. minetest.sound_play(sound,{
  101. max_hear_distance = 16,
  102. pos = pos,
  103. gain = 1.0
  104. })
  105.  
  106. local timer = minetest.get_node_timer(pos)
  107. local a = minetest.get_node({x=pos.x, y=pos.y, z=pos.z-1})
  108. local b = minetest.get_node({x=pos.x, y=pos.y, z=pos.z+1})
  109. local c = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z})
  110. local d = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z})
  111. local e = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z-1})
  112. local f = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z-1})
  113. local g = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z+1})
  114. local h = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z+1})
  115.  
  116.  
  117. minetest.set_node(pos, {name=opened, param2=node.param2})
  118. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=opened_top, param2=node.param2})
  119.  
  120. if a.name == closed then
  121. minetest.set_node({x=pos.x, y=pos.y, z=pos.z-1}, {name=opened, param2=a.param2})
  122. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z-1}, {name=opened_top, param2=a.param2})
  123. end
  124. if b.name == closed then
  125. minetest.set_node({x=pos.x, y=pos.y, z=pos.z+1}, {name=opened, param2=b.param2})
  126. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z+1}, {name=opened_top, param2=b.param2})
  127. end
  128. if c.name == closed then
  129. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z}, {name=opened, param2=c.param2})
  130. minetest.set_node({x=pos.x+1,y=pos.y+1,z=pos.z}, {name=opened_top, param2=c.param2})
  131. end
  132. if d.name == closed then
  133. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=opened, param2=d.param2})
  134. minetest.set_node({x=pos.x-1,y=pos.y+1,z=pos.z}, {name=opened_top, param2=d.param2})
  135. end
  136. if e.name == closed then
  137. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z-1}, {name=opened, param2=e.param2})
  138. minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z-1}, {name=opened_top, param2=e.param2})
  139. end
  140. if f.name == closed then
  141. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z-1}, {name=opened, param2=f.param2})
  142. minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z-1}, {name=opened_top, param2=f.param2})
  143. end
  144. if g.name == closed then
  145. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z+1}, {name=opened, param2=g.param2})
  146. minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z+1}, {name=opened_top, param2=g.param2})
  147. end
  148. if h.name == closed then
  149. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z+1}, {name=opened, param2=h.param2})
  150. minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z+1}, {name=opened_top, param2=h.param2})
  151. end
  152.  
  153. timer:start(3)
  154.  
  155. end
  156.  
  157. function afterplace(pos, placer, itemstack, pointed_thing)
  158. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name=opened_top,param2=nodeu.param2})
  159. end
  160.  
  161. function ontimer(pos, elapsed)
  162. -- play sound
  163. minetest.sound_play(sound,{
  164. max_hear_distance = 16,
  165. pos = pos,
  166. gain = 1.0
  167. })
  168.  
  169. local node = minetest.get_node(pos)
  170. local a = minetest.get_node({x=pos.x, y=pos.y, z=pos.z-1})
  171. local b = minetest.get_node({x=pos.x, y=pos.y, z=pos.z+1})
  172. local c = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z})
  173. local d = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z})
  174. local e = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z-1})
  175. local f = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z-1})
  176. local g = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z+1})
  177. local h = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z+1})
  178.  
  179.  
  180. minetest.set_node(pos, {name=closed, param2=node.param2})
  181. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=closed_top, param2=node.param2})
  182.  
  183. if a.name == opened then
  184. minetest.set_node({x=pos.x, y=pos.y, z=pos.z-1}, {name=closed, param2=a.param2})
  185. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z-1}, {name=closed_top, param2=a.param2})
  186. end
  187. if b.name == opened then
  188. minetest.set_node({x=pos.x, y=pos.y, z=pos.z+1}, {name=closed, param2=b.param2})
  189. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z+1}, {name=closed_top, param2=b.param2})
  190. end
  191. if c.name == opened then
  192. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z}, {name=closed, param2=c.param2})
  193. minetest.set_node({x=pos.x+1,y=pos.y+1,z=pos.z}, {name=closed_top, param2=c.param2})
  194. end
  195. if d.name == opened then
  196. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=closed, param2=d.param2})
  197. minetest.set_node({x=pos.x-1,y=pos.y+1,z=pos.z}, {name=closed_top, param2=d.param2})
  198. end
  199. if e.name == opened then
  200. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z-1}, {name=closed, param2=e.param2})
  201. minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z-1}, {name=closed_top, param2=e.param2})
  202. end
  203. if f.name == opened then
  204. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z-1}, {name=closed, param2=f.param2})
  205. minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z-1}, {name=closed_top, param2=f.param2})
  206. end
  207. if g.name == opened then
  208. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z+1}, {name=closed, param2=g.param2})
  209. minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z+1}, {name=closed_top, param2=g.param2})
  210. end
  211. if h.name == opened then
  212. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z+1}, {name=closed, param2=h.param2})
  213. minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z+1}, {name=closed_top, param2=h.param2})
  214. end
  215.  
  216. end
  217.  
  218. -- allow doors opening on mesecon signal
  219. -- from a pressure plate
  220. local mesecons_door_def
  221. local mesecons_door_top_def
  222. local mesecons_door_rules
  223. local mesecons_door_top_rules
  224. if minetest.get_modpath("mesecons") then
  225. mesecons_door_rules = {
  226. -- get signal from pressure plate
  227. {x=1, y=0, z=0},
  228. {x=-1, y=0, z=0},
  229. {x=0, y=0, z=1},
  230. {x=0, y=0, z=-1},
  231. -- get signal from wall mounted button
  232. {x=1, y=1, z=1},
  233. {x=-1, y=1, z=1},
  234. {x=1, y=1, z=-1},
  235. {x=-1, y=1, z=-1},
  236. }
  237. mesecons_door_def = {
  238. effector = {
  239. action_on = rightclick
  240. },
  241. rules = mesecons_door_rules
  242. }
  243. mesecons_door_top_rules = {
  244. -- get signal switch or digicode
  245. {x=1, y=0, z=1},
  246. {x=-1, y=0, z=1},
  247. {x=1, y=0, z=1},
  248. {x=-1, y=0, z=-1},
  249. -- get signal from door_bottom
  250. {x=0, y=-1, z=0},
  251. }
  252. mesecons_door_top_def = {
  253. conductor = {
  254. rules = mesecons_door_top_rules
  255. }
  256. }
  257. end
  258.  
  259. minetest.register_node(closed, {
  260. description = current_door.base_name.." sliding door",
  261. inventory_image = "scifi_nodes_door_"..base_name.."_inv.png",
  262. wield_image = "scifi_nodes_door_"..base_name.."_inv.png",
  263. tiles = {
  264. "scifi_nodes_door_"..base_name.."_edge.png",
  265. "scifi_nodes_door_"..base_name.."_edge.png",
  266. "scifi_nodes_door_"..base_name.."_edge.png",
  267. "scifi_nodes_door_"..base_name.."_edge.png",
  268. "scifi_nodes_door_"..base_name.."_rbottom.png",
  269. "scifi_nodes_door_"..base_name.."_bottom.png"
  270. },
  271. drawtype = "nodebox",
  272. paramtype = "light",
  273. paramtype2 = "facedir",
  274. groups = {cracky = 3},
  275. node_box = {
  276. type = "fixed",
  277. fixed = {
  278. {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.0625}
  279. }
  280. },
  281. selection_box = {
  282. type = "fixed",
  283. fixed = {
  284. {-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625}
  285. }
  286. },
  287. mesecons = mesecons_door_def,
  288.  
  289. on_place = onplace,
  290.  
  291. after_destruct = afterdestruct,
  292.  
  293. on_rightclick = rightclick,
  294. })
  295.  
  296. minetest.register_node(closed_top, {
  297. tiles = {
  298. "scifi_nodes_door_"..base_name.."_edge.png",
  299. "scifi_nodes_door_"..base_name.."_edge.png",
  300. "scifi_nodes_door_"..base_name.."_edge.png",
  301. "scifi_nodes_door_"..base_name.."_edge.png",
  302. "scifi_nodes_door_"..base_name.."_rtop.png",
  303. "scifi_nodes_door_"..base_name.."_top.png"
  304. },
  305. drawtype = "nodebox",
  306. paramtype = "light",
  307. paramtype2 = "facedir",
  308. groups = {cracky = 1},
  309. node_box = {
  310. type = "fixed",
  311. fixed = {
  312. {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.0625}
  313. }
  314. },
  315. selection_box = {
  316. type = "fixed",
  317. fixed = {
  318. {0, 0, 0, 0, 0, 0},
  319. }
  320. },
  321. mesecons = mesecons_door_top_def,
  322. })
  323.  
  324. minetest.register_node(opened, {
  325. tiles = {
  326. "scifi_nodes_door_"..base_name.."_edge.png",
  327. "scifi_nodes_door_"..base_name.."_edge.png",
  328. "scifi_nodes_door_"..base_name.."_edge.png",
  329. "scifi_nodes_door_"..base_name.."_edge.png",
  330. "scifi_nodes_door_"..base_name.."_rbottom0.png",
  331. "scifi_nodes_door_"..base_name.."_bottom0.png"
  332. },
  333. drawtype = "nodebox",
  334. paramtype = "light",
  335. paramtype2 = "facedir",
  336. drop = closed,
  337. groups = {cracky = 1},
  338. node_box = {
  339. type = "fixed",
  340. fixed = {
  341. {-0.5, -0.5, -0.0625, -0.25, 0.5, 0.0625},
  342. }
  343. },
  344. selection_box = {
  345. type = "fixed",
  346. fixed = {
  347. {-0.5, -0.5, -0.0625, -0.25, 1.5, 0.0625},
  348. }
  349. },
  350. after_place_node = afterplace,
  351. after_destruct = afterdestruct,
  352. on_timer = ontimer,
  353. })
  354.  
  355. minetest.register_node(opened_top, {
  356. tiles = {
  357. "scifi_nodes_door_"..base_name.."_edge.png",
  358. "scifi_nodes_door_"..base_name.."_edge.png",
  359. "scifi_nodes_door_"..base_name.."_edge.png",
  360. "scifi_nodes_door_"..base_name.."_edge.png",
  361. "scifi_nodes_door_"..base_name.."_rtopo.png",
  362. "scifi_nodes_door_"..base_name.."_topo.png"
  363. },
  364. drawtype = "nodebox",
  365. paramtype = "light",
  366. paramtype2 = "facedir",
  367. groups = {cracky = 1},
  368. node_box = {
  369. type = "fixed",
  370. fixed = {
  371. {-0.5, -0.5, -0.0625, -0.25, 0.5, 0.0625},
  372. }
  373. },
  374. selection_box = {
  375. type = "fixed",
  376. fixed = {
  377. {0, 0, 0, 0, 0, 0},
  378. }
  379. },
  380. })
  381. end -- end of doors table browsing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement