2017-10-08 18:21:19 +02:00
|
|
|
local specs = {
|
|
|
|
normal = {
|
|
|
|
offname = "mesecons_pistons:piston_normal_off",
|
|
|
|
onname = "mesecons_pistons:piston_normal_on",
|
|
|
|
pusher = "mesecons_pistons:piston_pusher_normal",
|
|
|
|
},
|
|
|
|
sticky = {
|
|
|
|
offname = "mesecons_pistons:piston_sticky_off",
|
|
|
|
onname = "mesecons_pistons:piston_sticky_on",
|
|
|
|
pusher = "mesecons_pistons:piston_pusher_sticky",
|
|
|
|
sticky = true,
|
|
|
|
},
|
2017-01-15 11:53:49 +01:00
|
|
|
}
|
2013-03-14 19:19:02 +01:00
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local function get_pistonspec_name(name, part)
|
|
|
|
if part then
|
|
|
|
for spec_name, spec in pairs(specs) do
|
|
|
|
if name == spec[part] then
|
|
|
|
return spec_name, part
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
for spec_name, spec in pairs(specs) do
|
|
|
|
for part, value in pairs(spec) do
|
|
|
|
if name == value then
|
|
|
|
return spec_name, part
|
|
|
|
end
|
|
|
|
end
|
2012-12-16 11:58:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local function get_pistonspec(name, part)
|
|
|
|
return specs[get_pistonspec_name(name, part)]
|
2012-12-16 01:12:20 +01:00
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local max_push = mesecon.setting("piston_max_push", 15)
|
|
|
|
local max_pull = mesecon.setting("piston_max_pull", 15)
|
|
|
|
|
|
|
|
-- Get mesecon rules of pistons
|
|
|
|
local function piston_get_rules(node)
|
|
|
|
local dir = minetest.facedir_to_dir(node.param2)
|
|
|
|
for k, v in pairs(dir) do
|
|
|
|
if v ~= 0 then
|
|
|
|
dir = {k, -v}
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local rules = table.copy(mesecon.rules.default)
|
|
|
|
for i, rule in ipairs(rules) do
|
|
|
|
if rule[dir[1]] == dir[2] then
|
|
|
|
table.remove(rules, i)
|
|
|
|
end
|
2012-12-16 01:12:20 +01:00
|
|
|
end
|
2017-10-08 18:21:19 +02:00
|
|
|
return rules
|
2012-12-16 01:12:20 +01:00
|
|
|
end
|
2012-10-02 23:09:39 +02:00
|
|
|
|
2018-12-21 20:02:57 +01:00
|
|
|
local function piston_remove_pusher(pos, node, check_falling)
|
2017-10-08 18:21:19 +02:00
|
|
|
local pistonspec = get_pistonspec(node.name, "onname")
|
|
|
|
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,
|
|
|
|
})
|
2018-12-21 20:02:57 +01:00
|
|
|
|
|
|
|
if check_falling then
|
|
|
|
minetest.check_for_falling(pusherpos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function piston_after_dig(pos, node)
|
|
|
|
piston_remove_pusher(pos, node, true)
|
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)
|
2017-10-08 18:21:19 +02:00
|
|
|
local pistonspec = get_pistonspec(node.name, "offname")
|
|
|
|
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
|
|
|
|
local pusher_pos = vector.add(pos, dir)
|
2019-09-21 01:04:52 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local success, stack, oldstack = mesecon.mvps_push(pusher_pos, dir, max_push, meta:get_string("owner"))
|
2017-10-08 18:21:19 +02:00
|
|
|
if not success then
|
2019-09-21 01:04:52 +02:00
|
|
|
if stack == "protected" then
|
|
|
|
meta:set_string("infotext", "Can't extend: protected area on the way")
|
|
|
|
end
|
2017-10-08 18:21:19 +02:00
|
|
|
return
|
2012-03-05 19:21:26 +01:00
|
|
|
end
|
2019-09-21 01:04:52 +02:00
|
|
|
minetest.swap_node(pos, {param2 = node.param2, name = pistonspec.onname})
|
2017-10-08 18:21:19 +02:00
|
|
|
minetest.set_node(pusher_pos, {param2 = node.param2, name = pistonspec.pusher})
|
|
|
|
minetest.sound_play("piston_extend", {
|
|
|
|
pos = pos,
|
|
|
|
max_hear_distance = 20,
|
|
|
|
gain = 0.3,
|
|
|
|
})
|
|
|
|
mesecon.mvps_process_stack(stack)
|
|
|
|
mesecon.mvps_move_objects(pusher_pos, dir, oldstack)
|
2012-10-02 23:09:39 +02:00
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local function piston_off(pos, node)
|
|
|
|
local pistonspec = get_pistonspec(node.name, "onname")
|
2019-09-21 01:04:52 +02:00
|
|
|
minetest.swap_node(pos, {param2 = node.param2, name = pistonspec.offname})
|
|
|
|
piston_remove_pusher(pos, node, not pistonspec.sticky) -- allow that even in protected area
|
2012-10-13 18:45:15 +02:00
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
if not pistonspec.sticky then
|
|
|
|
return
|
2012-10-13 18:45:15 +02:00
|
|
|
end
|
2017-10-18 21:53:22 +02:00
|
|
|
local dir = minetest.facedir_to_dir(node.param2)
|
|
|
|
local pullpos = vector.add(pos, vector.multiply(dir, -2))
|
2019-09-21 01:04:52 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local success, stack, oldstack = mesecon.mvps_pull_single(pullpos, dir, max_pull, meta:get_string("owner"))
|
2017-10-18 21:53:22 +02:00
|
|
|
if success then
|
|
|
|
mesecon.mvps_move_objects(pullpos, vector.multiply(dir, -1), oldstack, -1)
|
|
|
|
end
|
2012-10-13 18:45:15 +02:00
|
|
|
end
|
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local orientations = {
|
|
|
|
[0] = { 4, 8},
|
|
|
|
{13, 17},
|
|
|
|
{10, 6},
|
|
|
|
{20, 15},
|
|
|
|
}
|
2012-12-26 22:54:28 +01:00
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local function piston_orientate(pos, placer)
|
2019-09-21 01:04:52 +02:00
|
|
|
mesecon.mvps_set_owner(pos, placer)
|
2017-10-08 18:21:19 +02:00
|
|
|
if not placer then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local pitch = math.deg(placer:get_look_vertical())
|
2013-12-01 04:13:00 +01:00
|
|
|
local node = minetest.get_node(pos)
|
2017-10-08 18:21:19 +02:00
|
|
|
if pitch > 55 then
|
|
|
|
node.param2 = orientations[node.param2][1]
|
|
|
|
elseif pitch < -55 then
|
|
|
|
node.param2 = orientations[node.param2][2]
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
-- minetest.after, because on_placenode for unoriented piston must be processed first
|
|
|
|
minetest.after(0, mesecon.on_placenode, pos, node)
|
|
|
|
end
|
2016-02-15 16:35:38 +01:00
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local rotations = {
|
|
|
|
{0, 16, 20, 12},
|
|
|
|
{2, 14, 22, 18},
|
|
|
|
{1, 5, 23, 9},
|
|
|
|
{3, 11, 21, 7},
|
|
|
|
{4, 13, 10, 19},
|
|
|
|
{6, 15, 8, 17},
|
|
|
|
}
|
2016-02-15 16:35:38 +01:00
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local function get_rotation(param2)
|
|
|
|
for a = 1, #rotations do
|
|
|
|
for f = 1, #rotations[a] do
|
|
|
|
if rotations[a][f] == param2 then
|
|
|
|
return a, f
|
|
|
|
end
|
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
end
|
2012-08-07 09:11:36 +02:00
|
|
|
end
|
2012-08-09 06:22:47 +02:00
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local function rotate(param2, mode)
|
|
|
|
local axis, face = get_rotation(param2)
|
|
|
|
if mode == screwdriver.ROTATE_FACE then
|
|
|
|
face = face + 1
|
|
|
|
if face > 4 then
|
|
|
|
face = 1
|
|
|
|
end
|
|
|
|
elseif mode == screwdriver.ROTATE_AXIS then
|
|
|
|
axis = axis + 1
|
|
|
|
if axis > 6 then
|
|
|
|
axis = 1
|
|
|
|
end
|
|
|
|
face = 1
|
|
|
|
else
|
|
|
|
return param2
|
|
|
|
end
|
|
|
|
return rotations[axis][face]
|
|
|
|
end
|
2012-12-26 22:54:28 +01:00
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local function piston_rotate(pos, node, _, mode)
|
|
|
|
node.param2 = rotate(node.param2, mode)
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
mesecon.execute_autoconnect_hooks_now(pos, node)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function piston_rotate_on(pos, node, player, mode)
|
|
|
|
local pistonspec = get_pistonspec(node.name, "onname")
|
|
|
|
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
|
|
|
|
local pusher_pos = vector.add(dir, pos)
|
|
|
|
local pusher_node = minetest.get_node(pusher_pos)
|
|
|
|
if pusher_node.name ~= pistonspec.pusher then
|
|
|
|
return piston_rotate(pos, node, nil, mode)
|
|
|
|
end
|
|
|
|
if mode == screwdriver.ROTATE_FACE then
|
|
|
|
piston_rotate(pusher_pos, pusher_node, nil, mode)
|
|
|
|
return piston_rotate(pos, node, nil, mode)
|
|
|
|
elseif mode ~= screwdriver.ROTATE_AXIS then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local player_name = player and player:is_player() and player:get_player_name() or ""
|
|
|
|
local ok, dir_after, pusher_pos_after
|
|
|
|
for i = 1, 5 do
|
|
|
|
node.param2 = rotate(node.param2, mode)
|
|
|
|
dir_after = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
|
|
|
|
pusher_pos_after = vector.add(dir_after, pos)
|
|
|
|
local pusher_pos_after_node_name = minetest.get_node(pusher_pos_after).name
|
|
|
|
local pusher_pos_after_node_def = minetest.registered_nodes[pusher_pos_after_node_name]
|
|
|
|
if pusher_pos_after_node_def and pusher_pos_after_node_def.buildable_to and
|
|
|
|
not minetest.is_protected(pusher_pos_after, player_name) then
|
|
|
|
ok = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not ok then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
pusher_node.param2 = node.param2
|
|
|
|
minetest.remove_node(pusher_pos)
|
|
|
|
minetest.set_node(pusher_pos_after, pusher_node)
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
mesecon.execute_autoconnect_hooks_now(pos, node)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function piston_rotate_pusher(pos, node, player, mode)
|
|
|
|
local pistonspec = get_pistonspec(node.name, "pusher")
|
|
|
|
local piston_pos = vector.add(pos, minetest.facedir_to_dir(node.param2))
|
|
|
|
local piston_node = minetest.get_node(piston_pos)
|
|
|
|
if piston_node.name ~= pistonspec.onname then
|
|
|
|
minetest.remove_node(pos) -- Make it possible to remove alone pushers.
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return piston_rotate_on(piston_pos, piston_node, player, mode)
|
|
|
|
end
|
|
|
|
|
2019-09-21 01:04:52 +02:00
|
|
|
local function piston_punch(pos, node, player)
|
|
|
|
local player_name = player and player.get_player_name and player:get_player_name()
|
|
|
|
if mesecon.mvps_claim(pos, player_name) then
|
|
|
|
minetest.chat_send_player(player_name, "Reclaimed piston")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
|
|
|
|
-- Boxes:
|
2012-12-26 22:54:28 +01: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},
|
2017-10-08 18:21:19 +02:00
|
|
|
},
|
2012-12-26 22:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local piston_on_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-.5, -.5, -.5 + pt, .5, .5, .5}
|
2017-10-08 18:21:19 +02:00
|
|
|
},
|
2012-12-26 22:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
-- Normal (non-sticky) Pistons:
|
2012-12-26 22:54:28 +01:00
|
|
|
-- 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"
|
2017-10-08 18:21:19 +02:00
|
|
|
},
|
2012-12-26 22:54:28 +01:00
|
|
|
groups = {cracky = 3},
|
2012-12-16 01:12:20 +01:00
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-12-26 22:54:28 +01:00
|
|
|
after_place_node = piston_orientate,
|
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,
|
2017-10-08 18:21:19 +02:00
|
|
|
rules = piston_get_rules,
|
2017-10-07 00:44:49 +02:00
|
|
|
}},
|
2019-09-21 01:04:52 +02:00
|
|
|
on_punch = piston_punch,
|
2017-10-08 18:21:19 +02:00
|
|
|
on_rotate = piston_rotate,
|
2017-10-07 00:44:49 +02:00
|
|
|
on_blast = mesecon.on_blastnode,
|
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", {
|
2017-10-08 18:21:19 +02:00
|
|
|
description = "Activated Piston Base",
|
2012-12-26 22:54:28 +01:00
|
|
|
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"
|
2017-10-08 18:21:19 +02:00
|
|
|
},
|
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",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2013-01-20 13:01:40 +01:00
|
|
|
drop = "mesecons_pistons:piston_normal_off",
|
2018-12-21 20:02:57 +01:00
|
|
|
after_dig_node = piston_after_dig,
|
2012-12-26 22:54:28 +01:00
|
|
|
node_box = piston_on_box,
|
|
|
|
selection_box = piston_on_box,
|
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,
|
2017-10-08 18:21:19 +02:00
|
|
|
rules = piston_get_rules,
|
2017-10-07 00:44:49 +02:00
|
|
|
}},
|
2017-10-08 18:21:19 +02:00
|
|
|
on_rotate = piston_rotate_on,
|
2017-10-07 00:44:49 +02:00
|
|
|
on_blast = mesecon.on_blastnode,
|
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", {
|
2017-10-08 18:21:19 +02:00
|
|
|
description = "Piston Pusher",
|
2012-12-16 01:12:20 +01:00
|
|
|
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"
|
2017-10-08 18:21:19 +02:00
|
|
|
},
|
|
|
|
groups = {not_in_creative_inventory = 1},
|
2012-12-16 01:12:20 +01:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-12-16 01:12:20 +01:00
|
|
|
diggable = false,
|
2012-12-26 22:54:28 +01:00
|
|
|
selection_box = piston_pusher_box,
|
|
|
|
node_box = piston_pusher_box,
|
2017-10-08 18:21:19 +02:00
|
|
|
on_rotate = piston_rotate_pusher,
|
2017-10-07 00:44:49 +02:00
|
|
|
drop = "",
|
2018-01-28 20:56:42 +01:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2012-12-16 01:12:20 +01:00
|
|
|
})
|
|
|
|
|
2012-12-26 22:54:28 +01:00
|
|
|
-- Sticky ones
|
|
|
|
-- 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"
|
2017-10-08 18:21:19 +02:00
|
|
|
},
|
2012-12-26 22:54:28 +01:00
|
|
|
groups = {cracky = 3},
|
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-12-26 22:54:28 +01:00
|
|
|
after_place_node = piston_orientate,
|
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,
|
2017-10-08 18:21:19 +02:00
|
|
|
rules = piston_get_rules,
|
2017-10-07 00:44:49 +02:00
|
|
|
}},
|
2019-09-21 01:04:52 +02:00
|
|
|
on_punch = piston_punch,
|
2017-10-08 18:21:19 +02:00
|
|
|
on_rotate = piston_rotate,
|
2017-10-07 00:44:49 +02:00
|
|
|
on_blast = mesecon.on_blastnode,
|
2012-12-26 22:54:28 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
-- onstate
|
|
|
|
minetest.register_node("mesecons_pistons:piston_sticky_on", {
|
2017-10-08 18:21:19 +02:00
|
|
|
description = "Activated Sticky Piston Base",
|
2012-12-26 22:54:28 +01:00
|
|
|
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"
|
2017-10-08 18:21:19 +02:00
|
|
|
},
|
2012-12-26 22:54:28 +01:00
|
|
|
groups = {cracky = 3, not_in_creative_inventory = 1},
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2015-02-05 20:26:51 +01:00
|
|
|
drop = "mesecons_pistons:piston_sticky_off",
|
2018-12-21 20:02:57 +01:00
|
|
|
after_dig_node = piston_after_dig,
|
2012-12-26 22:54:28 +01:00
|
|
|
node_box = piston_on_box,
|
|
|
|
selection_box = piston_on_box,
|
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,
|
2017-10-08 18:21:19 +02:00
|
|
|
rules = piston_get_rules,
|
2017-10-07 00:44:49 +02:00
|
|
|
}},
|
2017-10-08 18:21:19 +02:00
|
|
|
on_rotate = piston_rotate_on,
|
2017-10-07 00:44:49 +02:00
|
|
|
on_blast = mesecon.on_blastnode,
|
2012-12-26 22:54:28 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
-- pusher
|
2012-12-16 01:12:20 +01:00
|
|
|
minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
|
2017-10-08 18:21:19 +02:00
|
|
|
description = "Sticky Piston Pusher",
|
2012-12-16 01:12:20 +01:00
|
|
|
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"
|
2017-10-08 18:21:19 +02:00
|
|
|
},
|
|
|
|
groups = {not_in_creative_inventory = 1},
|
2012-12-16 01:12:20 +01:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-12-16 01:12:20 +01:00
|
|
|
diggable = false,
|
2012-12-26 22:54:28 +01:00
|
|
|
selection_box = piston_pusher_box,
|
|
|
|
node_box = piston_pusher_box,
|
2017-10-08 18:21:19 +02:00
|
|
|
on_rotate = piston_rotate_pusher,
|
2017-10-07 00:44:49 +02:00
|
|
|
drop = "",
|
2018-01-28 20:56:42 +01:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
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
|
2017-10-08 18:21:19 +02:00
|
|
|
local function piston_pusher_get_stopper(node, dir, stack, stackid)
|
2012-12-26 22:54:28 +01:00
|
|
|
if (stack[stackid + 1]
|
2017-10-08 18:21:19 +02:00
|
|
|
and stack[stackid + 1].node.name == get_pistonspec(node.name, "pusher").onname
|
2012-12-26 22:54:28 +01:00
|
|
|
and stack[stackid + 1].node.param2 == node.param2)
|
|
|
|
or (stack[stackid - 1]
|
2017-10-08 18:21:19 +02:00
|
|
|
and stack[stackid - 1].node.name == get_pistonspec(node.name, "pusher").onname
|
2012-12-26 22:54:28 +01:00
|
|
|
and stack[stackid - 1].node.param2 == node.param2) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local function piston_pusher_up_down_get_stopper(node, dir, stack, stackid)
|
2012-12-26 22:54:28 +01:00
|
|
|
if (stack[stackid + 1]
|
2017-10-08 18:21:19 +02:00
|
|
|
and stack[stackid + 1].node.name == get_pistonspec(node.name, "pusher").onname)
|
2012-12-26 22:54:28 +01:00
|
|
|
or (stack[stackid - 1]
|
2017-10-08 18:21:19 +02:00
|
|
|
and stack[stackid - 1].node.name == get_pistonspec(node.name, "pusher").onname) then
|
2012-12-26 22:54:28 +01:00
|
|
|
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]
|
2017-10-08 18:21:19 +02:00
|
|
|
and stack[stackid + 1].node.name == get_pistonspec(node.name, "onname").pusher)
|
2012-12-26 22:54:28 +01:00
|
|
|
or (stack[stackid - 1]
|
2017-10-08 18:21:19 +02:00
|
|
|
and stack[stackid - 1].node.name == get_pistonspec(node.name, "onname").pusher) then
|
2012-12-26 22:54:28 +01:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-10-08 18:21:19 +02:00
|
|
|
local function piston_get_stopper(node, dir, stack, stackid)
|
|
|
|
local pistonspec = get_pistonspec(node.name, "onname")
|
|
|
|
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
|
|
|
|
local pusherpos = vector.add(stack[stackid].pos, dir)
|
2013-12-01 04:13:00 +01:00
|
|
|
local pushernode = minetest.get_node(pusherpos)
|
2017-10-08 18:21:19 +02:00
|
|
|
if pistonspec.pusher == pushernode.name then
|
2012-12-27 19:14:54 +01:00
|
|
|
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 = {
|
2017-10-08 18:21:19 +02:00
|
|
|
{"group:wood", "group:wood", "group:wood"},
|
|
|
|
{"default:cobble", "default:steel_ingot", "default:cobble"},
|
2012-12-16 01:12:20 +01:00
|
|
|
{"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
|
|
|
})
|
2017-10-08 18:21:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- load legacy code
|
|
|
|
dofile(minetest.get_modpath("mesecons_pistons")..DIR_DELIM.."legacy.lua")
|