init.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. -- Get mesecon rules of pistons
  2. piston_rules =
  3. {{x=0, y=0, z=1}, --everything apart from z- (pusher side)
  4. {x=1, y=0, z=0},
  5. {x=-1, y=0, z=0},
  6. {x=1, y=1, z=0},
  7. {x=1, y=-1, z=0},
  8. {x=-1, y=1, z=0},
  9. {x=-1, y=-1, z=0},
  10. {x=0, y=1, z=1},
  11. {x=0, y=-1, z=1}}
  12. local piston_get_rules = function (node)
  13. local rules = piston_rules
  14. for i = 1, node.param2 do
  15. rules = mesecon:rotate_rules_left(rules)
  16. end
  17. return rules
  18. end
  19. piston_facedir_direction = function (node)
  20. local rules = {{x = 0, y = 0, z = -1}}
  21. for i = 1, node.param2 do
  22. rules = mesecon:rotate_rules_left(rules)
  23. end
  24. return rules[1]
  25. end
  26. piston_get_direction = function (dir, node)
  27. if type(dir) == "function" then
  28. return dir(node)
  29. else
  30. return dir
  31. end
  32. end
  33. local piston_remove_pusher = function (pos, node)
  34. pistonspec = minetest.registered_nodes[node.name].mesecons_piston
  35. dir = piston_get_direction(pistonspec.dir, node)
  36. local pusherpos = mesecon:addPosRule(pos, dir)
  37. local pushername = minetest.env:get_node(pusherpos).name
  38. if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
  39. minetest.env:remove_node(pusherpos)
  40. nodeupdate(pusherpos)
  41. end
  42. end
  43. local piston_on = function (pos, node)
  44. local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
  45. dir = piston_get_direction(pistonspec.dir, node)
  46. local np = mesecon:addPosRule(pos, dir)
  47. success, stack = mesecon:mvps_push(np, dir, PISTON_MAXIMUM_PUSH)
  48. if success then
  49. minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.onname})
  50. minetest.env:add_node(np, {param2 = node.param2, name = pistonspec.pusher})
  51. mesecon:mvps_process_stack(stack)
  52. end
  53. end
  54. local piston_off = function (pos, node)
  55. local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
  56. minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.offname})
  57. piston_remove_pusher (pos, node)
  58. if pistonspec.sticky then
  59. dir = piston_get_direction(pistonspec.dir, node)
  60. pullpos = mesecon:addPosRule(pos, dir)
  61. stack = mesecon:mvps_pull_single(pullpos, dir)
  62. mesecon:mvps_process_stack(stack)
  63. end
  64. end
  65. local piston_orientate = function (pos, placer)
  66. -- not placed by player
  67. if not placer then return end
  68. -- placer pitch in degrees
  69. local pitch = placer:get_look_pitch() * (180 / math.pi)
  70. local node = minetest.env:get_node(pos)
  71. local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
  72. if pitch > 55 then --looking upwards
  73. minetest.env:add_node(pos, {name=pistonspec.piston_down})
  74. elseif pitch < -55 then --looking downwards
  75. minetest.env:add_node(pos, {name=pistonspec.piston_up})
  76. end
  77. end
  78. -- Horizontal pistons
  79. local pt = 3/16 -- pusher thickness
  80. local piston_pusher_box = {
  81. type = "fixed",
  82. fixed = {
  83. {-2/16, -2/16, -.5 + pt, 2/16, 2/16, .5 + pt},
  84. {-.5 , -.5 , -.5 , .5 , .5 , -.5 + pt},
  85. }
  86. }
  87. local piston_on_box = {
  88. type = "fixed",
  89. fixed = {
  90. {-.5, -.5, -.5 + pt, .5, .5, .5}
  91. }
  92. }
  93. -- Normal (non-sticky) ones:
  94. local pistonspec_normal = {
  95. offname = "mesecons_pistons:piston_normal_off",
  96. onname = "mesecons_pistons:piston_normal_on",
  97. dir = piston_facedir_direction,
  98. pusher = "mesecons_pistons:piston_pusher_normal",
  99. piston_down = "mesecons_pistons:piston_down_normal_off",
  100. piston_up = "mesecons_pistons:piston_up_normal_off",
  101. }
  102. -- offstate
  103. minetest.register_node("mesecons_pistons:piston_normal_off", {
  104. description = "Piston",
  105. tiles = {
  106. "mesecons_piston_top.png",
  107. "mesecons_piston_bottom.png",
  108. "mesecons_piston_left.png",
  109. "mesecons_piston_right.png",
  110. "mesecons_piston_back.png",
  111. "mesecons_piston_pusher_front.png"
  112. },
  113. groups = {cracky = 3},
  114. paramtype2 = "facedir",
  115. after_place_node = piston_orientate,
  116. mesecons_piston = pistonspec_normal,
  117. mesecons = {effector={
  118. action_on = piston_on,
  119. rules = piston_get_rules
  120. }}
  121. })
  122. -- onstate
  123. minetest.register_node("mesecons_pistons:piston_normal_on", {
  124. drawtype = "nodebox",
  125. tiles = {
  126. "mesecons_piston_top.png",
  127. "mesecons_piston_bottom.png",
  128. "mesecons_piston_left.png",
  129. "mesecons_piston_right.png",
  130. "mesecons_piston_back.png",
  131. "mesecons_piston_on_front.png"
  132. },
  133. inventory_image = "mesecons_piston_top.png",
  134. wield_image = "mesecons_piston_top.png",
  135. groups = {cracky = 3, not_in_creative_inventory = 1},
  136. paramtype = "light",
  137. paramtype2 = "facedir",
  138. drop = "mesecons_pistons:piston_normal_off",
  139. after_dig_node = piston_remove_pusher,
  140. node_box = piston_on_box,
  141. selection_box = piston_on_box,
  142. mesecons_piston = pistonspec_normal,
  143. mesecons = {effector={
  144. action_off = piston_off,
  145. rules = piston_get_rules
  146. }}
  147. })
  148. -- pusher
  149. minetest.register_node("mesecons_pistons:piston_pusher_normal", {
  150. drawtype = "nodebox",
  151. tiles = {
  152. "mesecons_piston_pusher_top.png",
  153. "mesecons_piston_pusher_bottom.png",
  154. "mesecons_piston_pusher_left.png",
  155. "mesecons_piston_pusher_right.png",
  156. "mesecons_piston_pusher_back.png",
  157. "mesecons_piston_pusher_front.png"
  158. },
  159. paramtype = "light",
  160. paramtype2 = "facedir",
  161. diggable = false,
  162. corresponding_piston = "mesecons_pistons:piston_normal_on",
  163. selection_box = piston_pusher_box,
  164. node_box = piston_pusher_box,
  165. })
  166. -- Sticky ones
  167. local pistonspec_sticky = {
  168. offname = "mesecons_pistons:piston_sticky_off",
  169. onname = "mesecons_pistons:piston_sticky_on",
  170. dir = piston_facedir_direction,
  171. pusher = "mesecons_pistons:piston_pusher_sticky",
  172. sticky = true,
  173. piston_down = "mesecons_pistons:piston_down_sticky_off",
  174. piston_up = "mesecons_pistons:piston_up_sticky_off",
  175. }
  176. -- offstate
  177. minetest.register_node("mesecons_pistons:piston_sticky_off", {
  178. description = "Sticky Piston",
  179. tiles = {
  180. "mesecons_piston_top.png",
  181. "mesecons_piston_bottom.png",
  182. "mesecons_piston_left.png",
  183. "mesecons_piston_right.png",
  184. "mesecons_piston_back.png",
  185. "mesecons_piston_pusher_front_sticky.png"
  186. },
  187. groups = {cracky = 3},
  188. paramtype2 = "facedir",
  189. after_place_node = piston_orientate,
  190. mesecons_piston = pistonspec_sticky,
  191. mesecons = {effector={
  192. action_on = piston_on,
  193. rules = piston_get_rules
  194. }}
  195. })
  196. -- onstate
  197. minetest.register_node("mesecons_pistons:piston_sticky_on", {
  198. drawtype = "nodebox",
  199. tiles = {
  200. "mesecons_piston_top.png",
  201. "mesecons_piston_bottom.png",
  202. "mesecons_piston_left.png",
  203. "mesecons_piston_right.png",
  204. "mesecons_piston_back.png",
  205. "mesecons_piston_on_front.png"
  206. },
  207. inventory_image = "mesecons_piston_top.png",
  208. wield_image = "mesecons_piston_top.png",
  209. groups = {cracky = 3, not_in_creative_inventory = 1},
  210. paramtype = "light",
  211. paramtype2 = "facedir",
  212. drop = "mesecons_pistons:piston_normal_off",
  213. after_dig_node = piston_remove_pusher,
  214. node_box = piston_on_box,
  215. selection_box = piston_on_box,
  216. mesecons_piston = pistonspec_sticky,
  217. mesecons = {effector={
  218. action_off = piston_off,
  219. rules = piston_get_rules
  220. }}
  221. })
  222. -- pusher
  223. minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
  224. drawtype = "nodebox",
  225. tiles = {
  226. "mesecons_piston_pusher_top.png",
  227. "mesecons_piston_pusher_bottom.png",
  228. "mesecons_piston_pusher_left.png",
  229. "mesecons_piston_pusher_right.png",
  230. "mesecons_piston_pusher_back.png",
  231. "mesecons_piston_pusher_front_sticky.png"
  232. },
  233. paramtype = "light",
  234. paramtype2 = "facedir",
  235. diggable = false,
  236. corresponding_piston = "mesecons_pistons:piston_sticky_on",
  237. selection_box = piston_pusher_box,
  238. node_box = piston_pusher_box,
  239. })
  240. --
  241. --
  242. -- UP
  243. --
  244. --
  245. local piston_up_pusher_box = {
  246. type = "fixed",
  247. fixed = {
  248. {-2/16, -.5 - pt, -2/16, 2/16, .5, 2/16},
  249. {-.5 , .5 - pt, -.5 , .5 , .5, .5},
  250. }
  251. }
  252. local piston_up_on_box = {
  253. type = "fixed",
  254. fixed = {
  255. {-.5, -.5, -.5 , .5, .5-pt, .5}
  256. }
  257. }
  258. -- Normal
  259. local pistonspec_normal_up = {
  260. offname = "mesecons_pistons:piston_up_normal_off",
  261. onname = "mesecons_pistons:piston_up_normal_on",
  262. dir = {x = 0, y = 1, z = 0},
  263. pusher = "mesecons_pistons:piston_up_pusher_normal"
  264. }
  265. -- offstate
  266. minetest.register_node("mesecons_pistons:piston_up_normal_off", {
  267. tiles = {
  268. "mesecons_piston_pusher_front.png",
  269. "mesecons_piston_back.png",
  270. "mesecons_piston_left.png^[transformR270",
  271. "mesecons_piston_right.png^[transformR90",
  272. "mesecons_piston_bottom.png",
  273. "mesecons_piston_top.png^[transformR180",
  274. },
  275. inventory_image = "mesecons_piston_top.png",
  276. wield_image = "mesecons_piston_top.png",
  277. groups = {cracky = 3, not_in_creative_inventory = 1},
  278. paramtype2 = "facedir",
  279. drop = "mesecons_pistons:piston_normal_off",
  280. mesecons_piston = pistonspec_normal_up,
  281. mesecons = {effector={
  282. action_on = piston_on,
  283. }}
  284. })
  285. -- onstate
  286. minetest.register_node("mesecons_pistons:piston_up_normal_on", {
  287. drawtype = "nodebox",
  288. tiles = {
  289. "mesecons_piston_on_front.png",
  290. "mesecons_piston_back.png",
  291. "mesecons_piston_left.png^[transformR270",
  292. "mesecons_piston_right.png^[transformR90",
  293. "mesecons_piston_bottom.png",
  294. "mesecons_piston_top.png^[transformR180",
  295. },
  296. inventory_image = "mesecons_piston_top.png",
  297. wield_image = "mesecons_piston_top.png",
  298. groups = {cracky = 3, not_in_creative_inventory = 1},
  299. paramtype = "light",
  300. paramtype2 = "facedir",
  301. drop = "mesecons_pistons:piston_normal_off",
  302. after_dig_node = piston_remove_pusher,
  303. node_box = piston_up_on_box,
  304. selection_box = piston_up_on_box,
  305. mesecons_piston = pistonspec_normal_up,
  306. mesecons = {effector={
  307. action_off = piston_off,
  308. }}
  309. })
  310. -- pusher
  311. minetest.register_node("mesecons_pistons:piston_up_pusher_normal", {
  312. drawtype = "nodebox",
  313. tiles = {
  314. "mesecons_piston_pusher_front.png",
  315. "mesecons_piston_pusher_back.png",
  316. "mesecons_piston_pusher_left.png^[transformR270",
  317. "mesecons_piston_pusher_right.png^[transformR90",
  318. "mesecons_piston_pusher_bottom.png",
  319. "mesecons_piston_pusher_top.png^[transformR180",
  320. },
  321. paramtype = "light",
  322. paramtype2 = "facedir",
  323. diggable = false,
  324. corresponding_piston = "mesecons_pistons:piston_up_normal_on",
  325. selection_box = piston_up_pusher_box,
  326. node_box = piston_up_pusher_box,
  327. })
  328. -- Sticky
  329. local pistonspec_sticky_up = {
  330. offname = "mesecons_pistons:piston_up_sticky_off",
  331. onname = "mesecons_pistons:piston_up_sticky_on",
  332. dir = {x = 0, y = 1, z = 0},
  333. pusher = "mesecons_pistons:piston_up_pusher_sticky",
  334. sticky = true
  335. }
  336. -- offstate
  337. minetest.register_node("mesecons_pistons:piston_up_sticky_off", {
  338. tiles = {
  339. "mesecons_piston_pusher_front_sticky.png",
  340. "mesecons_piston_back.png",
  341. "mesecons_piston_left.png^[transformR270",
  342. "mesecons_piston_right.png^[transformR90",
  343. "mesecons_piston_bottom.png",
  344. "mesecons_piston_top.png^[transformR180",
  345. "mesecons_piston_tb.png"
  346. },
  347. inventory_image = "mesecons_piston_top.png",
  348. wield_image = "mesecons_piston_top.png",
  349. groups = {cracky = 3, not_in_creative_inventory = 1},
  350. paramtype2 = "facedir",
  351. drop = "mesecons_pistons:piston_sticky_off",
  352. mesecons_piston = pistonspec_sticky_up,
  353. mesecons = {effector={
  354. action_on = piston_on,
  355. }}
  356. })
  357. -- onstate
  358. minetest.register_node("mesecons_pistons:piston_up_sticky_on", {
  359. drawtype = "nodebox",
  360. tiles = {
  361. "mesecons_piston_on_front.png",
  362. "mesecons_piston_back.png",
  363. "mesecons_piston_left.png^[transformR270",
  364. "mesecons_piston_right.png^[transformR90",
  365. "mesecons_piston_bottom.png",
  366. "mesecons_piston_top.png^[transformR180",
  367. },
  368. inventory_image = "mesecons_piston_top.png",
  369. wield_image = "mesecons_piston_top.png",
  370. groups = {cracky = 3, not_in_creative_inventory = 1},
  371. paramtype = "light",
  372. paramtype2 = "facedir",
  373. drop = "mesecons_pistons:piston_normal_off",
  374. after_dig_node = piston_remove_pusher,
  375. node_box = piston_up_on_box,
  376. selection_box = piston_up_on_box,
  377. mesecons_piston = pistonspec_sticky_up,
  378. mesecons = {effector={
  379. action_off = piston_off,
  380. }}
  381. })
  382. -- pusher
  383. minetest.register_node("mesecons_pistons:piston_up_pusher_sticky", {
  384. drawtype = "nodebox",
  385. tiles = {
  386. "mesecons_piston_pusher_front_sticky.png",
  387. "mesecons_piston_pusher_back.png",
  388. "mesecons_piston_pusher_left.png^[transformR270",
  389. "mesecons_piston_pusher_right.png^[transformR90",
  390. "mesecons_piston_pusher_bottom.png",
  391. "mesecons_piston_pusher_top.png^[transformR180",
  392. },
  393. paramtype = "light",
  394. paramtype2 = "facedir",
  395. diggable = false,
  396. corresponding_piston = "mesecons_pistons:piston_up_sticky_on",
  397. selection_box = piston_up_pusher_box,
  398. node_box = piston_up_pusher_box,
  399. })
  400. --
  401. --
  402. -- DOWN
  403. --
  404. --
  405. local piston_down_pusher_box = {
  406. type = "fixed",
  407. fixed = {
  408. {-2/16, -.5, -2/16, 2/16, .5 + pt, 2/16},
  409. {-.5 , -.5, -.5 , .5 , -.5 + pt, .5},
  410. }
  411. }
  412. local piston_down_on_box = {
  413. type = "fixed",
  414. fixed = {
  415. {-.5, -.5+pt, -.5 , .5, .5, .5}
  416. }
  417. }
  418. -- Normal
  419. local pistonspec_normal_down = {
  420. offname = "mesecons_pistons:piston_down_normal_off",
  421. onname = "mesecons_pistons:piston_down_normal_on",
  422. dir = {x = 0, y = -1, z = 0},
  423. pusher = "mesecons_pistons:piston_down_pusher_normal",
  424. }
  425. -- offstate
  426. minetest.register_node("mesecons_pistons:piston_down_normal_off", {
  427. tiles = {
  428. "mesecons_piston_back.png",
  429. "mesecons_piston_pusher_front.png",
  430. "mesecons_piston_left.png^[transformR90",
  431. "mesecons_piston_right.png^[transformR270",
  432. "mesecons_piston_bottom.png^[transformR180",
  433. "mesecons_piston_top.png",
  434. },
  435. inventory_image = "mesecons_piston_top.png",
  436. wield_image = "mesecons_piston_top.png",
  437. groups = {cracky = 3, not_in_creative_inventory = 1},
  438. paramtype2 = "facedir",
  439. drop = "mesecons_pistons:piston_normal_off",
  440. mesecons_piston = pistonspec_normal_down,
  441. mesecons = {effector={
  442. action_on = piston_on,
  443. }}
  444. })
  445. -- onstate
  446. minetest.register_node("mesecons_pistons:piston_down_normal_on", {
  447. drawtype = "nodebox",
  448. tiles = {
  449. "mesecons_piston_back.png",
  450. "mesecons_piston_on_front.png",
  451. "mesecons_piston_left.png^[transformR90",
  452. "mesecons_piston_right.png^[transformR270",
  453. "mesecons_piston_bottom.png^[transformR180",
  454. "mesecons_piston_top.png",
  455. },
  456. inventory_image = "mesecons_piston_top.png",
  457. wield_image = "mesecons_piston_top.png",
  458. groups = {cracky = 3, not_in_creative_inventory = 1},
  459. paramtype = "light",
  460. paramtype2 = "facedir",
  461. drop = "mesecons_pistons:piston_normal_off",
  462. after_dig_node = piston_remove_pusher,
  463. node_box = piston_down_on_box,
  464. selection_box = piston_down_on_box,
  465. mesecons_piston = pistonspec_normal_down,
  466. mesecons = {effector={
  467. action_off = piston_off,
  468. }}
  469. })
  470. -- pusher
  471. minetest.register_node("mesecons_pistons:piston_down_pusher_normal", {
  472. drawtype = "nodebox",
  473. tiles = {
  474. "mesecons_piston_pusher_back.png",
  475. "mesecons_piston_pusher_front.png",
  476. "mesecons_piston_pusher_left.png^[transformR90",
  477. "mesecons_piston_pusher_right.png^[transformR270",
  478. "mesecons_piston_pusher_bottom.png^[transformR180",
  479. "mesecons_piston_pusher_top.png",
  480. },
  481. paramtype = "light",
  482. paramtype2 = "facedir",
  483. diggable = false,
  484. corresponding_piston = "mesecons_pistons:piston_down_normal_on",
  485. selection_box = piston_down_pusher_box,
  486. node_box = piston_down_pusher_box,
  487. })
  488. -- Sticky
  489. local pistonspec_sticky_down = {
  490. onname = "mesecons_pistons:piston_down_sticky_on",
  491. offname = "mesecons_pistons:piston_down_sticky_off",
  492. dir = {x = 0, y = -1, z = 0},
  493. pusher = "mesecons_pistons:piston_down_pusher_sticky",
  494. sticky = true
  495. }
  496. -- offstate
  497. minetest.register_node("mesecons_pistons:piston_down_sticky_off", {
  498. tiles = {
  499. "mesecons_piston_back.png",
  500. "mesecons_piston_pusher_front_sticky.png",
  501. "mesecons_piston_left.png^[transformR90",
  502. "mesecons_piston_right.png^[transformR270",
  503. "mesecons_piston_bottom.png^[transformR180",
  504. "mesecons_piston_top.png",
  505. },
  506. inventory_image = "mesecons_piston_top.png",
  507. wield_image = "mesecons_piston_top.png",
  508. groups = {cracky = 3, not_in_creative_inventory = 1},
  509. paramtype2 = "facedir",
  510. drop = "mesecons_pistons:piston_sticky_off",
  511. mesecons_piston = pistonspec_sticky_down,
  512. mesecons = {effector={
  513. action_on = piston_on,
  514. }}
  515. })
  516. -- onstate
  517. minetest.register_node("mesecons_pistons:piston_down_sticky_on", {
  518. drawtype = "nodebox",
  519. tiles = {
  520. "mesecons_piston_back.png",
  521. "mesecons_piston_on_front.png",
  522. "mesecons_piston_left.png^[transformR90",
  523. "mesecons_piston_right.png^[transformR270",
  524. "mesecons_piston_bottom.png^[transformR180",
  525. "mesecons_piston_top.png",
  526. },
  527. inventory_image = "mesecons_piston_top.png",
  528. wield_image = "mesecons_piston_top.png",
  529. groups = {cracky = 3, not_in_creative_inventory = 1},
  530. paramtype = "light",
  531. paramtype2 = "facedir",
  532. drop = "mesecons_pistons:piston_sticky_off",
  533. after_dig_node = piston_remove_pusher,
  534. node_box = piston_down_on_box,
  535. selection_box = piston_down_on_box,
  536. mesecons_piston = pistonspec_sticky_down,
  537. mesecons = {effector={
  538. action_off = piston_off,
  539. }}
  540. })
  541. -- pusher
  542. minetest.register_node("mesecons_pistons:piston_down_pusher_sticky", {
  543. drawtype = "nodebox",
  544. tiles = {
  545. "mesecons_piston_pusher_back.png",
  546. "mesecons_piston_pusher_front_sticky.png",
  547. "mesecons_piston_pusher_left.png^[transformR90",
  548. "mesecons_piston_pusher_right.png^[transformR270",
  549. "mesecons_piston_pusher_bottom.png^[transformR180",
  550. "mesecons_piston_pusher_top.png",
  551. },
  552. paramtype = "light",
  553. paramtype2 = "facedir",
  554. diggable = false,
  555. corresponding_piston = "mesecons_pistons:piston_down_sticky_on",
  556. selection_box = piston_down_pusher_box,
  557. node_box = piston_down_pusher_box,
  558. })
  559. -- Register pushers as stoppers if they would be seperated from the piston
  560. local piston_pusher_get_stopper = function (node, dir, stack, stackid)
  561. if (stack[stackid + 1]
  562. and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].corresponding_piston
  563. and stack[stackid + 1].node.param2 == node.param2)
  564. or (stack[stackid - 1]
  565. and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].corresponding_piston
  566. and stack[stackid - 1].node.param2 == node.param2) then
  567. return false
  568. end
  569. return true
  570. end
  571. local piston_pusher_up_down_get_stopper = function (node, dir, stack, stackid)
  572. if (stack[stackid + 1]
  573. and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].corresponding_piston)
  574. or (stack[stackid - 1]
  575. and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].corresponding_piston) then
  576. return false
  577. end
  578. return true
  579. end
  580. mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal", piston_pusher_get_stopper)
  581. mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky", piston_pusher_get_stopper)
  582. mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_normal", piston_pusher_up_down_get_stopper)
  583. mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_sticky", piston_pusher_up_down_get_stopper)
  584. mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_normal", piston_pusher_up_down_get_stopper)
  585. mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_sticky", piston_pusher_up_down_get_stopper)
  586. -- Register pistons as stoppers if they would be seperated from the stopper
  587. local piston_up_down_get_stopper = function (node, dir, stack, stackid)
  588. if (stack[stackid + 1]
  589. and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].mesecons_piston.pusher)
  590. or (stack[stackid - 1]
  591. and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].mesecons_piston.pusher) then
  592. return false
  593. end
  594. return true
  595. end
  596. local piston_get_stopper = function (node, dir, stack, stackid)
  597. pistonspec = minetest.registered_nodes[node.name].mesecons_piston
  598. dir = piston_get_direction(pistonspec.dir, node)
  599. local pusherpos = mesecon:addPosRule(stack[stackid].pos, dir)
  600. local pushernode = minetest.env:get_node(pusherpos)
  601. if minetest.registered_nodes[node.name].mesecons_piston.pusher == pushernode.name then
  602. for _, s in ipairs(stack) do
  603. if mesecon:cmpPos(s.pos, pusherpos) -- pusher is also to be pushed
  604. and s.node.param2 == node.param2 then
  605. return false
  606. end
  607. end
  608. end
  609. return true
  610. end
  611. mesecon:register_mvps_stopper("mesecons_pistons:piston_normal_on", piston_get_stopper)
  612. mesecon:register_mvps_stopper("mesecons_pistons:piston_sticky_on", piston_get_stopper)
  613. mesecon:register_mvps_stopper("mesecons_pistons:piston_up_normal_on", piston_up_down_get_stopper)
  614. mesecon:register_mvps_stopper("mesecons_pistons:piston_up_sticky_on", piston_up_down_get_stopper)
  615. mesecon:register_mvps_stopper("mesecons_pistons:piston_down_normal_on", piston_up_down_get_stopper)
  616. mesecon:register_mvps_stopper("mesecons_pistons:piston_down_sticky_on", piston_up_down_get_stopper)
  617. --craft recipes
  618. minetest.register_craft({
  619. output = 'mesecons_pistons:piston_normal_off 2',
  620. recipe = {
  621. {"default:wood", "default:wood", "default:wood"},
  622. {"default:cobble", "default:steel_ingot", "default:cobble"},
  623. {"default:cobble", "group:mesecon_conductor_craftable", "default:cobble"},
  624. }
  625. })
  626. minetest.register_craft({
  627. output = "mesecons_pistons:piston_sticky_off",
  628. recipe = {
  629. {"mesecons_materials:glue"},
  630. {"mesecons_pistons:piston_normal_off"},
  631. }
  632. })