From c743399a383554dc7fb64617ace8cc4aa0d1cb7d Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Wed, 27 May 2020 16:39:04 +0200 Subject: [PATCH] initial noflyzone-block --- chatcommands.lua | 12 +-- init.lua | 4 +- items.lua | 96 ++++++++++++++++++ region.lua | 14 +-- settingtypes.txt | 2 +- textures/creative_regions_protector_nofly.png | Bin 0 -> 2183 bytes 6 files changed, 112 insertions(+), 16 deletions(-) create mode 100644 textures/creative_regions_protector_nofly.png diff --git a/chatcommands.lua b/chatcommands.lua index 5a0b007..07620d9 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -17,9 +17,9 @@ minetest.register_chatcommand("creative_region", { local data = region_name local astore_id = creative_regions.astore:insert_area(edge1, edge2, tostring(data)) if astore_id then - creative_regions:set_region_privs("r"..tostring(astore_id), nil) + creative_regions.set_region_privs("r"..tostring(astore_id), nil) minetest.chat_send_player(name, "[creative_regions] New region set. ID: " .. "r"..astore_id) - creative_regions:save_regions() + creative_regions.save_regions() return true, "Done" else return false, "Failed" @@ -41,9 +41,9 @@ minetest.register_chatcommand("creative_region_privs", { return false, "Syntax error" end - creative_regions:set_region_privs(tostring(region_id), privstring) + creative_regions.set_region_privs(tostring(region_id), privstring) minetest.chat_send_player(name, "[creative_regions] Privstring set for region " .. region_id .. ": " .. privstring) - creative_regions:save_regions() + creative_regions.save_regions() return true, "Done" end, }) @@ -65,12 +65,12 @@ minetest.register_chatcommand("creative_region_rm", { local success = creative_regions.astore:remove_area(astore_id) if success then minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. "removed") - creative_regions:set_region_privs(tostring(region_id), nil) + creative_regions.set_region_privs(tostring(region_id), nil) else minetest.chat_send_player(name, "Failed to remove region " .. region_id) return false, "Region not found" end - creative_regions:save_regions() + creative_regions.save_regions() return true, "Done." end, }) diff --git a/init.lua b/init.lua index b349efe..0aa0024 100644 --- a/init.lua +++ b/init.lua @@ -37,7 +37,7 @@ function creative_regions:update_player(player) end -- find active regions - local current_regions = self.astore:get_areas_for_pos(pos, true, true) + local current_regions = creative_regions.astore:get_areas_for_pos(pos, true, true) for astore_id, astore_area in pairs( current_regions ) do local id = "r"..tostring(astore_id) local size = creative_regions:get_region_size(astore_area) @@ -100,7 +100,7 @@ function creative_regions:update_player(player) end -creative_regions:load_regions() +creative_regions.load_regions() local timer = 0 minetest.register_globalstep(function(dtime) diff --git a/items.lua b/items.lua index e69de29..842174a 100644 --- a/items.lua +++ b/items.lua @@ -0,0 +1,96 @@ +if minetest.get_modpath("areas") then + + function creative_regions.protector_set_noflyzone(pos, placer, itemstack, pointed_thing) + if not pos or not placer then + return + end + local meta = minetest.get_meta(pos) + local name = placer:get_player_name(); + local player_owns_id = nil + + local current_areas = areas:getAreasAtPos(pos) + for areas_id, areas_area in pairs( current_areas ) do + if areas_area.owner == name then + player_owns_id = "a"..tostring(areas_id) + break + end + end + + if player_owns_id then + meta:set_string("infotext", string.format("No-Fly-Zone Protector for area %s owned by %s", player_owns_id, name) + meta:set_string("area_id", player_owns_id) + meta:set_string("owner", name) + + creative_regions.set_region_privs(tostring(player_owns_id), "-fast, -fly") + minetest.chat_send_player(name, "[creative_regions] No-Fly-Zone set for region " .. player_owns_id) + creative_regions.save_regions() + else + minetest.after(0.2, function(pos) + minetest.remove_node(pos) + end, pos) + end + + end + + function creative_regions.protector_can_dig(pos, player) + if not pos or not player then + return true + end + local name = player:get_player_name() + local meta = minetest.get_meta(pos) + local id = meta:get_string("area_id") + local owner = meta:get_string("owner") + + local player_owns_id = nil + + local current_areas = areas:getAreasAtPos(pos) + for areas_id, areas_area in pairs( current_areas ) do + if areas_area.owner == name then + player_owns_id = "a"..tostring(areas_id) + break + end + end + + if player_owns_id then + return true + else + minetest.chat_send_player(name, "[creative_regions] Cannot remove No-Fly-Zone "..id.." owned by "..owner) + return false + end + + end + + function creative_regions.protector_remove_noflyzone(pos, oldnode, oldmetadata, digger) + if not oldmetadata or not oldmetadata.fields then + return + end + local owner = oldmetadata.fields.owner + local stored_id = oldmetadata.fields.area_id + local name = digger:get_player_name() + + local current_areas = areas:getAreasAtPos(pos) + for areas_id, areas_area in pairs( current_areas ) do + local id = "a"..tostring(areas_id) + if stored_id == id then + creative_regions.set_region_privs(tostring(id), nil) + minetest.chat_send_player(name, "[creative_regions] No-Fly-Zone for area " .. id .. " removed") + creative_regions.save_regions() + end + end + + end + + minetest.register_node("creative_regions:protector_nofly", { + description = "No-Fly-Zone Protector", + tiles = {"creative_regions_protector_nofly.png"}, + is_ground_content = true, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=1}, + light_source = 1, + after_place_node = creative_regions.protector_set_noflyzone, + can_dig = creative_regions.protector_can_dig, + after_dig_node = creative_regions.protector_remove_noflyzone, + }) + + --minetest.register_alias("noflyzone", "creative_regions:noflyprotector") + +end diff --git a/region.lua b/region.lua index b84ce76..59b1444 100644 --- a/region.lua +++ b/region.lua @@ -3,19 +3,19 @@ creative_regions.mod_storage = minetest.get_mod_storage() creative_regions.region_privs = {} -function creative_regions:load_regions() - self.astore:from_file(minetest.get_worldpath().."/creative_regions_regions") +function creative_regions.load_regions() + creative_regions.astore:from_file(minetest.get_worldpath().."/creative_regions_regions") creative_regions.region_privs = minetest.deserialize(creative_regions.mod_storage:get_string("astore_privs")) or {} -- local edge1 = { x=-10, y=-10, z=-10 } -- local edge2 = { x=10, y=10, z=10 } -- local data = "Testregion" --- local astore_id = self.astore:insert_area(edge1, edge2, tostring(data)) +-- local astore_id = creative_regions.astore:insert_area(edge1, edge2, tostring(data)) -- --- creative_regions:set_region_privs("r"..astore_id, "+creative, +fast, +fly") +-- creative_regions.set_region_privs("r"..astore_id, "+creative, +fast, +fly") end -function creative_regions:save_regions() - self.astore:to_file(minetest.get_worldpath().."/creative_regions_regions") +function creative_regions.save_regions() + creative_regions.astore:to_file(minetest.get_worldpath().."/creative_regions_regions") local datastr = minetest.serialize(creative_regions.region_privs) if not datastr then minetest.log("error", "[creative_regions] Failed to serialize region_privs data!") @@ -32,7 +32,7 @@ function creative_regions:get_region_size(astore_area) return x*z end -function creative_regions:set_region_privs(id, privs_string) +function creative_regions.set_region_privs(id, privs_string) creative_regions.region_privs[tostring(id)] = privs_string end diff --git a/settingtypes.txt b/settingtypes.txt index 55f1dd0..25f261c 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -2,7 +2,7 @@ creative_regions.owner_privs (Owner privs) string "+creative, +fast, +fly" # Privs of an areas mod guest -creative_regions.guest_privs (Guest privs) string "-fly, -fast" +creative_regions.guest_privs (Guest privs) string "-fast, -fly" # Default privs when not in an area creative_regions.noregion_privs (Noregion default privs) string "-creative, -fast, -fly" diff --git a/textures/creative_regions_protector_nofly.png b/textures/creative_regions_protector_nofly.png new file mode 100644 index 0000000000000000000000000000000000000000..ccc3e5cb39d34cba613828d18c652390c5d5a736 GIT binary patch literal 2183 zcmV;22zd92P) zaB^>EX>4U6ba`-PAZ2)IW&i+q+O1dX(c~x${7)1Y0*H4wJgYW?3;!B~ZS3(kyIXa3 zjg1jVLfsOKX#f7|;vZaOBne}EaM3x5%S00?p%ElsaXyta^SM6c(YW=CQ$Xm_cx(Rj zX^l_lx7UQjhRXMT5tf9)Qlw7B^U}leXxH6I^b_|hvlPX~4HtvoUCm2TSp%ml>t{~4 z_%*)8t-~Wq)xwY_YFcSIpMgEl{7d**JV|?uQ`(?ywGy){E@cSFZFy$^qjiziV+&G0%afl`ZPnkVSRc;cL9|X;g2BqUPJGVSC@=KMBQT447NJd zU|>eb^_=E#d;Bcge%=vxkVzImUS*LPcTrIhQ0YP$RaH`5wfQcpz(qrifC&*5(z7oB zqew+FPPkPkucNLy0IWhyXpL?xgoA7UL(R&#oQZk&e zf?qUv4L1gIN6odG`X1;5<*1F8Z+JHs5Xz$7!P$W~q4(i3NmaTae*AtiiW z3J@aLws1yiARwL6Ryid-kyi?F3;-y>bJB(~5Kz`qg_C5ob|gFn8n!XVt2ve|IU3!l zO#s4br#-NVIsq(WEcoM10Ed#*)>vzu^)?6_ZF1TfXPtB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