From 7166c89f02dd8416b7a602b1380b743d52d4ab2f Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Wed, 28 Jun 2017 18:17:58 +0200 Subject: [PATCH] cylinder conflict detection --- worldedit_commands/init.lua | 49 +++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index bc1c141..fceb91a 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -578,13 +578,6 @@ minetest.register_chatcommand("/dome", { }) local check_cylinder = function(name, param) - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then - worldedit.player_notify( - name, - "check_cylinder not yet supported with area protection" - ) - return nil - end if worldedit.pos1[name] == nil then worldedit.player_notify(name, "no position 1 selected") return nil @@ -594,6 +587,48 @@ local check_cylinder = function(name, param) worldedit.player_notify(name, "invalid usage: " .. param) return nil end + if nil ~= area_protection.areas then + if axis == "?" then + local sign + axis, sign = worldedit.player_axis(name) + length = length * sign + end + local pos1 = worldedit.pos1[name] + local current_pos = {x=pos1.x, y=pos1.y, z=pos1.z} + if length < 0 then + length = -length + current_pos[axis] = current_pos[axis] - length + end + local other1, other2 = worldedit.get_axis_others(axis) + local interact_pos1 = { + x = current_pos.x, + y = current_pos.y, + z = current_pos.z, + } + local interact_pos2 = { + x = current_pos.x, + y = current_pos.y, + z = current_pos.z, + } + interact_pos1[other1] = interact_pos1[other1] - radius + interact_pos1[other2] = interact_pos1[other2] - radius + interact_pos2[other1] = interact_pos2[other1] + radius + interact_pos2[other2] = interact_pos2[other2] + radius + interact_pos2[axis] = interact_pos2[axis] + length + local allowed, conflicting = area_protection.areas:canInteractInArea( + interact_pos1, + interact_pos2, + name, + false + ) + if false == allowed then + worldedit.player_notify( + name, + "cylinder may conflict with non-owned region " .. conflicting + ) + return nil + end + end local node = get_node(name, nodename) if not node then return nil end return math.ceil(math.pi * (tonumber(radius) ^ 2) * tonumber(length))