forked from VoxeLibre/VoxeLibre
Replaced positions check with an area check.
This one is using the minetest.is_area_protected so it should work faster. It also doesnt require the user to manually add all the points that should be checked so its nicer to use.
This commit is contained in:
parent
b0d9eed3e1
commit
64a7f76d5b
|
@ -729,28 +729,28 @@ function mcl_util.set_bone_position(obj, bone, pos, rot)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[Check for a protection violation on any of the given positions.
|
--[[Check for a protection violation in a given area.
|
||||||
--
|
--
|
||||||
-- @param positions A table of position tables to check for protection violation.
|
-- Applies is_protected() to a 3D lattice of points in the defined volume. The points are spaced
|
||||||
|
-- evenly throughout the volume and have a spacing similar to, but no larger than, "interval".
|
||||||
|
--
|
||||||
|
-- @param pos1 A position table of the area volume's first edge.
|
||||||
|
-- @param pos2 A position table of the area volume's second edge.
|
||||||
-- @param player The player performing the action.
|
-- @param player The player performing the action.
|
||||||
-- @param create_log Default: False. Should a log message be created on violation detection.
|
-- @param interval Optional. Max spacing between checked points at the volume.
|
||||||
|
-- Default: Same as minetest.is_area_protected.
|
||||||
--
|
--
|
||||||
-- @return true on protection violation detection. false otherwise.
|
-- @return true on protection violation detection. false otherwise.
|
||||||
|
--
|
||||||
|
-- @notes *All corners and edges of the defined volume are checked.
|
||||||
]]
|
]]
|
||||||
function mcl_util.check_positions_protection(positions, player, create_log)
|
function mcl_util.check_area_protection(pos1, pos2, player, interval)
|
||||||
create_log = create_log or false
|
|
||||||
local name = player and player:get_player_name() or ""
|
local name = player and player:get_player_name() or ""
|
||||||
|
|
||||||
for i = 1, #positions do
|
local protected_pos = minetest.is_area_protected(pos1, pos2, name, interval)
|
||||||
if minetest.is_protected(positions[i], name) then
|
if protected_pos then
|
||||||
if create_log then
|
minetest.record_protection_violation(protected_pos, name)
|
||||||
minetest.log("action", name .. " tried violating protection at position "
|
return true
|
||||||
.. minetest.pos_to_string(positions[i]))
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.record_protection_violation(positions[i], name)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -759,21 +759,14 @@ end
|
||||||
--[[Check for a protection violation on a single position.
|
--[[Check for a protection violation on a single position.
|
||||||
--
|
--
|
||||||
-- @param position A position table to check for protection violation.
|
-- @param position A position table to check for protection violation.
|
||||||
-- @param player See mcl_util.check_positions_protection.
|
-- @param player The player performing the action.
|
||||||
-- @param create_log See mcl_util.check_positions_protection.
|
|
||||||
--
|
--
|
||||||
-- @return See check_positions_protection.
|
-- @return true on protection violation detection. false otherwise.
|
||||||
]]
|
]]
|
||||||
function mcl_util.check_position_protection(position, player, create_log)
|
function mcl_util.check_position_protection(position, player)
|
||||||
create_log = create_log or false
|
|
||||||
local name = player and player:get_player_name() or ""
|
local name = player and player:get_player_name() or ""
|
||||||
|
|
||||||
if minetest.is_protected(position, name) then
|
if minetest.is_protected(position, name) then
|
||||||
if create_log then
|
|
||||||
minetest.log("action", name .. " tried violating protection at position "
|
|
||||||
.. minetest.pos_to_string(position))
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.record_protection_violation(position, name)
|
minetest.record_protection_violation(position, name)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,7 @@ local function seagrass_on_place(itemstack, placer, pointed_thing)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
if mcl_util.check_positions_protection({pos_under, pos_above}, placer, true) then
|
if mcl_util.check_area_protection(pos_under, pos_above, placer) then
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue