Minetest mod that adds scifi themed 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.
 
 
 

349 lines
10 KiB

  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_normal"},
  34. {base_name = "black", base_ingredient = "doors:door_steel", sound = "scifi_nodes_door_normal"},
  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_normal"},
  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 change_adjacent(target, pos, node)
  106. local target_opposite, target_top
  107. if target == opened then
  108. target_top = opened_top
  109. target_opposite = closed
  110. else
  111. target_top = closed_top
  112. target_opposite = opened
  113. end
  114. for offset = -1,1,2 do
  115. local x = pos.x
  116. local y = pos.y
  117. local z = pos.z
  118. -- match param2=0 or param2=2
  119. if node.param2 % 2 == 0 then
  120. x = x + offset
  121. else
  122. z = z + offset
  123. end
  124. local adjacent = minetest.get_node({x=x, y=y, z=z})
  125. if adjacent.name == target_opposite then
  126. minetest.set_node({x=x, y=y, z=z}, {name=target, param2 = adjacent.param2})
  127. minetest.set_node({x=x, y=y+1, z=z}, {name=target_top, param2 = adjacent.param2})
  128. end
  129. end
  130. end
  131. local function open_door(pos, node, player, itemstack, pointed_thing)
  132. -- play sound
  133. minetest.sound_play(sound,{
  134. max_hear_distance = 16,
  135. pos = pos,
  136. gain = 1.0
  137. })
  138. local timer = minetest.get_node_timer(pos)
  139. minetest.set_node(pos, {name=opened, param2=node.param2})
  140. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=opened_top, param2=node.param2})
  141. change_adjacent(opened, pos, node)
  142. timer:start(3)
  143. end
  144. local function afterplace(pos, placer, itemstack, pointed_thing)
  145. local node = minetest.get_node(pos)
  146. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name=opened_top,param2=node.param2})
  147. end
  148. local function ontimer(pos, elapsed)
  149. -- play sound
  150. minetest.sound_play(sound,{
  151. max_hear_distance = 16,
  152. pos = pos,
  153. gain = 1.0
  154. })
  155. local node = minetest.get_node(pos)
  156. minetest.set_node(pos, {name=closed, param2=node.param2})
  157. minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=closed_top, param2=node.param2})
  158. change_adjacent(closed, pos, node)
  159. end
  160. local mesecons_doors_rules = {
  161. -- get signal from pressure plate
  162. {x=-1, y=0, z=0},
  163. {x=0, y=0, z=1},
  164. {x=0, y=0, z=-1},
  165. {x=1, y=0, z=0},
  166. -- get signal from wall mounted button
  167. {x=-1, y=1, z=-1},
  168. {x=-1, y=1, z=1},
  169. {x=0, y=1, z=-1},
  170. {x=0, y=1, z=1},
  171. {x=1, y=1, z=-1},
  172. {x=1, y=1, z=1},
  173. {x=-1, y=1, z=0},
  174. {x=1, y=1, z=0},
  175. }
  176. local mesecons_doors_def = {
  177. effector = {
  178. action_on = open_door,
  179. rules = mesecons_doors_rules
  180. },
  181. }
  182. local function nodig(pos, digger)
  183. return false
  184. end
  185. local doors_rightclick = nil -- Crashes serv if empty table !
  186. if not scifi_nodes.doors_open_with_mesecon_only then doors_rightclick = open_door end
  187. minetest.register_node(closed, {
  188. description = current_door.base_name.." sliding door",
  189. inventory_image = "scifi_nodes_door_"..base_name.."_inv.png",
  190. wield_image = "scifi_nodes_door_"..base_name.."_inv.png",
  191. tiles = {
  192. "scifi_nodes_door_"..base_name.."_edge.png",
  193. "scifi_nodes_door_"..base_name.."_edge.png",
  194. "scifi_nodes_door_"..base_name.."_edge.png",
  195. "scifi_nodes_door_"..base_name.."_edge.png",
  196. "scifi_nodes_door_"..base_name.."_rbottom.png",
  197. "scifi_nodes_door_"..base_name.."_bottom.png"
  198. },
  199. drawtype = "nodebox",
  200. paramtype = "light",
  201. paramtype2 = "facedir",
  202. groups = {cracky = 3, oddly_breakable_by_hand = 1},
  203. node_box = {
  204. type = "fixed",
  205. fixed = {
  206. {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.0625}
  207. }
  208. },
  209. selection_box = {
  210. type = "fixed",
  211. fixed = {
  212. {-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625}
  213. }
  214. },
  215. mesecons = mesecons_doors_def,
  216. on_place = onplace,
  217. after_destruct = afterdestruct,
  218. on_rightclick = doors_rightclick,
  219. })
  220. minetest.register_node(closed_top, {
  221. tiles = {
  222. "scifi_nodes_door_"..base_name.."_edge.png",
  223. "scifi_nodes_door_"..base_name.."_edge.png",
  224. "scifi_nodes_door_"..base_name.."_edge.png",
  225. "scifi_nodes_door_"..base_name.."_edge.png",
  226. "scifi_nodes_door_"..base_name.."_rtop.png",
  227. "scifi_nodes_door_"..base_name.."_top.png"
  228. },
  229. drawtype = "nodebox",
  230. paramtype = "light",
  231. paramtype2 = "facedir",
  232. groups = {cracky = 1},
  233. node_box = {
  234. type = "fixed",
  235. fixed = {
  236. {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.0625}
  237. }
  238. },
  239. selection_box = {
  240. type = "fixed",
  241. fixed = {
  242. {0, 0, 0, 0, 0, 0},
  243. }
  244. },
  245. can_dig = nodig,
  246. })
  247. minetest.register_node(opened, {
  248. tiles = {
  249. "scifi_nodes_door_"..base_name.."_edge.png",
  250. "scifi_nodes_door_"..base_name.."_edge.png",
  251. "scifi_nodes_door_"..base_name.."_edge.png",
  252. "scifi_nodes_door_"..base_name.."_edge.png",
  253. "scifi_nodes_door_"..base_name.."_rbottom0.png",
  254. "scifi_nodes_door_"..base_name.."_bottom0.png"
  255. },
  256. drawtype = "nodebox",
  257. paramtype = "light",
  258. paramtype2 = "facedir",
  259. drop = closed,
  260. groups = {cracky = 1},
  261. node_box = {
  262. type = "fixed",
  263. fixed = {
  264. {-0.5, -0.5, -0.0625, -0.25, 0.5, 0.0625},
  265. }
  266. },
  267. selection_box = {
  268. type = "fixed",
  269. fixed = {
  270. {-0.5, -0.5, -0.0625, -0.25, 1.5, 0.0625},
  271. }
  272. },
  273. after_place_node = afterplace,
  274. after_destruct = afterdestruct,
  275. on_timer = ontimer,
  276. })
  277. minetest.register_node(opened_top, {
  278. tiles = {
  279. "scifi_nodes_door_"..base_name.."_edge.png",
  280. "scifi_nodes_door_"..base_name.."_edge.png",
  281. "scifi_nodes_door_"..base_name.."_edge.png",
  282. "scifi_nodes_door_"..base_name.."_edge.png",
  283. "scifi_nodes_door_"..base_name.."_rtopo.png",
  284. "scifi_nodes_door_"..base_name.."_topo.png"
  285. },
  286. drawtype = "nodebox",
  287. paramtype = "light",
  288. paramtype2 = "facedir",
  289. groups = {cracky = 1},
  290. node_box = {
  291. type = "fixed",
  292. fixed = {
  293. {-0.5, -0.5, -0.0625, -0.25, 0.5, 0.0625},
  294. }
  295. },
  296. selection_box = {
  297. type = "fixed",
  298. fixed = {
  299. {0, 0, 0, 0, 0, 0},
  300. }
  301. },
  302. can_dig = nodig,
  303. })
  304. end -- end of doors table browsing