parent
7316ba0bf8
commit
cfc2c779b8
76
init.lua
76
init.lua
|
@ -6,6 +6,15 @@ 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 function remove_display(pos)
|
||||||
|
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
|
for _,o in pairs(objs) do
|
||||||
|
o:remove()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("areasprotector:protector",{
|
minetest.register_node("areasprotector:protector",{
|
||||||
description = "Protector Block",
|
description = "Protector Block",
|
||||||
groups = {cracky=1},
|
groups = {cracky=1},
|
||||||
|
@ -14,8 +23,13 @@ minetest.register_node("areasprotector:protector",{
|
||||||
"default_steel_block.png",
|
"default_steel_block.png",
|
||||||
"default_steel_block.png^areasprotector_protector.png"
|
"default_steel_block.png^areasprotector_protector.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)
|
on_place = function(itemstack,player,pointed)
|
||||||
local radius = minetest.setting_get("areasprotector_radius") or 8
|
|
||||||
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,radius,radius))
|
||||||
local pos2 = vector.add(pos,vector.new(-1*radius,-1*radius,-1*radius))
|
local pos2 = vector.add(pos,vector.new(-1*radius,-1*radius,-1*radius))
|
||||||
|
@ -49,6 +63,66 @@ minetest.register_node("areasprotector:protector",{
|
||||||
areas:save()
|
areas:save()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
on_punch = function(pos, node, puncher)
|
||||||
|
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
|
||||||
|
for _, o in pairs(objs) do
|
||||||
|
if (not o:is_player()) and o:get_luaentity().name == "areasprotector:display" then
|
||||||
|
o:remove()
|
||||||
|
removed = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not removed then -- nothing was removed: there wasn't the entity
|
||||||
|
minetest.add_entity(pos, "areasprotector:display")
|
||||||
|
minetest.after(4, remove_display, pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
-- entities code below (and above) mostly copied-pasted from Zeg9's protector mod
|
||||||
|
|
||||||
|
minetest.register_entity("areasprotector:display", {
|
||||||
|
physical = false,
|
||||||
|
collisionbox = {0,0,0,0,0,0},
|
||||||
|
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
|
||||||
|
textures = {"areasprotector:display_node"},
|
||||||
|
on_step = function(self, dtime)
|
||||||
|
if minetest.get_node(self.object:getpos()).name ~= "areasprotector:protector" then
|
||||||
|
self.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
local nb_radius = radius + 0.55
|
||||||
|
|
||||||
|
minetest.register_node("areasprotector:display_node", {
|
||||||
|
tiles = {"areasprotector_display.png"},
|
||||||
|
walkable = false,
|
||||||
|
drawtype = "nodebox",
|
||||||
|
node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {
|
||||||
|
-- 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 = {
|
||||||
|
type = "regular",
|
||||||
|
},
|
||||||
|
paramtype = "light",
|
||||||
|
groups = {dig_immediate=3,not_in_creative_inventory=1},
|
||||||
|
drop = "",
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 96 B |
Loading…
Reference in New Issue