init.lua 21 KB

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