Minetest mod that adds scifi themed nodes https://content.minetest.net/packages/D00Med/scifi_nodes/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

396 lines
14KB

  1. -- mydoors mod by don
  2. -- DO WHAT YOU WANT TO PUBLIC LICENSE
  3. -- or abbreviated DWYWPL
  4. -- December 2nd 2015
  5. -- License Copyright (C) 2015 Michael Tomaino (PlatinumArts@gmail.com)
  6. -- www.sandboxgamemaker.com/DWYWPL/
  7. -- DO WHAT YOU WANT TO PUBLIC LICENSE
  8. -- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  9. -- 1. You are allowed to do whatever you want to with what content is using this license.
  10. -- 2. This content is provided 'as-is', without any express or implied warranty. In no event
  11. -- will the authors be held liable for any damages arising from the use of this content.
  12. -- Retrieving mod settings
  13. scifi_nodes.doors_open_with_mesecon_only = minetest.settings:get_bool("scifi_nodes.doors_open_with_mesecon_only", false)
  14. -- Some aliases to deal with old namming policy --
  15. minetest.register_alias("scifi_nodes:door1a","scifi_nodes:Doom_door_closed")
  16. minetest.register_alias("scifi_nodes:door1b","scifi_nodes:Doom_door_closed_top")
  17. minetest.register_alias("scifi_nodes:door1c","scifi_nodes:Doom_door_opened")
  18. minetest.register_alias("scifi_nodes:door1d","scifi_nodes:Doom_door_opened_top")
  19. minetest.register_alias("scifi_nodes:door2a","scifi_nodes:black_door_closed")
  20. minetest.register_alias("scifi_nodes:door2b","scifi_nodes:black_door_closed_top")
  21. minetest.register_alias("scifi_nodes:door2c","scifi_nodes:black_door_opened")
  22. minetest.register_alias("scifi_nodes:door2d","scifi_nodes:black_door_opened_top")
  23. minetest.register_alias("scifi_nodes:door3a","scifi_nodes:white_door_closed")
  24. minetest.register_alias("scifi_nodes:door3b","scifi_nodes:white_door_closed_top")
  25. minetest.register_alias("scifi_nodes:door3c","scifi_nodes:white_door_opened")
  26. minetest.register_alias("scifi_nodes:door3d","scifi_nodes:white_door_opened_top")
  27. minetest.register_alias("scifi_nodes:door4a","scifi_nodes:green_door_closed")
  28. minetest.register_alias("scifi_nodes:door4b","scifi_nodes:green_door_closed_top")
  29. minetest.register_alias("scifi_nodes:door4c","scifi_nodes:green_door_opened")
  30. minetest.register_alias("scifi_nodes:door4d","scifi_nodes:green_door_opened_top")
  31. -- This table now uses named parameters and more convenient variables names
  32. local doors = {
  33. {base_name = "Doom", base_ingredient = "doors:door_obsidian_glass", sound = "scifi_nodes_door_mechanic"},
  34. {base_name = "black", base_ingredient = "doors:door_steel", sound = "scifi_nodes_door_mechanic"},
  35. {base_name = "white", base_ingredient = "doors:door_glass", sound = "scifi_nodes_door_normal"},
  36. {base_name = "green", base_ingredient = "doors:door_wood", sound = "scifi_nodes_door_mechanic"},
  37. {base_name = "blue", base_ingredient = "default:steelblock", sound = "scifi_nodes_door_normal"}
  38. }
  39. for _, current_door in ipairs(doors) do
  40. local closed = "scifi_nodes:"..current_door.base_name.."_door_closed"
  41. local closed_top = "scifi_nodes:"..current_door.base_name.."_door_closed_top"
  42. local opened = "scifi_nodes:"..current_door.base_name.."_door_opened"
  43. local opened_top = "scifi_nodes:"..current_door.base_name.."_door_opened_top"
  44. local base_name = current_door.base_name
  45. local base_ingredient = current_door.base_ingredient
  46. local sound = current_door.sound
  47. minetest.register_craft({
  48. output = closed .. " 2",
  49. recipe = {
  50. {"scifi_nodes:white2", base_ingredient, "scifi_nodes:white2"},
  51. {"scifi_nodes:black", base_ingredient, "scifi_nodes:black"}
  52. }
  53. })
  54. local function onplace(itemstack, placer, pointed_thing)
  55. -- Is there room enough ?
  56. local pos1 = pointed_thing.above
  57. local pos2 = {x=pos1.x, y=pos1.y, z=pos1.z}
  58. pos2.y = pos2.y+1 -- 2 nodes above
  59. if
  60. not minetest.registered_nodes[minetest.get_node(pos1).name].buildable_to or
  61. not minetest.registered_nodes[minetest.get_node(pos2).name].buildable_to or
  62. not placer or
  63. not placer:is_player() or
  64. minetest.is_protected(pos1, placer:get_player_name()) or
  65. minetest.is_protected(pos2, placer:get_player_name()) then
  66. return
  67. end
  68. local pt = pointed_thing.above
  69. local pt2 = {x=pt.x, y=pt.y, z=pt.z}
  70. pt2.y = pt2.y+1
  71. -- Player look dir is converted to node rotation ?
  72. local p2 = minetest.dir_to_facedir(placer:get_look_dir())
  73. -- Where to look for another door ?
  74. local pt3 = {x=pt.x, y=pt.y, z=pt.z}
  75. -- Door param2 depends of placer's look dir
  76. local p4 = 0
  77. if p2 == 0 then
  78. pt3.x = pt3.x-1
  79. p4 = 2
  80. elseif p2 == 1 then
  81. pt3.z = pt3.z+1
  82. p4 = 3
  83. elseif p2 == 2 then
  84. pt3.x = pt3.x+1
  85. p4 = 0
  86. elseif p2 == 3 then
  87. pt3.z = pt3.z-1
  88. p4 = 1
  89. end
  90. -- First door of a pair is already there
  91. if minetest.get_node(pt3).name == closed then
  92. minetest.set_node(pt, {name=closed, param2=p4,})
  93. minetest.set_node(pt2, {name=closed_top, param2=p4})
  94. -- Placed door is the first of a pair
  95. else
  96. minetest.set_node(pt, {name=closed, param2=p2,})
  97. minetest.set_node(pt2, {name=closed_top, param2=p2})
  98. end
  99. itemstack:take_item(1)
  100. return itemstack;
  101. end
  102. local function afterdestruct(pos, oldnode)
  103. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name="air"})
  104. end
  105. local function open_door(pos, node, player, itemstack, pointed_thing)
  106. -- play sound
  107. minetest.sound_play(sound,{
  108. max_hear_distance = 16,
  109. pos = pos,
  110. gain = 1.0
  111. })
  112. local timer = minetest.get_node_timer(pos)
  113. local a = minetest.get_node({x=pos.x, y=pos.y, z=pos.z-1})
  114. local b = minetest.get_node({x=pos.x, y=pos.y, z=pos.z+1})
  115. local c = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z})
  116. local d = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z})
  117. local e = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z-1})
  118. local f = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z-1})
  119. local g = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z+1})
  120. local h = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z+1})
  121. minetest.set_node(pos, {name=opened, param2=node.param2})
  122. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=opened_top, param2=node.param2})
  123. if a.name == closed then
  124. minetest.set_node({x=pos.x, y=pos.y, z=pos.z-1}, {name=opened, param2=a.param2})
  125. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z-1}, {name=opened_top, param2=a.param2})
  126. end
  127. if b.name == closed then
  128. minetest.set_node({x=pos.x, y=pos.y, z=pos.z+1}, {name=opened, param2=b.param2})
  129. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z+1}, {name=opened_top, param2=b.param2})
  130. end
  131. if c.name == closed then
  132. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z}, {name=opened, param2=c.param2})
  133. minetest.set_node({x=pos.x+1,y=pos.y+1,z=pos.z}, {name=opened_top, param2=c.param2})
  134. end
  135. if d.name == closed then
  136. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=opened, param2=d.param2})
  137. minetest.set_node({x=pos.x-1,y=pos.y+1,z=pos.z}, {name=opened_top, param2=d.param2})
  138. end
  139. if e.name == closed then
  140. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z-1}, {name=opened, param2=e.param2})
  141. minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z-1}, {name=opened_top, param2=e.param2})
  142. end
  143. if f.name == closed then
  144. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z-1}, {name=opened, param2=f.param2})
  145. minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z-1}, {name=opened_top, param2=f.param2})
  146. end
  147. if g.name == closed then
  148. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z+1}, {name=opened, param2=g.param2})
  149. minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z+1}, {name=opened_top, param2=g.param2})
  150. end
  151. if h.name == closed then
  152. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z+1}, {name=opened, param2=h.param2})
  153. minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z+1}, {name=opened_top, param2=h.param2})
  154. end
  155. timer:start(3)
  156. end
  157. local function afterplace(pos, placer, itemstack, pointed_thing)
  158. local node = minetest.get_node(pos)
  159. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name=opened_top,param2=node.param2})
  160. end
  161. local 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. local node = minetest.get_node(pos)
  169. local a = minetest.get_node({x=pos.x, y=pos.y, z=pos.z-1})
  170. local b = minetest.get_node({x=pos.x, y=pos.y, z=pos.z+1})
  171. local c = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z})
  172. local d = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z})
  173. local e = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z-1})
  174. local f = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z-1})
  175. local g = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z+1})
  176. local h = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z+1})
  177. minetest.set_node(pos, {name=closed, param2=node.param2})
  178. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=closed_top, param2=node.param2})
  179. if a.name == opened then
  180. minetest.set_node({x=pos.x, y=pos.y, z=pos.z-1}, {name=closed, param2=a.param2})
  181. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z-1}, {name=closed_top, param2=a.param2})
  182. end
  183. if b.name == opened then
  184. minetest.set_node({x=pos.x, y=pos.y, z=pos.z+1}, {name=closed, param2=b.param2})
  185. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z+1}, {name=closed_top, param2=b.param2})
  186. end
  187. if c.name == opened then
  188. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z}, {name=closed, param2=c.param2})
  189. minetest.set_node({x=pos.x+1,y=pos.y+1,z=pos.z}, {name=closed_top, param2=c.param2})
  190. end
  191. if d.name == opened then
  192. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=closed, param2=d.param2})
  193. minetest.set_node({x=pos.x-1,y=pos.y+1,z=pos.z}, {name=closed_top, param2=d.param2})
  194. end
  195. if e.name == opened then
  196. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z-1}, {name=closed, param2=e.param2})
  197. minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z-1}, {name=closed_top, param2=e.param2})
  198. end
  199. if f.name == opened then
  200. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z-1}, {name=closed, param2=f.param2})
  201. minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z-1}, {name=closed_top, param2=f.param2})
  202. end
  203. if g.name == opened then
  204. minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z+1}, {name=closed, param2=g.param2})
  205. minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z+1}, {name=closed_top, param2=g.param2})
  206. end
  207. if h.name == opened then
  208. minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z+1}, {name=closed, param2=h.param2})
  209. minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z+1}, {name=closed_top, param2=h.param2})
  210. end
  211. end
  212. local mesecons_doors_rules = {
  213. -- get signal from pressure plate
  214. {x=-1, y=0, z=0},
  215. {x=0, y=0, z=1},
  216. {x=0, y=0, z=-1},
  217. {x=1, y=0, z=0},
  218. -- get signal from wall mounted button
  219. {x=-1, y=1, z=-1},
  220. {x=-1, y=1, z=1},
  221. {x=0, y=1, z=-1},
  222. {x=0, y=1, z=1},
  223. {x=1, y=1, z=-1},
  224. {x=1, y=1, z=1},
  225. {x=-1, y=1, z=0},
  226. {x=1, y=1, z=0},
  227. }
  228. local mesecons_doors_def = {
  229. effector = {
  230. action_on = open_door,
  231. rules = mesecons_doors_rules
  232. },
  233. }
  234. local function nodig(pos, digger)
  235. return false
  236. end
  237. local doors_rightclick = nil -- Crashes serv if empty table !
  238. if not scifi_nodes.doors_open_with_mesecon_only then doors_rightclick = open_door end
  239. minetest.register_node(closed, {
  240. description = current_door.base_name.." sliding door",
  241. inventory_image = "scifi_nodes_door_"..base_name.."_inv.png",
  242. wield_image = "scifi_nodes_door_"..base_name.."_inv.png",
  243. tiles = {
  244. "scifi_nodes_door_"..base_name.."_edge.png",
  245. "scifi_nodes_door_"..base_name.."_edge.png",
  246. "scifi_nodes_door_"..base_name.."_edge.png",
  247. "scifi_nodes_door_"..base_name.."_edge.png",
  248. "scifi_nodes_door_"..base_name.."_rbottom.png",
  249. "scifi_nodes_door_"..base_name.."_bottom.png"
  250. },
  251. drawtype = "nodebox",
  252. paramtype = "light",
  253. paramtype2 = "facedir",
  254. groups = {cracky = 3, oddly_breakable_by_hand = 1},
  255. node_box = {
  256. type = "fixed",
  257. fixed = {
  258. {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.0625}
  259. }
  260. },
  261. selection_box = {
  262. type = "fixed",
  263. fixed = {
  264. {-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625}
  265. }
  266. },
  267. mesecons = mesecons_doors_def,
  268. on_place = onplace,
  269. after_destruct = afterdestruct,
  270. on_rightclick = doors_rightclick,
  271. })
  272. minetest.register_node(closed_top, {
  273. tiles = {
  274. "scifi_nodes_door_"..base_name.."_edge.png",
  275. "scifi_nodes_door_"..base_name.."_edge.png",
  276. "scifi_nodes_door_"..base_name.."_edge.png",
  277. "scifi_nodes_door_"..base_name.."_edge.png",
  278. "scifi_nodes_door_"..base_name.."_rtop.png",
  279. "scifi_nodes_door_"..base_name.."_top.png"
  280. },
  281. drawtype = "nodebox",
  282. paramtype = "light",
  283. paramtype2 = "facedir",
  284. groups = {cracky = 1},
  285. node_box = {
  286. type = "fixed",
  287. fixed = {
  288. {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.0625}
  289. }
  290. },
  291. selection_box = {
  292. type = "fixed",
  293. fixed = {
  294. {0, 0, 0, 0, 0, 0},
  295. }
  296. },
  297. can_dig = nodig,
  298. })
  299. minetest.register_node(opened, {
  300. tiles = {
  301. "scifi_nodes_door_"..base_name.."_edge.png",
  302. "scifi_nodes_door_"..base_name.."_edge.png",
  303. "scifi_nodes_door_"..base_name.."_edge.png",
  304. "scifi_nodes_door_"..base_name.."_edge.png",
  305. "scifi_nodes_door_"..base_name.."_rbottom0.png",
  306. "scifi_nodes_door_"..base_name.."_bottom0.png"
  307. },
  308. drawtype = "nodebox",
  309. paramtype = "light",
  310. paramtype2 = "facedir",
  311. drop = closed,
  312. groups = {cracky = 1},
  313. node_box = {
  314. type = "fixed",
  315. fixed = {
  316. {-0.5, -0.5, -0.0625, -0.25, 0.5, 0.0625},
  317. }
  318. },
  319. selection_box = {
  320. type = "fixed",
  321. fixed = {
  322. {-0.5, -0.5, -0.0625, -0.25, 1.5, 0.0625},
  323. }
  324. },
  325. after_place_node = afterplace,
  326. after_destruct = afterdestruct,
  327. on_timer = ontimer,
  328. })
  329. minetest.register_node(opened_top, {
  330. tiles = {
  331. "scifi_nodes_door_"..base_name.."_edge.png",
  332. "scifi_nodes_door_"..base_name.."_edge.png",
  333. "scifi_nodes_door_"..base_name.."_edge.png",
  334. "scifi_nodes_door_"..base_name.."_edge.png",
  335. "scifi_nodes_door_"..base_name.."_rtopo.png",
  336. "scifi_nodes_door_"..base_name.."_topo.png"
  337. },
  338. drawtype = "nodebox",
  339. paramtype = "light",
  340. paramtype2 = "facedir",
  341. groups = {cracky = 1},
  342. node_box = {
  343. type = "fixed",
  344. fixed = {
  345. {-0.5, -0.5, -0.0625, -0.25, 0.5, 0.0625},
  346. }
  347. },
  348. selection_box = {
  349. type = "fixed",
  350. fixed = {
  351. {0, 0, 0, 0, 0, 0},
  352. }
  353. },
  354. can_dig = nodig,
  355. })
  356. end -- end of doors table browsing