2012-03-05 19:21:26 +01:00
|
|
|
-- MOVESTONE
|
2012-12-09 00:42:30 +01:00
|
|
|
-- Non-sticky:
|
|
|
|
-- Moves along mesecon lines
|
|
|
|
-- Pushes all blocks in front of it
|
|
|
|
--
|
|
|
|
-- Sticky one
|
|
|
|
-- Moves along mesecon lines
|
|
|
|
-- Pushes all block in front of it
|
|
|
|
-- Pull all blocks in its back
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2017-10-08 18:41:22 +02:00
|
|
|
-- settings:
|
|
|
|
local timer_interval = 1 / mesecon.setting("movestone_speed", 3)
|
|
|
|
local max_push = mesecon.setting("movestone_max_push", 50)
|
|
|
|
local max_pull = mesecon.setting("movestone_max_pull", 50)
|
|
|
|
|
|
|
|
-- helper functions:
|
|
|
|
local function get_movestone_direction(rulename, is_vertical)
|
|
|
|
if is_vertical then
|
|
|
|
if rulename.z > 0 then
|
|
|
|
return {x = 0, y = -1, z = 0}
|
|
|
|
elseif rulename.z < 0 then
|
|
|
|
return {x = 0, y = 1, z = 0}
|
|
|
|
elseif rulename.x > 0 then
|
|
|
|
return {x = 0, y = -1, z = 0}
|
|
|
|
elseif rulename.x < 0 then
|
|
|
|
return {x = 0, y = 1, z = 0}
|
2012-06-16 03:29:43 +02:00
|
|
|
end
|
2017-10-08 18:41:22 +02:00
|
|
|
else
|
|
|
|
if rulename.z > 0 then
|
|
|
|
return {x = -1, y = 0, z = 0}
|
|
|
|
elseif rulename.z < 0 then
|
|
|
|
return {x = 1, y = 0, z = 0}
|
|
|
|
elseif rulename.x > 0 then
|
|
|
|
return {x = 0, y = 0, z = -1}
|
|
|
|
elseif rulename.x < 0 then
|
|
|
|
return {x = 0, y = 0, z = 1}
|
2012-06-16 03:29:43 +02:00
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-08 18:41:22 +02:00
|
|
|
-- registration functions:
|
|
|
|
function mesecon.register_movestone(name, def, is_sticky, is_vertical)
|
|
|
|
local function movestone_move(pos, node, rulename)
|
|
|
|
local direction = get_movestone_direction(rulename, is_vertical)
|
2015-02-14 11:54:27 +01:00
|
|
|
local frontpos = vector.add(pos, direction)
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2015-02-14 11:54:27 +01:00
|
|
|
-- ### Step 1: Push nodes in front ###
|
2017-10-08 18:41:22 +02:00
|
|
|
local success, stack, oldstack = mesecon.mvps_push(frontpos, direction, max_push)
|
|
|
|
if not success then
|
|
|
|
minetest.get_node_timer(pos):start(timer_interval)
|
2012-06-16 03:29:43 +02:00
|
|
|
return
|
2012-06-16 18:53:14 +02:00
|
|
|
end
|
2017-10-08 18:41:22 +02:00
|
|
|
mesecon.mvps_move_objects(frontpos, direction, oldstack)
|
2012-06-16 18:53:14 +02:00
|
|
|
|
2015-02-14 11:54:27 +01:00
|
|
|
-- ### Step 2: Move the movestone ###
|
|
|
|
minetest.set_node(frontpos, node)
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
mesecon.on_dignode(pos, node)
|
|
|
|
mesecon.on_placenode(frontpos, node)
|
2017-10-08 18:41:22 +02:00
|
|
|
minetest.get_node_timer(frontpos):start(timer_interval)
|
2015-02-14 11:54:27 +01:00
|
|
|
|
|
|
|
-- ### Step 3: If sticky, pull stack behind ###
|
2018-07-23 12:14:05 +02:00
|
|
|
if is_sticky then
|
|
|
|
local backpos = vector.subtract(pos, direction)
|
|
|
|
success, stack, oldstack = mesecon.mvps_pull_all(backpos, direction, max_pull)
|
|
|
|
if success then
|
|
|
|
mesecon.mvps_move_objects(backpos, vector.multiply(direction, -1), oldstack, -1)
|
|
|
|
end
|
2013-03-14 18:44:49 +01:00
|
|
|
end
|
2018-07-23 12:14:05 +02:00
|
|
|
|
|
|
|
-- ### Step 4: Let things fall ###
|
|
|
|
minetest.check_for_falling(vector.add(pos, {x=0, y=1, z=0}))
|
2015-02-14 11:54:27 +01:00
|
|
|
end
|
2012-06-16 18:53:14 +02:00
|
|
|
|
2017-10-31 22:50:39 +01:00
|
|
|
def.is_ground_content = false
|
|
|
|
|
2015-02-14 11:54:27 +01:00
|
|
|
def.mesecons = {effector = {
|
2017-10-08 18:41:22 +02:00
|
|
|
action_on = function(pos, node, rulename)
|
|
|
|
if rulename and not minetest.get_node_timer(pos):is_started() then
|
|
|
|
movestone_move(pos, node, rulename)
|
2015-02-14 11:54:27 +01:00
|
|
|
end
|
|
|
|
end,
|
2017-10-08 18:41:22 +02:00
|
|
|
rules = mesecon.rules.default,
|
2015-02-14 11:54:27 +01:00
|
|
|
}}
|
|
|
|
|
2017-10-08 18:41:22 +02:00
|
|
|
def.on_timer = function(pos, elapsed)
|
|
|
|
local sourcepos = mesecon.is_powered(pos)
|
|
|
|
if not sourcepos then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local rulename = vector.subtract(sourcepos[1], pos)
|
|
|
|
mesecon.activate(pos, minetest.get_node(pos), rulename, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def.on_blast = mesecon.on_blastnode
|
2015-02-14 11:54:27 +01:00
|
|
|
|
|
|
|
minetest.register_node(name, def)
|
|
|
|
end
|
|
|
|
|
2017-10-08 18:41:22 +02:00
|
|
|
|
|
|
|
-- registration:
|
2015-02-14 11:54:27 +01:00
|
|
|
mesecon.register_movestone("mesecons_movestones:movestone", {
|
2017-10-08 18:41:22 +02:00
|
|
|
tiles = {
|
|
|
|
"jeija_movestone_side.png",
|
|
|
|
"jeija_movestone_side.png",
|
|
|
|
"jeija_movestone_arrows.png^[transformFX",
|
|
|
|
"jeija_movestone_arrows.png^[transformFX",
|
|
|
|
"jeija_movestone_arrows.png",
|
|
|
|
"jeija_movestone_arrows.png",
|
|
|
|
},
|
|
|
|
groups = {cracky = 3},
|
|
|
|
description = "Movestone",
|
|
|
|
sounds = default.node_sound_stone_defaults()
|
|
|
|
}, false, false)
|
|
|
|
|
|
|
|
mesecon.register_movestone("mesecons_movestones:sticky_movestone", {
|
|
|
|
tiles = {
|
|
|
|
"jeija_movestone_side.png",
|
|
|
|
"jeija_movestone_side.png",
|
|
|
|
"jeija_sticky_movestone.png^[transformFX",
|
|
|
|
"jeija_sticky_movestone.png^[transformFX",
|
|
|
|
"jeija_sticky_movestone.png",
|
|
|
|
"jeija_sticky_movestone.png",
|
|
|
|
},
|
|
|
|
groups = {cracky = 3},
|
|
|
|
description = "Sticky Movestone",
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
}, true, false)
|
|
|
|
|
|
|
|
mesecon.register_movestone("mesecons_movestones:movestone_vertical", {
|
|
|
|
tiles = {
|
|
|
|
"jeija_movestone_side.png",
|
|
|
|
"jeija_movestone_side.png",
|
|
|
|
"jeija_movestone_arrows.png^[transformFXR90",
|
|
|
|
"jeija_movestone_arrows.png^[transformR90",
|
|
|
|
"jeija_movestone_arrows.png^[transformFXR90",
|
|
|
|
"jeija_movestone_arrows.png^[transformR90",
|
|
|
|
},
|
|
|
|
groups = {cracky = 3},
|
|
|
|
description = "Vertical Movestone",
|
2015-02-14 11:54:27 +01:00
|
|
|
sounds = default.node_sound_stone_defaults()
|
2017-10-08 18:41:22 +02:00
|
|
|
}, false, true)
|
|
|
|
|
|
|
|
mesecon.register_movestone("mesecons_movestones:sticky_movestone_vertical", {
|
|
|
|
tiles = {
|
|
|
|
"jeija_movestone_side.png",
|
|
|
|
"jeija_movestone_side.png",
|
|
|
|
"jeija_sticky_movestone.png^[transformFXR90",
|
|
|
|
"jeija_sticky_movestone.png^[transformR90",
|
|
|
|
"jeija_sticky_movestone.png^[transformFXR90",
|
|
|
|
"jeija_sticky_movestone.png^[transformR90",
|
|
|
|
},
|
|
|
|
groups = {cracky = 3},
|
|
|
|
description = "Vertical Sticky Movestone",
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
}, true, true)
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2017-10-08 18:41:22 +02:00
|
|
|
|
|
|
|
-- crafting:
|
|
|
|
-- base recipe:
|
2012-03-05 19:21:26 +01:00
|
|
|
minetest.register_craft({
|
2013-04-28 12:40:08 +02:00
|
|
|
output = "mesecons_movestones:movestone 2",
|
2012-03-05 19:21:26 +01:00
|
|
|
recipe = {
|
2013-04-28 12:40:08 +02:00
|
|
|
{"default:stone", "default:stone", "default:stone"},
|
|
|
|
{"group:mesecon_conductor_craftable", "group:mesecon_conductor_craftable", "group:mesecon_conductor_craftable"},
|
|
|
|
{"default:stone", "default:stone", "default:stone"},
|
2012-03-05 19:21:26 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-10-08 18:41:22 +02:00
|
|
|
-- conversation:
|
|
|
|
minetest.register_craft({
|
|
|
|
type = "shapeless",
|
|
|
|
output = "mesecons_movestones:movestone",
|
|
|
|
recipe = {"mesecons_movestones:movestone_vertical"},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = "shapeless",
|
|
|
|
output = "mesecons_movestones:movestone_vertical",
|
|
|
|
recipe = {"mesecons_movestones:movestone"},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = "shapeless",
|
|
|
|
output = "mesecons_movestones:sticky_movestone",
|
|
|
|
recipe = {"mesecons_movestones:sticky_movestone_vertical"},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = "shapeless",
|
|
|
|
output = "mesecons_movestones:sticky_movestone_vertical",
|
|
|
|
recipe = {"mesecons_movestones:sticky_movestone"},
|
|
|
|
})
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2017-10-08 18:41:22 +02:00
|
|
|
-- make sticky:
|
2012-03-05 19:21:26 +01:00
|
|
|
minetest.register_craft({
|
2017-02-23 18:11:24 +01:00
|
|
|
output = "mesecons_movestones:sticky_movestone",
|
2012-03-05 19:21:26 +01:00
|
|
|
recipe = {
|
2013-04-28 12:40:08 +02:00
|
|
|
{"mesecons_materials:glue", "mesecons_movestones:movestone", "mesecons_materials:glue"},
|
2012-03-05 19:21:26 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-10-08 18:41:22 +02:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "mesecons_movestones:sticky_movestone_vertical",
|
|
|
|
recipe = {
|
|
|
|
{"mesecons_materials:glue"},
|
|
|
|
{"mesecons_movestones:movestone_vertical"},
|
|
|
|
{"mesecons_materials:glue"},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- legacy code:
|
|
|
|
minetest.register_alias("mesecons_movestones:movestone_active",
|
|
|
|
"mesecons_movestones:movestone")
|
|
|
|
minetest.register_alias("mesecons_movestones:sticky_movestone_active",
|
|
|
|
"mesecons_movestones:sticky_movestone")
|