123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748 |
- -- Get mesecon rules of pistons
- piston_rules =
- {{x=0, y=0, z=1}, --everything apart from z- (pusher side)
- {x=1, y=0, z=0},
- {x=-1, y=0, z=0},
- {x=1, y=1, z=0},
- {x=1, y=-1, z=0},
- {x=-1, y=1, z=0},
- {x=-1, y=-1, z=0},
- {x=0, y=1, z=1},
- {x=0, y=-1, z=1}}
- local piston_up_rules =
- {{x=0, y=0, z=-1}, --everything apart from y+ (pusher side)
- {x=1, y=0, z=0},
- {x=-1, y=0, z=0},
- {x=0, y=0, z=1},
- {x=1, y=-1, z=0},
- {x=-1, y=-1, z=0},
- {x=0, y=-1, z=1},
- {x=0, y=-1, z=-1}}
- local piston_down_rules =
- {{x=0, y=0, z=-1}, --everything apart from y- (pusher side)
- {x=1, y=0, z=0},
- {x=-1, y=0, z=0},
- {x=0, y=0, z=1},
- {x=1, y=1, z=0},
- {x=-1, y=1, z=0},
- {x=0, y=1, z=1},
- {x=0, y=1, z=-1}}
- local piston_get_rules = function (node)
- local rules = piston_rules
- for i = 1, node.param2 do
- rules = mesecon:rotate_rules_left(rules)
- end
- return rules
- end
- piston_facedir_direction = function (node)
- local rules = {{x = 0, y = 0, z = -1}}
- for i = 1, node.param2 do
- rules = mesecon:rotate_rules_left(rules)
- end
- return rules[1]
- end
- piston_get_direction = function (dir, node)
- if type(dir) == "function" then
- return dir(node)
- else
- return dir
- end
- end
- local piston_remove_pusher = function (pos, node)
- pistonspec = minetest.registered_nodes[node.name].mesecons_piston
- dir = piston_get_direction(pistonspec.dir, node)
- local pusherpos = mesecon:addPosRule(pos, dir)
- local pushername = minetest.env:get_node(pusherpos).name
- if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
- minetest.env:remove_node(pusherpos)
- nodeupdate(pusherpos)
- end
- end
- local piston_on = function (pos, node)
- local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
- local dir = piston_get_direction(pistonspec.dir, node)
- local np = mesecon:addPosRule(pos, dir)
- local success, stack, oldstack = mesecon:mvps_push(np, dir, PISTON_MAXIMUM_PUSH)
- if success then
- minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.onname})
- minetest.env:add_node(np, {param2 = node.param2, name = pistonspec.pusher})
- mesecon:mvps_process_stack (stack)
- mesecon:mvps_move_objects (np, dir, oldstack)
- end
- end
- local piston_off = function (pos, node)
- local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
- minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.offname})
- piston_remove_pusher (pos, node)
- if pistonspec.sticky then
- dir = piston_get_direction(pistonspec.dir, node)
- pullpos = mesecon:addPosRule(pos, dir)
- stack = mesecon:mvps_pull_single(pullpos, dir)
- mesecon:mvps_process_stack(pos, dir, stack)
- end
- end
- local piston_orientate = function (pos, placer)
- -- not placed by player
- if not placer then return end
- -- placer pitch in degrees
- local pitch = placer:get_look_pitch() * (180 / math.pi)
- local node = minetest.env:get_node(pos)
- local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
- if pitch > 55 then --looking upwards
- minetest.env:add_node(pos, {name=pistonspec.piston_down})
- elseif pitch < -55 then --looking downwards
- minetest.env:add_node(pos, {name=pistonspec.piston_up})
- end
- end
- -- Horizontal pistons
- local pt = 3/16 -- pusher thickness
- local piston_pusher_box = {
- type = "fixed",
- fixed = {
- {-2/16, -2/16, -.5 + pt, 2/16, 2/16, .5 + pt},
- {-.5 , -.5 , -.5 , .5 , .5 , -.5 + pt},
- }
- }
- local piston_on_box = {
- type = "fixed",
- fixed = {
- {-.5, -.5, -.5 + pt, .5, .5, .5}
- }
- }
- -- Normal (non-sticky) ones:
- local pistonspec_normal = {
- offname = "mesecons_pistons:piston_normal_off",
- onname = "mesecons_pistons:piston_normal_on",
- dir = piston_facedir_direction,
- pusher = "mesecons_pistons:piston_pusher_normal",
- piston_down = "mesecons_pistons:piston_down_normal_off",
- piston_up = "mesecons_pistons:piston_up_normal_off",
- }
- -- offstate
- minetest.register_node("mesecons_pistons:piston_normal_off", {
- description = "Piston",
- tiles = {
- "mesecons_piston_top.png",
- "mesecons_piston_bottom.png",
- "mesecons_piston_left.png",
- "mesecons_piston_right.png",
- "mesecons_piston_back.png",
- "mesecons_piston_pusher_front.png"
- },
- groups = {cracky = 3},
- paramtype2 = "facedir",
- after_place_node = piston_orientate,
- mesecons_piston = pistonspec_normal,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_on = piston_on,
- rules = piston_get_rules
- }}
- })
- -- onstate
- minetest.register_node("mesecons_pistons:piston_normal_on", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_top.png",
- "mesecons_piston_bottom.png",
- "mesecons_piston_left.png",
- "mesecons_piston_right.png",
- "mesecons_piston_back.png",
- "mesecons_piston_on_front.png"
- },
- inventory_image = "mesecons_piston_top.png",
- wield_image = "mesecons_piston_top.png",
- groups = {cracky = 3, not_in_creative_inventory = 1},
- paramtype = "light",
- paramtype2 = "facedir",
- drop = "mesecons_pistons:piston_normal_off",
- after_dig_node = piston_remove_pusher,
- node_box = piston_on_box,
- selection_box = piston_on_box,
- mesecons_piston = pistonspec_normal,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_off = piston_off,
- rules = piston_get_rules
- }}
- })
- -- pusher
- minetest.register_node("mesecons_pistons:piston_pusher_normal", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_pusher_top.png",
- "mesecons_piston_pusher_bottom.png",
- "mesecons_piston_pusher_left.png",
- "mesecons_piston_pusher_right.png",
- "mesecons_piston_pusher_back.png",
- "mesecons_piston_pusher_front.png"
- },
- paramtype = "light",
- paramtype2 = "facedir",
- diggable = false,
- corresponding_piston = "mesecons_pistons:piston_normal_on",
- selection_box = piston_pusher_box,
- node_box = piston_pusher_box,
- })
- -- Sticky ones
- local pistonspec_sticky = {
- offname = "mesecons_pistons:piston_sticky_off",
- onname = "mesecons_pistons:piston_sticky_on",
- dir = piston_facedir_direction,
- pusher = "mesecons_pistons:piston_pusher_sticky",
- sticky = true,
- piston_down = "mesecons_pistons:piston_down_sticky_off",
- piston_up = "mesecons_pistons:piston_up_sticky_off",
- }
- -- offstate
- minetest.register_node("mesecons_pistons:piston_sticky_off", {
- description = "Sticky Piston",
- tiles = {
- "mesecons_piston_top.png",
- "mesecons_piston_bottom.png",
- "mesecons_piston_left.png",
- "mesecons_piston_right.png",
- "mesecons_piston_back.png",
- "mesecons_piston_pusher_front_sticky.png"
- },
- groups = {cracky = 3},
- paramtype2 = "facedir",
- after_place_node = piston_orientate,
- mesecons_piston = pistonspec_sticky,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_on = piston_on,
- rules = piston_get_rules
- }}
- })
- -- onstate
- minetest.register_node("mesecons_pistons:piston_sticky_on", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_top.png",
- "mesecons_piston_bottom.png",
- "mesecons_piston_left.png",
- "mesecons_piston_right.png",
- "mesecons_piston_back.png",
- "mesecons_piston_on_front.png"
- },
- inventory_image = "mesecons_piston_top.png",
- wield_image = "mesecons_piston_top.png",
- groups = {cracky = 3, not_in_creative_inventory = 1},
- paramtype = "light",
- paramtype2 = "facedir",
- drop = "mesecons_pistons:piston_normal_off",
- after_dig_node = piston_remove_pusher,
- node_box = piston_on_box,
- selection_box = piston_on_box,
- mesecons_piston = pistonspec_sticky,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_off = piston_off,
- rules = piston_get_rules
- }}
- })
- -- pusher
- minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_pusher_top.png",
- "mesecons_piston_pusher_bottom.png",
- "mesecons_piston_pusher_left.png",
- "mesecons_piston_pusher_right.png",
- "mesecons_piston_pusher_back.png",
- "mesecons_piston_pusher_front_sticky.png"
- },
- paramtype = "light",
- paramtype2 = "facedir",
- diggable = false,
- corresponding_piston = "mesecons_pistons:piston_sticky_on",
- selection_box = piston_pusher_box,
- node_box = piston_pusher_box,
- })
- --
- --
- -- UP
- --
- --
- local piston_up_pusher_box = {
- type = "fixed",
- fixed = {
- {-2/16, -.5 - pt, -2/16, 2/16, .5 - pt, 2/16},
- {-.5 , .5 - pt, -.5 , .5 , .5 , .5},
- }
- }
- local piston_up_on_box = {
- type = "fixed",
- fixed = {
- {-.5, -.5, -.5 , .5, .5-pt, .5}
- }
- }
- -- Normal
- local pistonspec_normal_up = {
- offname = "mesecons_pistons:piston_up_normal_off",
- onname = "mesecons_pistons:piston_up_normal_on",
- dir = {x = 0, y = 1, z = 0},
- pusher = "mesecons_pistons:piston_up_pusher_normal"
- }
- -- offstate
- minetest.register_node("mesecons_pistons:piston_up_normal_off", {
- tiles = {
- "mesecons_piston_pusher_front.png",
- "mesecons_piston_back.png",
- "mesecons_piston_left.png^[transformR270",
- "mesecons_piston_right.png^[transformR90",
- "mesecons_piston_bottom.png",
- "mesecons_piston_top.png^[transformR180",
- },
- inventory_image = "mesecons_piston_top.png",
- wield_image = "mesecons_piston_top.png",
- groups = {cracky = 3, not_in_creative_inventory = 1},
- paramtype2 = "facedir",
- drop = "mesecons_pistons:piston_normal_off",
- mesecons_piston = pistonspec_normal_up,
- mesecons = {effector={
- action_on = piston_on,
- rules = piston_up_rules,
- }}
- })
- -- onstate
- minetest.register_node("mesecons_pistons:piston_up_normal_on", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_on_front.png",
- "mesecons_piston_back.png",
- "mesecons_piston_left.png^[transformR270",
- "mesecons_piston_right.png^[transformR90",
- "mesecons_piston_bottom.png",
- "mesecons_piston_top.png^[transformR180",
- },
- inventory_image = "mesecons_piston_top.png",
- wield_image = "mesecons_piston_top.png",
- groups = {cracky = 3, not_in_creative_inventory = 1},
- paramtype = "light",
- paramtype2 = "facedir",
- drop = "mesecons_pistons:piston_normal_off",
- after_dig_node = piston_remove_pusher,
- node_box = piston_up_on_box,
- selection_box = piston_up_on_box,
- mesecons_piston = pistonspec_normal_up,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_off = piston_off,
- rules = piston_up_rules,
- }}
- })
- -- pusher
- minetest.register_node("mesecons_pistons:piston_up_pusher_normal", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_pusher_front.png",
- "mesecons_piston_pusher_back.png",
- "mesecons_piston_pusher_left.png^[transformR270",
- "mesecons_piston_pusher_right.png^[transformR90",
- "mesecons_piston_pusher_bottom.png",
- "mesecons_piston_pusher_top.png^[transformR180",
- },
- paramtype = "light",
- paramtype2 = "facedir",
- diggable = false,
- corresponding_piston = "mesecons_pistons:piston_up_normal_on",
- selection_box = piston_up_pusher_box,
- node_box = piston_up_pusher_box,
- })
- -- Sticky
- local pistonspec_sticky_up = {
- offname = "mesecons_pistons:piston_up_sticky_off",
- onname = "mesecons_pistons:piston_up_sticky_on",
- dir = {x = 0, y = 1, z = 0},
- pusher = "mesecons_pistons:piston_up_pusher_sticky",
- sticky = true
- }
- -- offstate
- minetest.register_node("mesecons_pistons:piston_up_sticky_off", {
- tiles = {
- "mesecons_piston_pusher_front_sticky.png",
- "mesecons_piston_back.png",
- "mesecons_piston_left.png^[transformR270",
- "mesecons_piston_right.png^[transformR90",
- "mesecons_piston_bottom.png",
- "mesecons_piston_top.png^[transformR180",
- "mesecons_piston_tb.png"
- },
- inventory_image = "mesecons_piston_top.png",
- wield_image = "mesecons_piston_top.png",
- groups = {cracky = 3, not_in_creative_inventory = 1},
- paramtype2 = "facedir",
- drop = "mesecons_pistons:piston_sticky_off",
- mesecons_piston = pistonspec_sticky_up,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_on = piston_on,
- rules = piston_up_rules,
- }}
- })
- -- onstate
- minetest.register_node("mesecons_pistons:piston_up_sticky_on", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_on_front.png",
- "mesecons_piston_back.png",
- "mesecons_piston_left.png^[transformR270",
- "mesecons_piston_right.png^[transformR90",
- "mesecons_piston_bottom.png",
- "mesecons_piston_top.png^[transformR180",
- },
- inventory_image = "mesecons_piston_top.png",
- wield_image = "mesecons_piston_top.png",
- groups = {cracky = 3, not_in_creative_inventory = 1},
- paramtype = "light",
- paramtype2 = "facedir",
- drop = "mesecons_pistons:piston_normal_off",
- after_dig_node = piston_remove_pusher,
- node_box = piston_up_on_box,
- selection_box = piston_up_on_box,
- mesecons_piston = pistonspec_sticky_up,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_off = piston_off,
- rules = piston_up_rules,
- }}
- })
- -- pusher
- minetest.register_node("mesecons_pistons:piston_up_pusher_sticky", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_pusher_front_sticky.png",
- "mesecons_piston_pusher_back.png",
- "mesecons_piston_pusher_left.png^[transformR270",
- "mesecons_piston_pusher_right.png^[transformR90",
- "mesecons_piston_pusher_bottom.png",
- "mesecons_piston_pusher_top.png^[transformR180",
- },
- paramtype = "light",
- paramtype2 = "facedir",
- diggable = false,
- corresponding_piston = "mesecons_pistons:piston_up_sticky_on",
- selection_box = piston_up_pusher_box,
- node_box = piston_up_pusher_box,
- })
- --
- --
- -- DOWN
- --
- --
- local piston_down_pusher_box = {
- type = "fixed",
- fixed = {
- {-2/16, -.5 + pt, -2/16, 2/16, .5 + pt, 2/16},
- {-.5 , -.5 , -.5 , .5 , -.5 + pt, .5},
- }
- }
- local piston_down_on_box = {
- type = "fixed",
- fixed = {
- {-.5, -.5+pt, -.5 , .5, .5, .5}
- }
- }
- -- Normal
- local pistonspec_normal_down = {
- offname = "mesecons_pistons:piston_down_normal_off",
- onname = "mesecons_pistons:piston_down_normal_on",
- dir = {x = 0, y = -1, z = 0},
- pusher = "mesecons_pistons:piston_down_pusher_normal",
- }
- -- offstate
- minetest.register_node("mesecons_pistons:piston_down_normal_off", {
- tiles = {
- "mesecons_piston_back.png",
- "mesecons_piston_pusher_front.png",
- "mesecons_piston_left.png^[transformR90",
- "mesecons_piston_right.png^[transformR270",
- "mesecons_piston_bottom.png^[transformR180",
- "mesecons_piston_top.png",
- },
- inventory_image = "mesecons_piston_top.png",
- wield_image = "mesecons_piston_top.png",
- groups = {cracky = 3, not_in_creative_inventory = 1},
- paramtype2 = "facedir",
- drop = "mesecons_pistons:piston_normal_off",
- mesecons_piston = pistonspec_normal_down,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_on = piston_on,
- rules = piston_down_rules,
- }}
- })
- -- onstate
- minetest.register_node("mesecons_pistons:piston_down_normal_on", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_back.png",
- "mesecons_piston_on_front.png",
- "mesecons_piston_left.png^[transformR90",
- "mesecons_piston_right.png^[transformR270",
- "mesecons_piston_bottom.png^[transformR180",
- "mesecons_piston_top.png",
- },
- inventory_image = "mesecons_piston_top.png",
- wield_image = "mesecons_piston_top.png",
- groups = {cracky = 3, not_in_creative_inventory = 1},
- paramtype = "light",
- paramtype2 = "facedir",
- drop = "mesecons_pistons:piston_normal_off",
- after_dig_node = piston_remove_pusher,
- node_box = piston_down_on_box,
- selection_box = piston_down_on_box,
- mesecons_piston = pistonspec_normal_down,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_off = piston_off,
- rules = piston_down_rules,
- }}
- })
- -- pusher
- minetest.register_node("mesecons_pistons:piston_down_pusher_normal", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_pusher_back.png",
- "mesecons_piston_pusher_front.png",
- "mesecons_piston_pusher_left.png^[transformR90",
- "mesecons_piston_pusher_right.png^[transformR270",
- "mesecons_piston_pusher_bottom.png^[transformR180",
- "mesecons_piston_pusher_top.png",
- },
- paramtype = "light",
- paramtype2 = "facedir",
- diggable = false,
- corresponding_piston = "mesecons_pistons:piston_down_normal_on",
- selection_box = piston_down_pusher_box,
- node_box = piston_down_pusher_box,
- })
- -- Sticky
- local pistonspec_sticky_down = {
- onname = "mesecons_pistons:piston_down_sticky_on",
- offname = "mesecons_pistons:piston_down_sticky_off",
- dir = {x = 0, y = -1, z = 0},
- pusher = "mesecons_pistons:piston_down_pusher_sticky",
- sticky = true
- }
- -- offstate
- minetest.register_node("mesecons_pistons:piston_down_sticky_off", {
- tiles = {
- "mesecons_piston_back.png",
- "mesecons_piston_pusher_front_sticky.png",
- "mesecons_piston_left.png^[transformR90",
- "mesecons_piston_right.png^[transformR270",
- "mesecons_piston_bottom.png^[transformR180",
- "mesecons_piston_top.png",
- },
- inventory_image = "mesecons_piston_top.png",
- wield_image = "mesecons_piston_top.png",
- groups = {cracky = 3, not_in_creative_inventory = 1},
- paramtype2 = "facedir",
- drop = "mesecons_pistons:piston_sticky_off",
- mesecons_piston = pistonspec_sticky_down,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_on = piston_on,
- rules = piston_down_rules,
- }}
- })
- -- onstate
- minetest.register_node("mesecons_pistons:piston_down_sticky_on", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_back.png",
- "mesecons_piston_on_front.png",
- "mesecons_piston_left.png^[transformR90",
- "mesecons_piston_right.png^[transformR270",
- "mesecons_piston_bottom.png^[transformR180",
- "mesecons_piston_top.png",
- },
- inventory_image = "mesecons_piston_top.png",
- wield_image = "mesecons_piston_top.png",
- groups = {cracky = 3, not_in_creative_inventory = 1},
- paramtype = "light",
- paramtype2 = "facedir",
- drop = "mesecons_pistons:piston_sticky_off",
- after_dig_node = piston_remove_pusher,
- node_box = piston_down_on_box,
- selection_box = piston_down_on_box,
- mesecons_piston = pistonspec_sticky_down,
- sounds = default.node_sound_wood_defaults(),
- mesecons = {effector={
- action_off = piston_off,
- rules = piston_down_rules,
- }}
- })
- -- pusher
- minetest.register_node("mesecons_pistons:piston_down_pusher_sticky", {
- drawtype = "nodebox",
- tiles = {
- "mesecons_piston_pusher_back.png",
- "mesecons_piston_pusher_front_sticky.png",
- "mesecons_piston_pusher_left.png^[transformR90",
- "mesecons_piston_pusher_right.png^[transformR270",
- "mesecons_piston_pusher_bottom.png^[transformR180",
- "mesecons_piston_pusher_top.png",
- },
- paramtype = "light",
- paramtype2 = "facedir",
- diggable = false,
- corresponding_piston = "mesecons_pistons:piston_down_sticky_on",
- selection_box = piston_down_pusher_box,
- node_box = piston_down_pusher_box,
- })
- -- Register pushers as stoppers if they would be seperated from the piston
- local piston_pusher_get_stopper = function (node, dir, stack, stackid)
- if (stack[stackid + 1]
- and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].corresponding_piston
- and stack[stackid + 1].node.param2 == node.param2)
- or (stack[stackid - 1]
- and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].corresponding_piston
- and stack[stackid - 1].node.param2 == node.param2) then
- return false
- end
- return true
- end
- local piston_pusher_up_down_get_stopper = function (node, dir, stack, stackid)
- if (stack[stackid + 1]
- and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].corresponding_piston)
- or (stack[stackid - 1]
- and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].corresponding_piston) then
- return false
- end
- return true
- end
- mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal", piston_pusher_get_stopper)
- mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky", piston_pusher_get_stopper)
- mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_normal", piston_pusher_up_down_get_stopper)
- mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_sticky", piston_pusher_up_down_get_stopper)
- mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_normal", piston_pusher_up_down_get_stopper)
- mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_sticky", piston_pusher_up_down_get_stopper)
- -- Register pistons as stoppers if they would be seperated from the stopper
- local piston_up_down_get_stopper = function (node, dir, stack, stackid)
- if (stack[stackid + 1]
- and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].mesecons_piston.pusher)
- or (stack[stackid - 1]
- and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].mesecons_piston.pusher) then
- return false
- end
- return true
- end
- local piston_get_stopper = function (node, dir, stack, stackid)
- pistonspec = minetest.registered_nodes[node.name].mesecons_piston
- dir = piston_get_direction(pistonspec.dir, node)
- local pusherpos = mesecon:addPosRule(stack[stackid].pos, dir)
- local pushernode = minetest.env:get_node(pusherpos)
- if minetest.registered_nodes[node.name].mesecons_piston.pusher == pushernode.name then
- for _, s in ipairs(stack) do
- if mesecon:cmpPos(s.pos, pusherpos) -- pusher is also to be pushed
- and s.node.param2 == node.param2 then
- return false
- end
- end
- end
- return true
- end
- mesecon:register_mvps_stopper("mesecons_pistons:piston_normal_on", piston_get_stopper)
- mesecon:register_mvps_stopper("mesecons_pistons:piston_sticky_on", piston_get_stopper)
- mesecon:register_mvps_stopper("mesecons_pistons:piston_up_normal_on", piston_up_down_get_stopper)
- mesecon:register_mvps_stopper("mesecons_pistons:piston_up_sticky_on", piston_up_down_get_stopper)
- mesecon:register_mvps_stopper("mesecons_pistons:piston_down_normal_on", piston_up_down_get_stopper)
- mesecon:register_mvps_stopper("mesecons_pistons:piston_down_sticky_on", piston_up_down_get_stopper)
- --craft recipes
- minetest.register_craft({
- output = "mesecons_pistons:piston_normal_off 2",
- recipe = {
- {"default:wood", "default:wood", "default:wood"},
- {"default:cobble", "default:steel_ingot", "default:cobble"},
- {"default:cobble", "group:mesecon_conductor_craftable", "default:cobble"},
- }
- })
- minetest.register_craft({
- output = "mesecons_pistons:piston_sticky_off",
- recipe = {
- {"mesecons_materials:glue"},
- {"mesecons_pistons:piston_normal_off"},
- }
- })
|