Minor code fixes and cleanup
parent
86e3170ad7
commit
ca1ec9fcdf
2
api.lua
2
api.lua
|
@ -16,13 +16,11 @@ function areas:registerOnMove(func)
|
||||||
table.insert(areas.registered_on_moves, func)
|
table.insert(areas.registered_on_moves, func)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Adds a function as a HUD handler, it will be able to add items to the Areas HUD element.
|
--- Adds a function as a HUD handler, it will be able to add items to the Areas HUD element.
|
||||||
function areas:registerHudHandler(handler)
|
function areas:registerHudHandler(handler)
|
||||||
table.insert(hudHandlers, handler)
|
table.insert(hudHandlers, handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function areas:getExternalHudEntries(pos)
|
function areas:getExternalHudEntries(pos)
|
||||||
local areas = {}
|
local areas = {}
|
||||||
for _, func in pairs(hudHandlers) do
|
for _, func in pairs(hudHandlers) do
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
minetest.register_chatcommand("protect", {
|
minetest.register_chatcommand("protect", {
|
||||||
params = "<AreaName>",
|
params = "<AreaName>",
|
||||||
description = "Protect your own area",
|
description = "Protect your own area",
|
||||||
|
@ -75,7 +74,7 @@ minetest.register_chatcommand("set_owner", {
|
||||||
|
|
||||||
minetest.register_chatcommand("add_owner", {
|
minetest.register_chatcommand("add_owner", {
|
||||||
params = "<ParentID> <Player> <AreaName>",
|
params = "<ParentID> <Player> <AreaName>",
|
||||||
description = "Give a player access to a sub-area beetween two"
|
description = "Give a player access to a sub-area between two"
|
||||||
.." positions that have already been protected,"
|
.." positions that have already been protected,"
|
||||||
.." Use set_owner if you don't want the parent to be set.",
|
.." Use set_owner if you don't want the parent to be set.",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
|
@ -167,7 +166,12 @@ minetest.register_chatcommand("find_areas", {
|
||||||
if str:find(param) then
|
if str:find(param) then
|
||||||
table.insert(matches, str)
|
table.insert(matches, str)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if #matches > 10 then
|
||||||
|
break
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if #matches > 0 then
|
if #matches > 0 then
|
||||||
return true, table.concat(matches, "\n")
|
return true, table.concat(matches, "\n")
|
||||||
else
|
else
|
||||||
|
@ -193,7 +197,10 @@ minetest.register_chatcommand("list_areas", {
|
||||||
end
|
end
|
||||||
if #areaStrings == 0 then
|
if #areaStrings == 0 then
|
||||||
return true, "No visible areas."
|
return true, "No visible areas."
|
||||||
|
elseif #areaStrings > 100 then
|
||||||
|
return true, "Too many areas to list."
|
||||||
end
|
end
|
||||||
|
|
||||||
return true, table.concat(areaStrings, "\n")
|
return true, table.concat(areaStrings, "\n")
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
1
init.lua
1
init.lua
|
@ -36,4 +36,3 @@ if minetest.settings:get_bool("log_mods") then
|
||||||
local diffTime = os.clock() - areas.startTime
|
local diffTime = os.clock() - areas.startTime
|
||||||
minetest.log("action", "areas loaded in "..diffTime.."s.")
|
minetest.log("action", "areas loaded in "..diffTime.."s.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,13 @@ local function red(str)
|
||||||
return minetest.colorize("#FF5555", str)
|
return minetest.colorize("#FF5555", str)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node(":areasprotector:protector", {
|
minetest.register_node("areas:protector", {
|
||||||
description = "Protector Block",
|
description = "Protector Block",
|
||||||
groups = {cracky = 1},
|
groups = {cracky = 1},
|
||||||
tiles = {
|
tiles = {
|
||||||
"default_stonebrick_carved.png",
|
"default_stonebrick_carved.png",
|
||||||
"default_stonebrick_carved.png",
|
"default_stonebrick_carved.png",
|
||||||
"default_stonebrick_carved.png^areasprotector_stone.png"
|
"default_stonebrick_carved.png^areas_protector_stone.png"
|
||||||
},
|
},
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
|
@ -40,7 +40,7 @@ minetest.register_node(":areasprotector:protector", {
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name,
|
||||||
("The area from %s to %s has been protected as #%s")
|
("The area from %s to %s has been protected as #%s")
|
||||||
:format(cyan(minetest.pos_to_string(pos1)), cyan(minetest.pos_to_string(pos2)), cyan(id)))
|
:format(cyan(minetest.pos_to_string(pos1)), cyan(minetest.pos_to_string(pos2)), cyan(id)))
|
||||||
minetest.set_node(pos, {name = "areasprotector:protector"})
|
minetest.set_node(pos, {name = "areas:protector"})
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("infotext", ("Protecting area %d, Owned by %s"):format(id, name))
|
meta:set_string("infotext", ("Protecting area %d, Owned by %s"):format(id, name))
|
||||||
meta:set_int("area_id", id)
|
meta:set_int("area_id", id)
|
||||||
|
@ -66,29 +66,29 @@ minetest.register_node(":areasprotector:protector", {
|
||||||
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, .5) -- a radius of .5 since the entity serialization seems to be not that precise
|
||||||
local displayed = false
|
local displayed = false
|
||||||
for _, o in pairs(objs) do
|
for _, o in pairs(objs) do
|
||||||
if not o:is_player() and o:get_luaentity().name == "areasprotector:display" then
|
if not o:is_player() and o:get_luaentity().name == "areas:display" then
|
||||||
o:remove()
|
o:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not displayed then -- nothing was removed: there wasn't the entity
|
if not displayed then -- nothing was removed: there wasn't the entity
|
||||||
minetest.add_entity(pos, "areasprotector:display")
|
minetest.add_entity(pos, "areas:display")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- entities code below (and above) mostly copied-pasted from Zeg9's protector mod
|
-- entities code below (and above) mostly copied-pasted from Zeg9's protector mod
|
||||||
|
|
||||||
minetest.register_entity(":areasprotector:display", {
|
minetest.register_entity("areas:display", {
|
||||||
physical = false,
|
physical = false,
|
||||||
collisionbox = {0},
|
collisionbox = {0},
|
||||||
visual = "wielditem",
|
visual = "wielditem",
|
||||||
visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5}, -- wielditem seems to be scaled to 1.5 times original node size
|
visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5}, -- wielditem seems to be scaled to 1.5 times original node size
|
||||||
textures = {"areasprotector:display_node"},
|
textures = {"areas:display_node"},
|
||||||
timer = 0,
|
timer = 0,
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
self.timer = self.timer + dtime
|
self.timer = self.timer + dtime
|
||||||
if self.timer > 4 or minetest.get_node(self.object:getpos()).name ~= "areasprotector:protector" then
|
if self.timer > 4 or minetest.get_node(self.object:getpos()).name ~= "areas:protector" then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -96,8 +96,8 @@ minetest.register_entity(":areasprotector:display", {
|
||||||
|
|
||||||
local nb_radius = radius + 0.55
|
local nb_radius = radius + 0.55
|
||||||
|
|
||||||
minetest.register_node(":areasprotector:display_node", {
|
minetest.register_node("areas:display_node", {
|
||||||
tiles = {"areasprotector_display.png"},
|
tiles = {"areas_protector_display.png"},
|
||||||
walkable = false,
|
walkable = false,
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
node_box = {
|
node_box = {
|
||||||
|
@ -123,7 +123,7 @@ minetest.register_node(":areasprotector:display_node", {
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "areasprotector:protector",
|
output = "areas:protector",
|
||||||
type = "shapeless",
|
type = "shapeless",
|
||||||
recipe = {
|
recipe = {
|
||||||
"default:stonebrickcarved", "default:stonebrickcarved", "default:stonebrickcarved",
|
"default:stonebrickcarved", "default:stonebrickcarved", "default:stonebrickcarved",
|
||||||
|
@ -131,3 +131,7 @@ minetest.register_craft({
|
||||||
"default:stonebrickcarved", "default:stonebrickcarved", "default:stonebrickcarved"
|
"default:stonebrickcarved", "default:stonebrickcarved", "default:stonebrickcarved"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Aliases
|
||||||
|
minetest.register_alias("areasprotector:protector", "areas:protector")
|
||||||
|
minetest.register_alias("areasprotector:display_node", "areas:display_node")
|
||||||
|
|
Before Width: | Height: | Size: 88 B After Width: | Height: | Size: 88 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in New Issue