Skip to content

Commit ef9d5f4

Browse files
committed
Remove Protector Block
1 parent a633c77 commit ef9d5f4

File tree

3 files changed

+5
-159
lines changed

3 files changed

+5
-159
lines changed

protector.lua

Lines changed: 5 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,6 @@
1-
local S = areas.S
2-
3-
local radius = minetest.settings:get("areasprotector_radius") or 8
4-
5-
local function cyan(str)
6-
return minetest.colorize("#7CFC00", str)
7-
end
8-
9-
local function red(str)
10-
return minetest.colorize("#FF0000", str)
11-
end
12-
13-
local vadd, vnew = vector.add, vector.new
14-
15-
minetest.register_node("areas:protector", {
16-
description = S("Protector Block"),
17-
tiles = {
18-
"default_stonebrick_carved.png",
19-
"default_stonebrick_carved.png",
20-
"default_stonebrick_carved.png^areas_protector_stone.png"
21-
},
22-
paramtype = "light",
23-
groups = {cracky = 1, not_cuttable = 1},
24-
node_placement_prediction = "",
25-
26-
on_place = function(itemstack, player, pointed_thing)
27-
local pos = pointed_thing.above
28-
local name = player and player:get_player_name()
29-
30-
if not name or not minetest.is_protected(pos, name) then
31-
-- Don't replace nodes that aren't buildable to
32-
local old_node = minetest.get_node(pos)
33-
local def = minetest.registered_nodes[old_node.name]
34-
if not def or not def.buildable_to then
35-
return itemstack
36-
end
37-
38-
local pos1 = vadd(pos, vnew(radius, radius, radius))
39-
local pos2 = vadd(pos, vnew(-radius, -radius, -radius))
40-
local perm, err = areas:canPlayerAddArea(pos1, pos2, name)
41-
42-
if not perm then
43-
minetest.chat_send_player(name,
44-
red(S("You are not allowed to protect that area: @1", err)))
45-
return itemstack
46-
end
47-
48-
if minetest.find_node_near(pos, radius / 2, {"areas:protector"}) then
49-
minetest.chat_send_player(name, red(S("You have already protected this area.")))
50-
return itemstack
51-
end
52-
53-
local id = areas:add(name, S("Protector Block"), pos1, pos2)
54-
areas:save()
55-
minetest.chat_send_player(name,
56-
S("The area from @1 to @2 has been protected as ID @3",
57-
cyan(minetest.pos_to_string(pos1)), cyan(minetest.pos_to_string(pos2)), cyan(id))
58-
)
59-
60-
minetest.set_node(pos, {name = "areas:protector"})
61-
local meta = minetest.get_meta(pos)
62-
meta:set_string("infotext", S("Protected area @1, Owned by @2", id, name))
63-
meta:set_int("area_id", id)
64-
itemstack:take_item()
65-
end
66-
67-
return itemstack
68-
end,
69-
70-
after_dig_node = function(_, _, oldmetadata, digger)
71-
if oldmetadata and oldmetadata.fields then
72-
local id = tonumber(oldmetadata.fields.area_id)
73-
local name = digger and digger:get_player_name() or ""
74-
if areas.areas[id] and areas:isAreaOwner(id, name) then
75-
areas:remove(id)
76-
areas:save()
77-
minetest.chat_send_player(name, S("Removed area @1", cyan(id)))
78-
end
79-
end
80-
end,
81-
82-
on_punch = function(pos)
83-
-- a radius of 0.5 since the entity serialization seems to be not that precise
84-
local objs = minetest.get_objects_inside_radius(pos, 0.5)
85-
for _, obj in pairs(objs) do
86-
if not obj:is_player() and obj:get_luaentity().name == "areas:display" then
87-
obj:remove()
88-
return
89-
end
90-
end
91-
92-
minetest.add_entity(pos, "areas:display")
93-
end
94-
})
95-
96-
-- entities code below (and above) mostly copied-pasted from Zeg9's protector mod
97-
minetest.register_entity("areas:display", {
98-
physical = false,
99-
collisionbox = {0},
100-
visual = "wielditem",
101-
-- wielditem seems to be scaled to 1.5 times original node size
102-
visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5},
103-
textures = {"areas:display_node"},
104-
timer = 0,
105-
on_step = function(self, dtime)
106-
self.timer = self.timer + dtime
107-
if self.timer > 4 or
108-
minetest.get_node(self.object:get_pos()).name ~= "areas:protector" then
109-
self.object:remove()
110-
end
111-
end
112-
})
113-
114-
local nb_radius = radius + 0.55
115-
116-
minetest.register_node("areas:display_node", {
117-
tiles = {"areas_protector_display.png"},
118-
use_texture_alpha = "clip",
119-
walkable = false,
120-
drawtype = "nodebox",
121-
node_box = {
122-
type = "fixed",
123-
fixed = {
124-
-- sides
125-
{-nb_radius, -nb_radius, -nb_radius, -nb_radius, nb_radius, nb_radius},
126-
{-nb_radius, -nb_radius, nb_radius, nb_radius, nb_radius, nb_radius},
127-
{nb_radius, -nb_radius, -nb_radius, nb_radius, nb_radius, nb_radius},
128-
{-nb_radius, -nb_radius, -nb_radius, nb_radius, nb_radius, -nb_radius},
129-
-- top
130-
{-nb_radius, nb_radius, -nb_radius, nb_radius, nb_radius, nb_radius},
131-
-- bottom
132-
{-nb_radius, -nb_radius, -nb_radius, nb_radius, -nb_radius, nb_radius},
133-
-- middle (surround protector)
134-
{-0.55, -0.55, -0.55, 0.55, 0.55, 0.55}
135-
}
136-
},
137-
selection_box = {type = "regular"},
138-
paramtype = "light",
139-
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
140-
drop = ""
141-
})
142-
143-
minetest.register_craft({
144-
output = "areas:protector",
145-
type = "shapeless",
146-
recipe = {
147-
"default:stonebrickcarved", "default:stonebrickcarved", "default:stonebrickcarved",
148-
"default:stonebrickcarved", "mesecons:wire_00000000_off", "default:stonebrickcarved",
149-
"default:stonebrickcarved", "default:stonebrickcarved", "default:stonebrickcarved"
150-
}
151-
})
152-
153-
-- MVPS stopper
154-
if mesecon and mesecon.register_mvps_stopper then
155-
mesecon.register_mvps_stopper("areas:protector")
156-
end
157-
1581
-- Aliases
159-
minetest.register_alias("areasprotector:protector", "areas:protector")
160-
minetest.register_alias("areasprotector:display_node", "areas:display_node")
2+
minetest.register_alias("areasprotector:protector", "default:stonebrickcarved")
3+
minetest.register_alias("areasprotector:display_node", "air")
4+
5+
minetest.register_alias("areas:protector", "default:stonebrickcarved")
6+
minetest.register_alias("areas:display_node", "air")
-88 Bytes
Binary file not shown.

textures/areas_protector_stone.png

-272 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)