2021-07-26 16:50:04 -04:00
|
|
|
--[[
|
|
|
|
Copyright (C) 2021 Jude Melton-Houghton
|
|
|
|
|
|
|
|
This file is part of area_containers. It implements the protection layer.
|
|
|
|
|
|
|
|
area_containers is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
area_containers is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with area_containers. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
]]
|
|
|
|
|
|
|
|
--[[
|
|
|
|
OVERVIEW
|
|
|
|
|
|
|
|
The protection layer extends one block above and below the inside Y-level
|
|
|
|
block. It excludes the insides (but walls are protected.)
|
|
|
|
]]
|
|
|
|
|
2021-08-23 18:49:20 -04:00
|
|
|
local use = ...
|
|
|
|
local floor_blocksize = use("misc", {"floor_blocksize"})
|
2021-08-26 08:38:51 -04:00
|
|
|
local INSIDE_Y_LEVEL, get_params_from_inside = use("relation", {
|
|
|
|
"INSIDE_Y_LEVEL", "get_params_from_inside",
|
2021-08-23 18:49:20 -04:00
|
|
|
})
|
2021-07-26 16:50:04 -04:00
|
|
|
|
2021-08-23 09:20:24 -04:00
|
|
|
-- The minimum and maximum layers at which the protection applies.
|
2021-08-26 08:38:51 -04:00
|
|
|
local MIN_APPLICABLE_Y = INSIDE_Y_LEVEL - 16
|
|
|
|
local MAX_APPLICABLE_Y = INSIDE_Y_LEVEL + 16 + 15
|
2021-08-09 14:52:19 -04:00
|
|
|
|
2021-07-26 16:50:04 -04:00
|
|
|
-- Checks whether the position is protected only according to area_containers.
|
|
|
|
-- See the overview for this file.
|
2021-08-09 07:53:46 -04:00
|
|
|
local function is_area_containers_protected(pos)
|
2021-08-09 14:52:19 -04:00
|
|
|
-- Check that the position is within the protected level:
|
|
|
|
local y = pos.y
|
2021-08-26 08:38:51 -04:00
|
|
|
if y >= MIN_APPLICABLE_Y and y <= MAX_APPLICABLE_Y then
|
2021-08-09 14:52:19 -04:00
|
|
|
-- The minimum position of the block containing pos:
|
2021-08-23 18:49:20 -04:00
|
|
|
local block_min_pos = vector.apply(pos, floor_blocksize)
|
|
|
|
if get_params_from_inside(block_min_pos) then
|
2021-07-26 16:50:04 -04:00
|
|
|
-- The position is in an inside block.
|
|
|
|
-- Protect the walls:
|
|
|
|
local block_offset = vector.subtract(pos, block_min_pos)
|
|
|
|
if block_offset.x == 0 or block_offset.x == 15 or
|
|
|
|
block_offset.y == 0 or block_offset.y == 15 or
|
|
|
|
block_offset.z == 0 or block_offset.z == 15 then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- Non-inside blocks in the layer are protected.
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2021-08-23 09:20:24 -04:00
|
|
|
local old_is_protected = minetest.is_protected
|
|
|
|
function minetest.is_protected(pos, name)
|
2021-07-26 16:50:04 -04:00
|
|
|
-- Apply our mod's protection unless the player can bypass it:
|
2021-08-09 14:52:19 -04:00
|
|
|
if is_area_containers_protected(pos) and
|
|
|
|
not minetest.check_player_privs(name, "protection_bypass") then
|
2021-07-26 16:50:04 -04:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
return old_is_protected(pos, name)
|
|
|
|
end
|