2016-12-26 05:24:28 +01:00
|
|
|
local piston_get_rules = function (node)
|
|
|
|
local all_rules ={
|
|
|
|
{x=0, y=0, z=1},
|
|
|
|
{x=0, y=0, z=-1},
|
|
|
|
{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},
|
|
|
|
{x=0, y=1, z=-1},
|
|
|
|
{x=0, y=-1, z=-1}}
|
2016-12-28 12:34:15 +01:00
|
|
|
local pusher_dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
|
2016-12-26 05:24:28 +01:00
|
|
|
for k,v in ipairs(all_rules) do
|
2016-12-28 12:34:15 +01:00
|
|
|
if vector.equals(v, pusher_dir) then
|
|
|
|
table.remove(all_rules, k)
|
2016-12-26 05:24:28 +01:00
|
|
|
end
|
2012-12-16 11:58:43 +01:00
|
|
|
end
|
2016-12-26 05:24:28 +01:00
|
|
|
return all_rules
|
2012-12-16 11:58:43 +01:00
|
|
|
end
|
|
|
|
|
2017-01-15 11:53:49 +01:00
|
|
|
local function piston_facedir_direction(node)
|
2012-12-26 22:54:28 +01:00
|
|
|
local rules = {{x = 0, y = 0, z = -1}}
|
|
|
|
for i = 1, node.param2 do
|
2014-11-22 15:42:22 +01:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
2012-12-16 01:12:20 +01:00
|
|
|
end
|
2012-12-26 22:54:28 +01:00
|
|
|
return rules[1]
|
2012-12-16 01:12:20 +01:00
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2013-06-22 21:43:58 +02:00
|
|
|
local piston_remove_pusher = function(pos, node)
|
2014-11-29 15:08:37 +01:00
|
|
|
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
2016-12-28 12:34:15 +01:00
|
|
|
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
|
2016-02-14 20:55:50 +01:00
|
|
|
local pusherpos = vector.add(pos, dir)
|
2013-12-01 04:13:00 +01:00
|
|
|
local pushername = minetest.get_node(pusherpos).name
|
2012-12-27 12:03:05 +01:00
|
|
|
|
2014-11-21 21:43:28 +01:00
|
|
|
-- make sure there actually is a pusher (for compatibility reasons mainly)
|
|
|
|
if pushername ~= pistonspec.pusher then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-12-01 04:13:00 +01:00
|
|
|
minetest.remove_node(pusherpos)
|
2013-06-22 21:43:58 +02:00
|
|
|
minetest.sound_play("piston_retract", {
|
|
|
|
pos = pos,
|
|
|
|
max_hear_distance = 20,
|
|
|
|
gain = 0.3,
|
|
|
|
})
|
|
|
|
nodeupdate(pusherpos)
|
2012-12-26 22:54:28 +01:00
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2013-06-22 21:43:58 +02:00
|
|
|
local piston_on = function(pos, node)
|
2012-12-26 22:54:28 +01:00
|
|
|
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
2016-12-28 12:34:15 +01:00
|
|
|
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
|
2016-02-14 20:55:50 +01:00
|
|
|
local np = vector.add(pos, dir)
|
2014-11-22 22:09:26 +01:00
|
|
|
local maxpush = mesecon.setting("piston_max_push", 15)
|
|
|
|
local success, stack, oldstack = mesecon.mvps_push(np, dir, maxpush)
|
2012-12-26 22:54:28 +01:00
|
|
|
if success then
|
2016-02-14 21:00:37 +01:00
|
|
|
minetest.set_node(pos, {param2 = node.param2, name = pistonspec.onname})
|
|
|
|
minetest.set_node(np, {param2 = node.param2, name = pistonspec.pusher})
|
2013-06-05 22:01:11 +02:00
|
|
|
minetest.sound_play("piston_extend", {
|
|
|
|
pos = pos,
|
|
|
|
max_hear_distance = 20,
|
|
|
|
gain = 0.3,
|
|
|
|
})
|
2015-02-14 11:54:27 +01:00
|
|
|
mesecon.mvps_process_stack(stack)
|
|
|
|
mesecon.mvps_move_objects(np, dir, oldstack)
|
2012-03-05 19:21:26 +01:00
|
|
|
end
|
2012-10-02 23:09:39 +02:00
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2013-06-22 21:43:58 +02:00
|
|
|
local piston_off = function(pos, node)
|
2012-12-26 22:54:28 +01:00
|
|
|
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
2016-02-14 21:00:37 +01:00
|
|
|
minetest.set_node(pos, {param2 = node.param2, name = pistonspec.offname})
|
2013-06-22 21:43:58 +02:00
|
|
|
piston_remove_pusher(pos, node)
|
2012-12-26 22:54:28 +01:00
|
|
|
if pistonspec.sticky then
|
2015-02-28 13:42:39 +01:00
|
|
|
local maxpull = mesecon.setting("piston_max_pull", 15)
|
2016-12-28 12:34:15 +01:00
|
|
|
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
|
2015-02-28 13:42:39 +01:00
|
|
|
local pullpos = vector.add(pos, vector.multiply(dir, 2))
|
|
|
|
local stack = mesecon.mvps_pull_single(pullpos, vector.multiply(dir, -1), maxpull)
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.mvps_process_stack(pos, dir, stack)
|
2012-10-13 18:45:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-28 12:34:15 +01:00
|
|
|
local piston_onrotate = function(pos, node, _, _, newparam2)
|
2016-12-26 05:24:28 +01:00
|
|
|
local node_copy = minetest.get_node(pos)
|
2016-12-28 12:34:15 +01:00
|
|
|
minetest.after(0, mesecon.on_dignode, pos, node)
|
2016-12-26 05:24:28 +01:00
|
|
|
node_copy.param2 = newparam2
|
2016-12-28 12:34:15 +01:00
|
|
|
minetest.after(0, mesecon.on_placenode, pos, node_copy)
|
2012-08-07 09:11:36 +02:00
|
|
|
end
|
2012-08-09 06:22:47 +02:00
|
|
|
|
2012-12-27 18:13:40 +01:00
|
|
|
local pt = 3/16 -- pusher thickness
|
2012-12-26 22:54:28 +01:00
|
|
|
|
|
|
|
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",
|
|
|
|
}
|
|
|
|
|
|
|
|
-- offstate
|
|
|
|
minetest.register_node("mesecons_pistons:piston_normal_off", {
|
2012-12-16 01:12:20 +01:00
|
|
|
description = "Piston",
|
2012-12-27 18:13:40 +01:00
|
|
|
tiles = {
|
2015-10-04 13:30:34 +02:00
|
|
|
"mesecons_piston_top.png",
|
|
|
|
"mesecons_piston_bottom.png",
|
|
|
|
"mesecons_piston_left.png",
|
|
|
|
"mesecons_piston_right.png",
|
|
|
|
"mesecons_piston_back.png",
|
2012-12-27 18:13:40 +01:00
|
|
|
"mesecons_piston_pusher_front.png"
|
|
|
|
},
|
2012-12-26 22:54:28 +01:00
|
|
|
groups = {cracky = 3},
|
2012-12-16 01:12:20 +01:00
|
|
|
paramtype2 = "facedir",
|
2012-12-26 22:54:28 +01:00
|
|
|
mesecons_piston = pistonspec_normal,
|
2016-12-26 05:24:28 +01:00
|
|
|
on_rotate = piston_onrotate,
|
2013-03-07 02:51:57 +01:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2012-12-16 01:12:20 +01:00
|
|
|
mesecons = {effector={
|
2012-12-26 22:54:28 +01:00
|
|
|
action_on = piston_on,
|
2012-12-16 11:58:43 +01:00
|
|
|
rules = piston_get_rules
|
2012-12-16 01:12:20 +01:00
|
|
|
}}
|
|
|
|
})
|
|
|
|
|
2012-12-26 22:54:28 +01:00
|
|
|
-- onstate
|
|
|
|
minetest.register_node("mesecons_pistons:piston_normal_on", {
|
|
|
|
drawtype = "nodebox",
|
2012-12-27 18:13:40 +01:00
|
|
|
tiles = {
|
2015-10-04 13:30:34 +02:00
|
|
|
"mesecons_piston_top.png",
|
|
|
|
"mesecons_piston_bottom.png",
|
|
|
|
"mesecons_piston_left.png",
|
|
|
|
"mesecons_piston_right.png",
|
|
|
|
"mesecons_piston_back.png",
|
2012-12-27 18:13:40 +01:00
|
|
|
"mesecons_piston_on_front.png"
|
|
|
|
},
|
2013-02-08 20:36:20 +01:00
|
|
|
inventory_image = "mesecons_piston_top.png",
|
|
|
|
wield_image = "mesecons_piston_top.png",
|
2012-12-26 22:54:28 +01:00
|
|
|
groups = {cracky = 3, not_in_creative_inventory = 1},
|
|
|
|
paramtype = "light",
|
2012-12-16 01:12:20 +01:00
|
|
|
paramtype2 = "facedir",
|
2013-01-20 13:01:40 +01:00
|
|
|
drop = "mesecons_pistons:piston_normal_off",
|
2012-12-26 22:54:28 +01:00
|
|
|
after_dig_node = piston_remove_pusher,
|
|
|
|
node_box = piston_on_box,
|
|
|
|
selection_box = piston_on_box,
|
|
|
|
mesecons_piston = pistonspec_normal,
|
2016-12-26 05:24:28 +01:00
|
|
|
on_rotate = false,
|
2013-03-07 02:51:57 +01:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2012-12-16 01:12:20 +01:00
|
|
|
mesecons = {effector={
|
2012-12-26 22:54:28 +01:00
|
|
|
action_off = piston_off,
|
2012-12-16 11:58:43 +01:00
|
|
|
rules = piston_get_rules
|
2012-12-16 01:12:20 +01:00
|
|
|
}}
|
|
|
|
})
|
|
|
|
|
2012-12-26 22:54:28 +01:00
|
|
|
-- pusher
|
2012-12-16 01:12:20 +01:00
|
|
|
minetest.register_node("mesecons_pistons:piston_pusher_normal", {
|
|
|
|
drawtype = "nodebox",
|
2012-12-27 18:13:40 +01:00
|
|
|
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"
|
|
|
|
},
|
2012-12-16 01:12:20 +01:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
diggable = false,
|
2016-12-26 05:24:28 +01:00
|
|
|
on_rotate = false,
|
2012-12-26 22:54:28 +01:00
|
|
|
corresponding_piston = "mesecons_pistons:piston_normal_on",
|
|
|
|
selection_box = piston_pusher_box,
|
|
|
|
node_box = piston_pusher_box,
|
2012-12-16 01:12:20 +01:00
|
|
|
})
|
|
|
|
|
2012-12-26 22:54:28 +01:00
|
|
|
-- 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,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- offstate
|
|
|
|
minetest.register_node("mesecons_pistons:piston_sticky_off", {
|
|
|
|
description = "Sticky Piston",
|
2012-12-27 18:13:40 +01:00
|
|
|
tiles = {
|
2015-10-04 13:30:34 +02:00
|
|
|
"mesecons_piston_top.png",
|
|
|
|
"mesecons_piston_bottom.png",
|
|
|
|
"mesecons_piston_left.png",
|
|
|
|
"mesecons_piston_right.png",
|
|
|
|
"mesecons_piston_back.png",
|
2012-12-27 18:13:40 +01:00
|
|
|
"mesecons_piston_pusher_front_sticky.png"
|
|
|
|
},
|
2012-12-26 22:54:28 +01:00
|
|
|
groups = {cracky = 3},
|
|
|
|
paramtype2 = "facedir",
|
2016-12-26 05:24:28 +01:00
|
|
|
on_rotate = piston_onrotate,
|
2012-12-26 22:54:28 +01:00
|
|
|
mesecons_piston = pistonspec_sticky,
|
2013-03-07 02:51:57 +01:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2012-12-26 22:54:28 +01:00
|
|
|
mesecons = {effector={
|
|
|
|
action_on = piston_on,
|
|
|
|
rules = piston_get_rules
|
|
|
|
}}
|
|
|
|
})
|
|
|
|
|
|
|
|
-- onstate
|
|
|
|
minetest.register_node("mesecons_pistons:piston_sticky_on", {
|
|
|
|
drawtype = "nodebox",
|
2012-12-27 18:13:40 +01:00
|
|
|
tiles = {
|
2015-10-04 13:30:34 +02:00
|
|
|
"mesecons_piston_top.png",
|
|
|
|
"mesecons_piston_bottom.png",
|
|
|
|
"mesecons_piston_left.png",
|
|
|
|
"mesecons_piston_right.png",
|
|
|
|
"mesecons_piston_back.png",
|
2012-12-27 18:13:40 +01:00
|
|
|
"mesecons_piston_on_front.png"
|
|
|
|
},
|
2013-02-08 20:36:20 +01:00
|
|
|
inventory_image = "mesecons_piston_top.png",
|
|
|
|
wield_image = "mesecons_piston_top.png",
|
2012-12-26 22:54:28 +01:00
|
|
|
groups = {cracky = 3, not_in_creative_inventory = 1},
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2015-02-05 20:26:51 +01:00
|
|
|
drop = "mesecons_pistons:piston_sticky_off",
|
2012-12-26 22:54:28 +01:00
|
|
|
after_dig_node = piston_remove_pusher,
|
|
|
|
node_box = piston_on_box,
|
|
|
|
selection_box = piston_on_box,
|
|
|
|
mesecons_piston = pistonspec_sticky,
|
2016-12-26 05:24:28 +01:00
|
|
|
on_rotate = false,
|
2013-03-07 02:51:57 +01:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2012-12-26 22:54:28 +01:00
|
|
|
mesecons = {effector={
|
|
|
|
action_off = piston_off,
|
|
|
|
rules = piston_get_rules
|
|
|
|
}}
|
|
|
|
})
|
|
|
|
|
|
|
|
-- pusher
|
2012-12-16 01:12:20 +01:00
|
|
|
minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
|
|
|
|
drawtype = "nodebox",
|
|
|
|
tiles = {
|
2012-12-27 18:13:40 +01:00
|
|
|
"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"
|
2012-12-16 01:12:20 +01:00
|
|
|
},
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
diggable = false,
|
2016-12-26 05:24:28 +01:00
|
|
|
on_rotate = false,
|
2012-12-26 22:54:28 +01:00
|
|
|
corresponding_piston = "mesecons_pistons:piston_sticky_on",
|
|
|
|
selection_box = piston_pusher_box,
|
|
|
|
node_box = piston_pusher_box,
|
2012-12-16 01:12:20 +01:00
|
|
|
})
|
|
|
|
|
2012-12-26 22:54:28 +01:00
|
|
|
-- 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
|
|
|
|
|
2014-11-22 15:42:22 +01:00
|
|
|
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)
|
2012-12-26 22:54:28 +01:00
|
|
|
|
|
|
|
-- 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)
|
2012-12-27 19:14:54 +01:00
|
|
|
pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
|
|
|
dir = piston_get_direction(pistonspec.dir, node)
|
2016-02-14 20:55:50 +01:00
|
|
|
local pusherpos = vector.add(stack[stackid].pos, dir)
|
2013-12-01 04:13:00 +01:00
|
|
|
local pushernode = minetest.get_node(pusherpos)
|
2012-12-27 19:14:54 +01:00
|
|
|
|
|
|
|
if minetest.registered_nodes[node.name].mesecons_piston.pusher == pushernode.name then
|
|
|
|
for _, s in ipairs(stack) do
|
2016-02-14 20:55:50 +01:00
|
|
|
if vector.equals(s.pos, pusherpos) -- pusher is also to be pushed
|
2012-12-27 19:14:54 +01:00
|
|
|
and s.node.param2 == node.param2 then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2012-12-26 22:54:28 +01:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.register_mvps_stopper("mesecons_pistons:piston_normal_on", piston_get_stopper)
|
|
|
|
mesecon.register_mvps_stopper("mesecons_pistons:piston_sticky_on", piston_get_stopper)
|
2012-12-26 22:54:28 +01:00
|
|
|
|
2012-12-16 01:12:20 +01:00
|
|
|
--craft recipes
|
|
|
|
minetest.register_craft({
|
2013-04-28 12:40:08 +02:00
|
|
|
output = "mesecons_pistons:piston_normal_off 2",
|
2012-12-16 01:12:20 +01:00
|
|
|
recipe = {
|
2013-12-01 01:07:12 +01:00
|
|
|
{"group:wood", "group:wood", "group:wood"},
|
2012-12-16 01:12:20 +01:00
|
|
|
{"default:cobble", "default:steel_ingot", "default:cobble"},
|
|
|
|
{"default:cobble", "group:mesecon_conductor_craftable", "default:cobble"},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2013-01-20 13:01:40 +01:00
|
|
|
output = "mesecons_pistons:piston_sticky_off",
|
2012-12-16 01:12:20 +01:00
|
|
|
recipe = {
|
|
|
|
{"mesecons_materials:glue"},
|
2013-02-09 01:50:20 +01:00
|
|
|
{"mesecons_pistons:piston_normal_off"},
|
2012-12-16 01:12:20 +01:00
|
|
|
}
|
2012-12-16 08:59:06 +01:00
|
|
|
})
|
2016-12-26 05:24:28 +01:00
|
|
|
|