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
|
|
|
|
2022-12-01 18:33:19 +01:00
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
|
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)
|
2019-09-21 01:04:52 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local owner = meta:get_string("owner")
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2015-02-14 11:54:27 +01:00
|
|
|
-- ### Step 1: Push nodes in front ###
|
2019-09-21 01:04:52 +02:00
|
|
|
local success, stack, oldstack = mesecon.mvps_push(frontpos, direction, max_push, owner)
|
2017-10-08 18:41:22 +02:00
|
|
|
if not success then
|
2019-09-21 01:04:52 +02:00
|
|
|
if stack == "protected" then
|
|
|
|
meta:set_string("infotext", "Can't move: protected area on the way")
|
|
|
|
return
|
|
|
|
end
|
2017-10-08 18:41:22 +02:00
|
|
|
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)
|
2019-09-21 01:04:52 +02:00
|
|
|
local meta2 = minetest.get_meta(frontpos)
|
|
|
|
meta2:set_string("owner", owner)
|
2015-02-14 11:54:27 +01:00
|
|
|
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)
|
2020-08-01 15:10:14 +02:00
|
|
|
minetest.sound_play("movestone", { pos = pos, max_hear_distance = 20, gain = 0.5 }, true)
|
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)
|
2022-02-12 20:12:12 +01:00
|
|
|
local success, _, oldstack = mesecon.mvps_pull_all(backpos, direction, max_pull, owner)
|
2018-07-23 12:14:05 +02:00
|
|
|
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
|
|
|
}}
|
|
|
|
|
2019-09-21 01:04:52 +02:00
|
|
|
def.after_place_node = mesecon.mvps_set_owner
|
|
|
|
|
2022-02-12 20:12:12 +01:00
|
|
|
def.on_punch = function(pos, _, player)
|
2019-09-21 01:04:52 +02:00
|
|
|
local player_name = player and player.get_player_name and player:get_player_name()
|
|
|
|
if mesecon.mvps_claim(pos, player_name) then
|
|
|
|
minetest.get_node_timer(pos):start(timer_interval)
|
|
|
|
minetest.chat_send_player(player_name, "Reclaimed movestone")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-12 20:12:12 +01:00
|
|
|
def.on_timer = function(pos)
|
2017-10-08 18:41:22 +02:00
|
|
|
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},
|
2022-12-01 18:33:19 +01:00
|
|
|
description = S("Movestone"),
|
2022-05-05 16:57:53 +02:00
|
|
|
sounds = mesecon.node_sound.stone
|
2017-10-08 18:41:22 +02:00
|
|
|
}, 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},
|
2022-12-01 18:33:19 +01:00
|
|
|
description = S("Sticky Movestone"),
|
2022-05-05 16:57:53 +02:00
|
|
|
sounds = mesecon.node_sound.stone,
|
2017-10-08 18:41:22 +02:00
|
|
|
}, 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},
|
2022-12-01 18:33:19 +01:00
|
|
|
description = S("Vertical Movestone"),
|
2022-05-05 16:57:53 +02:00
|
|
|
sounds = mesecon.node_sound.stone
|
2017-10-08 18:41:22 +02:00
|
|
|
}, false, true)
|
|
|
|
|
|
|
|
mesecon.register_movestone("mesecons_movestones:sticky_movestone_vertical", {
|
|
|
|
tiles = {
|
2018-09-08 23:35:15 +02:00
|
|
|
"jeija_movestone_side.png^(mesecons_glue.png^[opacity:127)",
|
|
|
|
"jeija_movestone_side.png^(mesecons_glue.png^[opacity:127)",
|
|
|
|
"jeija_movestone_arrows.png^[transformFXR90",
|
|
|
|
"jeija_movestone_arrows.png^[transformR90",
|
|
|
|
"jeija_movestone_arrows.png^[transformFXR90",
|
|
|
|
"jeija_movestone_arrows.png^[transformR90",
|
2017-10-08 18:41:22 +02:00
|
|
|
},
|
|
|
|
groups = {cracky = 3},
|
2022-12-01 18:33:19 +01:00
|
|
|
description = S("Vertical Sticky Movestone"),
|
2022-05-05 16:57:53 +02:00
|
|
|
sounds = mesecon.node_sound.stone,
|
2017-10-08 18:41:22 +02:00
|
|
|
}, 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 = {
|
2022-05-05 16:57:53 +02:00
|
|
|
{"mesecons_gamecompat:stone", "mesecons_gamecompat:stone", "mesecons_gamecompat:stone"},
|
2013-04-28 12:40:08 +02:00
|
|
|
{"group:mesecon_conductor_craftable", "group:mesecon_conductor_craftable", "group:mesecon_conductor_craftable"},
|
2022-05-05 16:57:53 +02:00
|
|
|
{"mesecons_gamecompat:stone", "mesecons_gamecompat:stone", "mesecons_gamecompat: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")
|