Prohibit to place Protector Blocks too close

master
MoNTE48 2020-12-12 16:52:14 +01:00
parent 0b29bb7571
commit 7044c74804
2 changed files with 14 additions and 10 deletions

View File

@ -113,5 +113,6 @@ Unknown subcommand: @1=Неизвестная подкоманда: @1
Protector Block=Защитный Блок
You are not allowed to protect that area:=Вам не разрешено защищать эту область:
You have already protected this area.=Вы уже защитили эту область.
The area from @1 to @1 has been protected as ID @1=Зона от @1 до @1 была защещена, ID @1
Protecting area @1, Owned by @1=Защищённая зона @1, Владелец: @1

View File

@ -3,13 +3,15 @@ local S = intllib.make_gettext_pair()
local radius = minetest.settings:get("areasprotector_radius") or 8
local function cyan(str)
return minetest.colorize("#00FFFF", str)
return minetest.colorize("#7CFC00", str)
end
local function red(str)
return minetest.colorize("#FF5555", str)
return minetest.colorize("#FF0000", str)
end
local vadd, vnew = vector.add, vector.new
minetest.register_node("areas:protector", {
description = S("Protector Block"),
groups = {cracky = 1},
@ -19,16 +21,12 @@ minetest.register_node("areas:protector", {
"default_stonebrick_carved.png^areas_protector_stone.png"
},
paramtype = "light",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
},
node_placement_prediction = "",
on_place = function(itemstack, player, pointed)
local pos = pointed.above
local pos1 = vector.add(pos, vector.new(radius, radius, radius))
local pos2 = vector.add(pos, vector.new(-radius, -radius, -radius))
local pos1 = vadd(pos, vnew(radius, radius, radius))
local pos2 = vadd(pos, vnew(-radius, -radius, -radius))
local name = player:get_player_name()
if not minetest.is_protected_action(pos, name) then
@ -37,6 +35,11 @@ minetest.register_node("areas:protector", {
minetest.chat_send_player(name, red(S("You are not allowed to protect that area:") .. " ") .. err)
return itemstack
end
if minetest.find_node_near(pos, 4, {"areas:protector"}) then
minetest.chat_send_player(name, red(S("You have already protected this area.")))
return itemstack
end
local id = areas:add(name, "Protector Block", pos1, pos2)
areas:save()
minetest.chat_send_player(name,
@ -66,7 +69,7 @@ minetest.register_node("areas:protector", {
end,
on_punch = function(pos)
local objs = minetest.get_objects_inside_radius(pos, .5) -- a radius of .5 since the entity serialization seems to be not that precise
local objs = minetest.get_objects_inside_radius(pos, 0.5) -- a radius of 0.5 since the entity serialization seems to be not that precise
local displayed = false
for _, o in pairs(objs) do
if not o:is_player() and o:get_luaentity().name == "areas:display" then