* refactor a few things
* rename nodes to .."_large" * add smaller size, default 15³ m volume, make large default to 33³ this makes the large one fit nicely at the dead center of a "city block", with 5m wide roads and 1m easement, on a 40m grid. Small one fits well in a plot 1/4 of that, i.e. 5m/1m/40m roads, with 1-3m wide alleys on a 20m grid between them. * add separate height setting (default same as x/z "radius") * add coordinates of protector to description that's passed to `areas` mod * make standard recipe point to small size, gives 2 (recipe for large is just small x 8)
This commit is contained in:
parent
fe6e77b9fa
commit
75cac91bea
214
init.lua
214
init.lua
@ -9,7 +9,21 @@ local function red(str)
|
|||||||
return minetest.colorize("#FF5555",str)
|
return minetest.colorize("#FF5555",str)
|
||||||
end
|
end
|
||||||
|
|
||||||
local radius = minetest.setting_get("areasprotector_radius") or 8
|
local radius_large = minetest.setting_get("areasprotector_radius_large")
|
||||||
|
or minetest.setting_get("areasprotector_radius")
|
||||||
|
or 16
|
||||||
|
|
||||||
|
local height_large = minetest.setting_get("areasprotector_height_large")
|
||||||
|
or minetest.setting_get("areasprotector_radius_large")
|
||||||
|
or minetest.setting_get("areasprotector_radius")
|
||||||
|
or 16
|
||||||
|
|
||||||
|
local radius_small = minetest.setting_get("areasprotector_radius_small")
|
||||||
|
or 7
|
||||||
|
|
||||||
|
local height_small = minetest.setting_get("areasprotector_height_small")
|
||||||
|
or minetest.setting_get("areasprotector_radius_small")
|
||||||
|
or 7
|
||||||
|
|
||||||
local function remove_display(pos)
|
local function remove_display(pos)
|
||||||
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
@ -18,35 +32,21 @@ local function remove_display(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("areasprotector:protector",{
|
local function on_place(itemstack, player, pointed, radius, height, sizeword)
|
||||||
description = "Protector Block",
|
|
||||||
groups = {cracky=1},
|
|
||||||
tiles = {
|
|
||||||
"default_steel_block.png",
|
|
||||||
"default_steel_block.png",
|
|
||||||
"default_steel_block.png^basic_materials_padlock.png"
|
|
||||||
},
|
|
||||||
paramtype = "light",
|
|
||||||
drawtype = "nodebox",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
|
||||||
},
|
|
||||||
on_place = function(itemstack,player,pointed)
|
|
||||||
local pos = pointed.above
|
local pos = pointed.above
|
||||||
local pos1 = vector.add(pos,vector.new(radius,radius,radius))
|
local pos1 = vector.add(pos,vector.new(radius, height, radius))
|
||||||
local pos2 = vector.add(pos,vector.new(-1*radius,-1*radius,-1*radius))
|
local pos2 = vector.add(pos,vector.new(-radius, -height, -radius))
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local perm,err = areas:canPlayerAddArea(pos1,pos2,name)
|
local perm,err = areas:canPlayerAddArea(pos1,pos2,name)
|
||||||
if not perm then
|
if not perm then
|
||||||
minetest.chat_send_player(name,red("You are not allowed to protect that area: ")..err)
|
minetest.chat_send_player(name,red("You are not allowed to protect that area: ")..err)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
local id = areas:add(name,"Protected by Protector Block",pos1,pos2)
|
local id = areas:add(name,"Protected by Protector Block at "..minetest.pos_to_string(pos, 0),pos1,pos2)
|
||||||
areas:save()
|
areas:save()
|
||||||
local msg = string.format("The area from %s to %s has been protected as #%s",cyan(minetest.pos_to_string(pos1)),cyan(minetest.pos_to_string(pos2)),cyan(id))
|
local msg = string.format("The area from %s to %s has been protected as #%s",cyan(minetest.pos_to_string(pos1)),cyan(minetest.pos_to_string(pos2)),cyan(id))
|
||||||
minetest.chat_send_player(name,msg)
|
minetest.chat_send_player(name,msg)
|
||||||
minetest.set_node(pos,{name="areasprotector:protector"})
|
minetest.set_node(pos,{name="areasprotector:protector_"..sizeword})
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local infotext = string.format("Protecting area %d owned by %s",id,name)
|
local infotext = string.format("Protecting area %d owned by %s",id,name)
|
||||||
meta:set_string("infotext",infotext)
|
meta:set_string("infotext",infotext)
|
||||||
@ -56,8 +56,9 @@ minetest.register_node("areasprotector:protector",{
|
|||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
||||||
|
local function after_dig(pos, oldnode, oldmetadata, digger, sizeword)
|
||||||
if oldmetadata and oldmetadata.fields then
|
if oldmetadata and oldmetadata.fields then
|
||||||
local owner = oldmetadata.fields.owner
|
local owner = oldmetadata.fields.owner
|
||||||
local id = tonumber(oldmetadata.fields.area_id)
|
local id = tonumber(oldmetadata.fields.area_id)
|
||||||
@ -67,7 +68,7 @@ minetest.register_node("areasprotector:protector",{
|
|||||||
local inv = digger:get_inventory()
|
local inv = digger:get_inventory()
|
||||||
if not creative_mode then
|
if not creative_mode then
|
||||||
if inv:room_for_item("main", "default:steel_ingot 6") then
|
if inv:room_for_item("main", "default:steel_ingot 6") then
|
||||||
inv:remove_item("main", "areasprotector:protector 1")
|
inv:remove_item("main", "areasprotector:protector_"..sizeword.." 1")
|
||||||
inv:add_item("main", "default:steel_ingot 6")
|
inv:add_item("main", "default:steel_ingot 6")
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(playername, "No room for the replacement ingots, just digging the protector and deleting the area normally.")
|
minetest.chat_send_player(playername, "No room for the replacement ingots, just digging the protector and deleting the area normally.")
|
||||||
@ -75,7 +76,7 @@ minetest.register_node("areasprotector:protector",{
|
|||||||
areas:save()
|
areas:save()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
inv:remove_item("main", "areasprotector:protector 1")
|
inv:remove_item("main", "areasprotector:protector_"..sizeword.." 1")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
areas:remove(id)
|
areas:remove(id)
|
||||||
@ -83,71 +84,178 @@ minetest.register_node("areasprotector:protector",{
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
on_punch = function(pos, node, puncher)
|
|
||||||
|
local function on_punch(pos, node, puncher, sizeword)
|
||||||
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 removed = false
|
local removed = 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 == "areasprotector:display_"..sizeword then
|
||||||
o:remove()
|
o:remove()
|
||||||
removed = true
|
removed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not removed then -- nothing was removed: there wasn't the entity
|
if not removed then -- nothing was removed: there wasn't the entity
|
||||||
minetest.add_entity(pos, "areasprotector:display")
|
minetest.add_entity(pos, "areasprotector:display_"..sizeword)
|
||||||
minetest.after(4, remove_display, pos)
|
minetest.after(4, remove_display, pos)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_step(self, dtime, sizeword)
|
||||||
|
if minetest.get_node(self.object:getpos()).name ~= "areasprotector:protector_"..sizeword then
|
||||||
|
self.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function make_display_nodebox(radius, height)
|
||||||
|
local nb_radius = radius + 0.55
|
||||||
|
local nb_height = height + 0.55
|
||||||
|
local t = {
|
||||||
|
-- sides
|
||||||
|
{ -nb_radius, -nb_height, -nb_radius, -nb_radius, nb_height, nb_radius },
|
||||||
|
{ -nb_radius, -nb_height, nb_radius, nb_radius, nb_height, nb_radius },
|
||||||
|
{ nb_radius, -nb_height, -nb_radius, nb_radius, nb_height, nb_radius },
|
||||||
|
{ -nb_radius, -nb_height, -nb_radius, nb_radius, nb_height, -nb_radius },
|
||||||
|
-- top
|
||||||
|
{ -nb_radius, nb_height, -nb_radius, nb_radius, nb_height, nb_radius },
|
||||||
|
-- bottom
|
||||||
|
{ -nb_radius, -nb_height, -nb_radius, nb_radius, -nb_height, nb_radius },
|
||||||
|
-- middle (surround protector)
|
||||||
|
{-.55,-.55,-.55, .55,.55,.55},
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local nbox = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||||
|
}
|
||||||
|
|
||||||
|
minetest.register_node("areasprotector:protector_large", {
|
||||||
|
description = "Protector Block (large volume)",
|
||||||
|
groups = {cracky=1},
|
||||||
|
tiles = {
|
||||||
|
"default_steel_block.png",
|
||||||
|
"default_steel_block.png",
|
||||||
|
"default_steel_block.png^areasprotector_large_overlay.png^basic_materials_padlock.png"
|
||||||
|
},
|
||||||
|
paramtype = "light",
|
||||||
|
drawtype = "nodebox",
|
||||||
|
node_box = nbox,
|
||||||
|
on_place = function(itemstack, player, pointed_thing)
|
||||||
|
on_place(itemstack, player, pointed_thing, radius_large, height_large, "large")
|
||||||
|
end,
|
||||||
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
|
after_dig(pos, oldnode, oldmetadata, digger, "large")
|
||||||
|
end,
|
||||||
|
on_punch = function(pos, node, puncher)
|
||||||
|
on_punch(pos, node, puncher, "large")
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("areasprotector:protector_small", {
|
||||||
|
description = "Protector Block (small volume)",
|
||||||
|
groups = {cracky=1},
|
||||||
|
tiles = {
|
||||||
|
"default_steel_block.png",
|
||||||
|
"default_steel_block.png",
|
||||||
|
"default_steel_block.png^basic_materials_padlock.png"
|
||||||
|
},
|
||||||
|
paramtype = "light",
|
||||||
|
drawtype = "nodebox",
|
||||||
|
node_box = nbox,
|
||||||
|
on_place = function(itemstack, player, pointed_thing)
|
||||||
|
on_place(itemstack, player, pointed_thing, radius_small, height_small, "small")
|
||||||
|
end,
|
||||||
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
|
after_dig(pos, oldnode, oldmetadata, digger, "small")
|
||||||
|
end,
|
||||||
|
on_punch = function(pos, node, puncher)
|
||||||
|
on_punch(pos, node, puncher, "small")
|
||||||
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", {
|
-- wielditem seems to be scaled to 1.5 times original node size
|
||||||
|
local vsize = {x=1.0/1.5, y=1.0/1.5}
|
||||||
|
local ecbox = {0, 0, 0, 0, 0, 0}
|
||||||
|
|
||||||
|
minetest.register_entity("areasprotector:display_large", {
|
||||||
physical = false,
|
physical = false,
|
||||||
collisionbox = {0,0,0,0,0,0},
|
collisionbox = ecbox,
|
||||||
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 = vsize,
|
||||||
textures = {"areasprotector:display_node"},
|
textures = {"areasprotector:display_node_large"},
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
if minetest.get_node(self.object:getpos()).name ~= "areasprotector:protector" then
|
on_step(self, dtime, "large")
|
||||||
self.object:remove()
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
local nb_radius = radius + 0.55
|
minetest.register_entity("areasprotector:display_small", {
|
||||||
|
physical = false,
|
||||||
|
collisionbox = ecbox,
|
||||||
|
visual = "wielditem",
|
||||||
|
visual_size = vsize,
|
||||||
|
textures = {"areasprotector:display_node_small"},
|
||||||
|
on_step = function(self, dtime)
|
||||||
|
on_step(self, dtime, "small")
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_node("areasprotector:display_node", {
|
minetest.register_node("areasprotector:display_node_large", {
|
||||||
tiles = {"areasprotector_display.png"},
|
tiles = {"areasprotector_display.png"},
|
||||||
walkable = false,
|
walkable = false,
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {
|
fixed = make_display_nodebox(radius_large, height_large)
|
||||||
-- sides
|
|
||||||
{ -nb_radius, -nb_radius, -nb_radius, -nb_radius, nb_radius, nb_radius },
|
|
||||||
{ -nb_radius, -nb_radius, nb_radius, nb_radius, nb_radius, nb_radius },
|
|
||||||
{ nb_radius, -nb_radius, -nb_radius, nb_radius, nb_radius, nb_radius },
|
|
||||||
{ -nb_radius, -nb_radius, -nb_radius, nb_radius, nb_radius, -nb_radius },
|
|
||||||
-- top
|
|
||||||
{ -nb_radius, nb_radius, -nb_radius, nb_radius, nb_radius, nb_radius },
|
|
||||||
-- bottom
|
|
||||||
{ -nb_radius, -nb_radius, -nb_radius, nb_radius, -nb_radius, nb_radius },
|
|
||||||
-- middle (surround protector)
|
|
||||||
{-.55,-.55,-.55, .55,.55,.55},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "regular",
|
type = "regular",
|
||||||
},
|
},
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
groups = {dig_immediate=3,not_in_creative_inventory=1},
|
groups = {dig_immediate=3,not_in_creative_inventory=1},
|
||||||
drop = "",
|
drop = ""
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("areasprotector:display_node_small", {
|
||||||
|
tiles = {"areasprotector_display.png"},
|
||||||
|
walkable = false,
|
||||||
|
drawtype = "nodebox",
|
||||||
|
node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = make_display_nodebox(radius_small, height_small)
|
||||||
|
},
|
||||||
|
selection_box = {
|
||||||
|
type = "regular",
|
||||||
|
},
|
||||||
|
paramtype = "light",
|
||||||
|
groups = {dig_immediate=3,not_in_creative_inventory=1},
|
||||||
|
drop = ""
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "areasprotector:protector",
|
output = "areasprotector:protector_small 2",
|
||||||
type = "shapeless",
|
type = "shapeless",
|
||||||
recipe = {"default:steelblock","basic_materials:padlock"},
|
recipe = {"default:steelblock","basic_materials:padlock"},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "areasprotector:protector_large",
|
||||||
|
type = "shapeless",
|
||||||
|
recipe = {
|
||||||
|
"areasprotector:protector_small",
|
||||||
|
"areasprotector:protector_small",
|
||||||
|
"areasprotector:protector_small",
|
||||||
|
"areasprotector:protector_small",
|
||||||
|
"areasprotector:protector_small",
|
||||||
|
"areasprotector:protector_small",
|
||||||
|
"areasprotector:protector_small",
|
||||||
|
"areasprotector:protector_small"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_alias("areasprotector:protector", "areasprotector:protector_large")
|
||||||
|
minetest.register_alias("areasprotector:display_node", "areasprotector:display_node_large")
|
||||||
|
BIN
textures/areasprotector_large_overlay.png
Normal file
BIN
textures/areasprotector_large_overlay.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 128 B |
Loading…
x
Reference in New Issue
Block a user