Fixes suggested by HybridDog
This commit is contained in:
parent
2693a0550d
commit
4c850852d6
|
@ -49,6 +49,10 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical)
|
|||
-- ### Step 1: Push nodes in front ###
|
||||
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
|
||||
|
@ -57,7 +61,7 @@ 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:from_table(meta:to_table())
|
||||
meta2:set_string("owner", owner)
|
||||
minetest.remove_node(pos)
|
||||
mesecon.on_dignode(pos, node)
|
||||
mesecon.on_placenode(frontpos, node)
|
||||
|
@ -87,7 +91,15 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical)
|
|||
rules = mesecon.rules.default,
|
||||
}}
|
||||
|
||||
def.after_place_node = mesecon.mvps_mark_owner
|
||||
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)
|
||||
|
|
|
@ -133,18 +133,30 @@ function mesecon.mvps_get_stack(pos, dir, maximum, all_pull_sticky)
|
|||
return nodes
|
||||
end
|
||||
|
||||
function mesecon.mvps_mark_owner(pos, placer)
|
||||
function mesecon.mvps_set_owner(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = placer and placer.get_player_name and placer:get_player_name()
|
||||
if owner and owner ~= "" then
|
||||
meta:set_string("owner", owner)
|
||||
meta:set_string("infotext", "Owned by " .. owner)
|
||||
else
|
||||
meta:set_string("owner", "$unknown") -- to distinguish from older pistons
|
||||
meta:set_string("infotext", "Unowned")
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon.mvps_claim(pos, player_name)
|
||||
if not player_name or player_name == "" then return end
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_string("infotext") == "" then return end
|
||||
if meta:get_string("owner") == player_name then return end -- already owned
|
||||
if minetest.is_protected(pos, player_name) then
|
||||
minetest.chat_send_player(player_name, "Can't reclaim: protected")
|
||||
return
|
||||
end
|
||||
meta:set_string("owner", player_name)
|
||||
meta:set_string("infotext", "")
|
||||
return true
|
||||
end
|
||||
|
||||
local function add_pos(positions, pos)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
positions[hash] = pos
|
||||
|
@ -170,7 +182,6 @@ local function are_protected(positions, player_name)
|
|||
local is_protected = minetest.is_protected
|
||||
for _, pos in pairs(positions) do
|
||||
if is_protected(pos, name) then
|
||||
minetest.record_protection_violation(pos, player_name)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -215,7 +226,7 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti
|
|||
add_pos(protection_check_set, vector.add(n.pos, movedir))
|
||||
end
|
||||
if are_protected(protection_check_set, player_name) then
|
||||
return
|
||||
return false, "protected"
|
||||
end
|
||||
|
||||
-- remove all nodes
|
||||
|
|
|
@ -89,6 +89,9 @@ local piston_on = function(pos, node)
|
|||
local meta = minetest.get_meta(pos)
|
||||
local success, stack, oldstack = mesecon.mvps_push(pusher_pos, dir, max_push, meta:get_string("owner"))
|
||||
if not success then
|
||||
if stack == "protected" then
|
||||
meta:set_string("infotext", "Can't extend: protected area on the way")
|
||||
end
|
||||
return
|
||||
end
|
||||
minetest.swap_node(pos, {param2 = node.param2, name = pistonspec.onname})
|
||||
|
@ -127,7 +130,7 @@ local orientations = {
|
|||
}
|
||||
|
||||
local function piston_orientate(pos, placer)
|
||||
mesecon.mvps_mark_owner(pos, placer)
|
||||
mesecon.mvps_set_owner(pos, placer)
|
||||
if not placer then
|
||||
return
|
||||
end
|
||||
|
@ -240,6 +243,13 @@ local function piston_rotate_pusher(pos, node, player, mode)
|
|||
return piston_rotate_on(piston_pos, piston_node, player, mode)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
|
||||
-- Boxes:
|
||||
|
||||
|
@ -282,6 +292,7 @@ minetest.register_node("mesecons_pistons:piston_normal_off", {
|
|||
action_on = piston_on,
|
||||
rules = piston_get_rules,
|
||||
}},
|
||||
on_punch = piston_punch,
|
||||
on_rotate = piston_rotate,
|
||||
on_blast = mesecon.on_blastnode,
|
||||
})
|
||||
|
@ -360,6 +371,7 @@ minetest.register_node("mesecons_pistons:piston_sticky_off", {
|
|||
action_on = piston_on,
|
||||
rules = piston_get_rules,
|
||||
}},
|
||||
on_punch = piston_punch,
|
||||
on_rotate = piston_rotate,
|
||||
on_blast = mesecon.on_blastnode,
|
||||
})
|
||||
|
|
|
@ -38,7 +38,7 @@ mesecon.luacontroller_lightweight_interrupts (Lightweight interrupts) bool false
|
|||
# - restrict: disallow legacy MVPS
|
||||
# Note that new unowned (e.g. machine-placed) MVPS are always
|
||||
# handled as in `normal` mode.
|
||||
mesecon.mvps_protection_mode (MVPS [movestones, pistons] protection handling) enum normal normal,compat,ignore,restrict
|
||||
mesecon.mvps_protection_mode (MVPS [movestones, pistons] protection handling) enum compat normal,compat,ignore,restrict
|
||||
|
||||
[mesecons_movestones]
|
||||
|
||||
|
|
Loading…
Reference in New Issue