From f6f629afa9160c83413bfccad7f9b0ab7e55d15f Mon Sep 17 00:00:00 2001 From: rnd1 Date: Tue, 14 Jun 2016 00:05:26 +0200 Subject: [PATCH] init --- depends.txt | 1 + init.lua | 103 +++++++++++++++++++++++++++++++++ textures/basic_protector.png | Bin 0 -> 743 bytes textures/protector_display.png | Bin 0 -> 96 bytes 4 files changed, 104 insertions(+) create mode 100644 depends.txt create mode 100644 init.lua create mode 100644 textures/basic_protector.png create mode 100644 textures/protector_display.png diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..331d858 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..6d5d04e --- /dev/null +++ b/init.lua @@ -0,0 +1,103 @@ +--Basic protect by rnd, 2016 +local protector = {}; +protector.radius = 20; -- 20x20x20 area + +protector.cache = {}; + +local old_is_protected = minetest.is_protected +function minetest.is_protected(pos, digger) + local r = protector.radius; + local p = {x=math.floor((pos.x)/r)*r,y=math.floor((pos.y)/r)*r,z=math.floor((pos.z)/r)*r} + + if not protector.cache[digger] then -- cache current check for faster future lookups + protector.cache[digger] = p; + else + local p0 = protector.cache[digger]; + if (p0.x==p.x and p0.y==p.y and p0.z==p.z) then -- already checked, just lookup + return protector.cache[digger].is_protected + else + protector.cache[digger] = p; -- refresh cache + end + end + + if minetest.get_node(p).name == "basic_protect:protector" then + local meta = minetest.get_meta(p); + local owner = meta:get_string("owner"); + if digger~=owner then + minetest.chat_send_player(digger, "area owned by " .. owner); + protector.cache[digger].is_protected = true; + return true + end + end + protector.cache[digger].is_protected = old_is_protected(pos, digger); + return protector.cache[digger].is_protected; +end + + +minetest.register_node("basic_protect:protector", { + description = "Protects a rectangle area of size " .. protector.radius, + tiles = {"basic_protector.png"}, + groups = {oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + on_place = function(itemstack, placer, pointed_thing) + --after_place_node = function(pos, placer) + local pos = pointed_thing.under; + local name = placer:get_player_name(); + local r = protector.radius; + local p = {x=math.floor((pos.x)/r)*r,y=math.floor((pos.y)/r)*r,z=math.floor((pos.z)/r)*r} + if minetest.get_node(p).name == "basic_protect:protector" then + minetest.chat_send_player(name,"area already protected at " .. minetest.pos_to_string(p)); + return nil + end + minetest.set_node(p, {name = "basic_protect:protector"}); + local meta = minetest.get_meta(p);meta:set_string("owner",name); + minetest.chat_send_player(name, "#protector: protected new area (" .. p.x .. "," .. p.y .. "," .. p.z .. ") + " .. protector.radius-1 .. " nodes"); + meta:set_string("infotext", "property of " .. name); + protector.cache = {}; -- reset cache + itemstack:take_item(); return itemstack + end, + on_punch = function(pos, node, puncher, pointed_thing) + local meta = minetest.get_meta(pos);local owner = meta:get_string("owner"); + if owner == puncher:get_player_name() then + minetest.add_entity({x=pos.x+protector.radius/2,y=pos.y+protector.radius/2,z=pos.z+protector.radius/2}, "basic_protect:display") + end + end +}); + + +minetest.register_entity("basic_protect:display", { + physical = false, + collisionbox = {0, 0, 0, 0, 0, 0}, + visual = "wielditem", + -- wielditem seems to be scaled to 1.5 times original node size + visual_size = {x = 1.29*protector.radius/20, y = 1.29*protector.radius/20}, + textures = {"protector:display_node"}, + timer = 0, + + on_activate = function(self, staticdata) + self.timer = 0; + -- Xanadu server only + if mobs and mobs.entity and mobs.entity == false then + self.object:remove() + end + end, + + on_step = function(self, dtime) + + self.timer = self.timer + dtime + + if self.timer > 20 then + self.object:remove() + end + end, +}) + + +minetest.register_craft({ + output = "basic_protect:protector", + recipe = { + {"default:stone", "default:stone","default:stone"}, + {"default:stone", "default:steel_ingot","default:stone"}, + {"default:stone", "default:stone", "default:stone"} + } +}) \ No newline at end of file diff --git a/textures/basic_protector.png b/textures/basic_protector.png new file mode 100644 index 0000000000000000000000000000000000000000..7c4595217e04c132d2f7da91de1d9325c41a188d GIT binary patch literal 743 zcmV?P)LPv)Pf;v!NF7KV&V?)QOq6-uJbVrvIfBO!MuLT1mX-U;<1c6B+6Tls{C)T1`|}H|od0e- z<}?YMWvRh+^!GhVlj-ZHZv?owzWw~mz%26QGu!L`5^rDsxp3kF6C=+*hJRGZ2OOMS z;zFYL-~9jo`xVpgcfY>;Wcu-yg-4u$>5sIeAQde5`;UQ}jp4|}cmICB<78(1|C@oI zhhxRwn}XtOtn3_Aus}>wMMjkO^*cxNk)WMP?ic7WEE6c zo6AZ`FsF1}9GLnkMaJ;u1*p*7(CEd*$-Y+Z%6F zWWmA(3y+^Vz4ZLj2M-uiV$G%b*;qOMq=s62`On|8eS)Hr^p;Iq@SA`yqg`En_51hl zCa_|lDZKvqnVk<`|CCUao_7&p?&X!2b;EVZ&&kMOee1gG*RNMCsU}_v<7m5R)Phk9 Z7yxqT3pupa4& literal 0 HcmV?d00001 diff --git a/textures/protector_display.png b/textures/protector_display.png new file mode 100644 index 0000000000000000000000000000000000000000..6d7ec7d9bbdc91afbe420c129496082762a756f1 GIT binary patch literal 96 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`>Ygr+Ar_~T_o)5+Z_muy!0Kf@ tY2|-=VdmC^D-D6nZoCd>dsEUg89v-+70_Ja_!y{#!PC{xWt~$(698Yh8(07U literal 0 HcmV?d00001