init.lua 22 KB

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