summaryrefslogtreecommitdiff
path: root/mesecons_movestones
diff options
context:
space:
mode:
Diffstat (limited to 'mesecons_movestones')
-rw-r--r--mesecons_movestones/init.lua22
1 files changed, 20 insertions, 2 deletions
diff --git a/mesecons_movestones/init.lua b/mesecons_movestones/init.lua
index cd82294..49ac2b5 100644
--- a/mesecons_movestones/init.lua
+++ b/mesecons_movestones/init.lua
@@ -43,10 +43,16 @@ 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)
local frontpos = vector.add(pos, direction)
+ local meta = minetest.get_meta(pos)
+ local owner = meta:get_string("owner")
-- ### Step 1: Push nodes in front ###
- local success, stack, oldstack = mesecon.mvps_push(frontpos, direction, max_push)
+ local success, stack, oldstack = mesecon.mvps_push(frontpos, direction, max_push, owner)
if not success then
+ if stack == "protected" then
+ meta:set_string("infotext", "Can't move: protected area on the way")
+ return
+ end
minetest.get_node_timer(pos):start(timer_interval)
return
end
@@ -54,6 +60,8 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical)
-- ### Step 2: Move the movestone ###
minetest.set_node(frontpos, node)
+ local meta2 = minetest.get_meta(frontpos)
+ meta2:set_string("owner", owner)
minetest.remove_node(pos)
mesecon.on_dignode(pos, node)
mesecon.on_placenode(frontpos, node)
@@ -62,7 +70,7 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical)
-- ### Step 3: If sticky, pull stack behind ###
if is_sticky then
local backpos = vector.subtract(pos, direction)
- success, stack, oldstack = mesecon.mvps_pull_all(backpos, direction, max_pull)
+ success, stack, oldstack = mesecon.mvps_pull_all(backpos, direction, max_pull, owner)
if success then
mesecon.mvps_move_objects(backpos, vector.multiply(direction, -1), oldstack, -1)
end
@@ -83,6 +91,16 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical)
rules = mesecon.rules.default,
}}
+ def.after_place_node = mesecon.mvps_set_owner
+
+ def.on_punch = function(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.get_node_timer(pos):start(timer_interval)
+ minetest.chat_send_player(player_name, "Reclaimed movestone")
+ end
+ end
+
def.on_timer = function(pos, elapsed)
local sourcepos = mesecon.is_powered(pos)
if not sourcepos then