2012-07-16 20:38:15 +02:00
|
|
|
worldedit.marker1 = {}
|
|
|
|
worldedit.marker2 = {}
|
2013-12-24 20:07:42 +01:00
|
|
|
worldedit.marker_region = {}
|
2013-07-31 06:02:37 +02:00
|
|
|
|
2020-04-16 23:50:15 +02:00
|
|
|
local init_sentinel = "new" .. tostring(math.random(99999))
|
|
|
|
|
2012-07-16 20:38:15 +02:00
|
|
|
--marks worldedit region position 1
|
2020-04-07 00:14:31 +02:00
|
|
|
worldedit.mark_pos1 = function(name, region_too)
|
2023-06-19 18:24:31 +02:00
|
|
|
local pos1 = worldedit.pos1[name]
|
2013-08-01 04:15:08 +02:00
|
|
|
|
2012-07-20 05:24:37 +02:00
|
|
|
if worldedit.marker1[name] ~= nil then --marker already exists
|
|
|
|
worldedit.marker1[name]:remove() --remove marker
|
|
|
|
worldedit.marker1[name] = nil
|
|
|
|
end
|
2013-08-01 04:15:08 +02:00
|
|
|
if pos1 ~= nil then
|
2024-04-20 13:59:04 +02:00
|
|
|
worldedit.keep_loaded(pos1, pos1)
|
2020-04-16 23:50:15 +02:00
|
|
|
|
2013-08-01 04:15:08 +02:00
|
|
|
--add marker
|
2020-04-16 23:50:15 +02:00
|
|
|
worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1", init_sentinel)
|
2013-12-24 20:07:42 +01:00
|
|
|
if worldedit.marker1[name] ~= nil then
|
2014-10-30 03:47:08 +01:00
|
|
|
worldedit.marker1[name]:get_luaentity().player_name = name
|
2013-07-31 06:02:37 +02:00
|
|
|
end
|
2012-07-16 20:38:15 +02:00
|
|
|
end
|
2020-04-07 00:14:31 +02:00
|
|
|
if region_too == nil or region_too then
|
|
|
|
worldedit.mark_region(name)
|
|
|
|
end
|
2012-07-16 20:38:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--marks worldedit region position 2
|
2020-04-07 00:14:31 +02:00
|
|
|
worldedit.mark_pos2 = function(name, region_too)
|
2023-06-19 18:24:31 +02:00
|
|
|
local pos2 = worldedit.pos2[name]
|
2013-08-01 04:15:08 +02:00
|
|
|
|
2012-07-20 05:24:37 +02:00
|
|
|
if worldedit.marker2[name] ~= nil then --marker already exists
|
|
|
|
worldedit.marker2[name]:remove() --remove marker
|
|
|
|
worldedit.marker2[name] = nil
|
|
|
|
end
|
2013-08-01 04:15:08 +02:00
|
|
|
if pos2 ~= nil then
|
2024-04-20 13:59:04 +02:00
|
|
|
worldedit.keep_loaded(pos2, pos2)
|
2020-04-16 23:50:15 +02:00
|
|
|
|
2013-08-01 04:15:08 +02:00
|
|
|
--add marker
|
2020-04-16 23:50:15 +02:00
|
|
|
worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2", init_sentinel)
|
2013-12-24 20:07:42 +01:00
|
|
|
if worldedit.marker2[name] ~= nil then
|
2014-10-30 03:47:08 +01:00
|
|
|
worldedit.marker2[name]:get_luaentity().player_name = name
|
2013-07-31 06:02:37 +02:00
|
|
|
end
|
|
|
|
end
|
2020-04-07 00:14:31 +02:00
|
|
|
if region_too == nil or region_too then
|
|
|
|
worldedit.mark_region(name)
|
|
|
|
end
|
2013-07-31 06:02:37 +02:00
|
|
|
end
|
|
|
|
|
2013-12-24 20:07:42 +01:00
|
|
|
worldedit.mark_region = function(name)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
2013-08-01 04:15:08 +02:00
|
|
|
|
2013-12-24 20:07:42 +01:00
|
|
|
if worldedit.marker_region[name] ~= nil then --marker already exists
|
|
|
|
for _, entity in ipairs(worldedit.marker_region[name]) do
|
|
|
|
entity:remove()
|
|
|
|
end
|
|
|
|
worldedit.marker_region[name] = nil
|
2012-07-16 20:38:15 +02:00
|
|
|
end
|
2016-12-10 22:02:40 +01:00
|
|
|
|
2013-08-01 04:15:08 +02:00
|
|
|
if pos1 ~= nil and pos2 ~= nil then
|
2013-12-24 20:07:42 +01:00
|
|
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
2016-12-10 22:02:40 +01:00
|
|
|
|
|
|
|
local vec = vector.subtract(pos2, pos1)
|
|
|
|
local maxside = math.max(vec.x, math.max(vec.y, vec.z))
|
2019-07-17 02:06:29 +02:00
|
|
|
local limit = tonumber(minetest.settings:get("active_object_send_range_blocks")) * 16
|
2016-12-10 22:02:40 +01:00
|
|
|
if maxside > limit * 1.5 then
|
|
|
|
-- The client likely won't be able to see the plane markers as intended anyway,
|
|
|
|
-- thus don't place them and also don't load the area into memory
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-12-24 20:07:42 +01:00
|
|
|
local thickness = 0.2
|
|
|
|
local sizex, sizey, sizez = (1 + pos2.x - pos1.x) / 2, (1 + pos2.y - pos1.y) / 2, (1 + pos2.z - pos1.z) / 2
|
|
|
|
|
2024-04-20 13:59:04 +02:00
|
|
|
-- TODO maybe we could skip this actually?
|
|
|
|
worldedit.keep_loaded(pos1, pos2)
|
2013-12-24 20:07:42 +01:00
|
|
|
|
|
|
|
local markers = {}
|
|
|
|
|
|
|
|
--XY plane markers
|
|
|
|
for _, z in ipairs({pos1.z - 0.5, pos2.z + 0.5}) do
|
2024-05-26 15:56:32 +02:00
|
|
|
local entpos = vector.new(pos1.x + sizex - 0.5, pos1.y + sizey - 0.5, z)
|
2020-04-16 23:50:15 +02:00
|
|
|
local marker = minetest.add_entity(entpos, "worldedit:region_cube", init_sentinel)
|
2016-12-21 14:26:24 +01:00
|
|
|
if marker ~= nil then
|
|
|
|
marker:set_properties({
|
|
|
|
visual_size={x=sizex * 2, y=sizey * 2},
|
|
|
|
collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
|
|
|
|
})
|
|
|
|
marker:get_luaentity().player_name = name
|
|
|
|
table.insert(markers, marker)
|
|
|
|
end
|
2013-12-24 20:07:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--YZ plane markers
|
|
|
|
for _, x in ipairs({pos1.x - 0.5, pos2.x + 0.5}) do
|
2024-05-26 15:56:32 +02:00
|
|
|
local entpos = vector.new(x, pos1.y + sizey - 0.5, pos1.z + sizez - 0.5)
|
2020-04-16 23:50:15 +02:00
|
|
|
local marker = minetest.add_entity(entpos, "worldedit:region_cube", init_sentinel)
|
2016-12-21 14:26:24 +01:00
|
|
|
if marker ~= nil then
|
|
|
|
marker:set_properties({
|
|
|
|
visual_size={x=sizez * 2, y=sizey * 2},
|
|
|
|
collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
|
|
|
|
})
|
2019-07-17 02:06:29 +02:00
|
|
|
marker:set_yaw(math.pi / 2)
|
2016-12-21 14:26:24 +01:00
|
|
|
marker:get_luaentity().player_name = name
|
|
|
|
table.insert(markers, marker)
|
|
|
|
end
|
2013-12-24 20:07:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
worldedit.marker_region[name] = markers
|
2013-08-01 04:15:08 +02:00
|
|
|
end
|
2012-07-16 20:38:15 +02:00
|
|
|
end
|
|
|
|
|
2020-04-07 00:14:31 +02:00
|
|
|
--convenience function that calls everything
|
|
|
|
worldedit.marker_update = function(name)
|
|
|
|
worldedit.mark_pos1(name, false)
|
|
|
|
worldedit.mark_pos2(name, false)
|
|
|
|
worldedit.mark_region(name)
|
|
|
|
end
|
|
|
|
|
2012-10-14 03:45:50 +02:00
|
|
|
minetest.register_entity(":worldedit:pos1", {
|
2012-07-16 20:38:15 +02:00
|
|
|
initial_properties = {
|
|
|
|
visual = "cube",
|
|
|
|
visual_size = {x=1.1, y=1.1},
|
|
|
|
textures = {"worldedit_pos1.png", "worldedit_pos1.png",
|
|
|
|
"worldedit_pos1.png", "worldedit_pos1.png",
|
|
|
|
"worldedit_pos1.png", "worldedit_pos1.png"},
|
|
|
|
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
|
2013-07-31 06:02:37 +02:00
|
|
|
physical = false,
|
2020-04-16 23:50:15 +02:00
|
|
|
static_save = false,
|
2012-07-16 20:38:15 +02:00
|
|
|
},
|
2020-04-16 23:50:15 +02:00
|
|
|
on_activate = function(self, staticdata, dtime_s)
|
|
|
|
if staticdata ~= init_sentinel then
|
|
|
|
-- we were loaded from before static_save = false was added
|
2012-07-22 21:55:49 +02:00
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end,
|
2012-07-16 20:38:15 +02:00
|
|
|
on_punch = function(self, hitter)
|
|
|
|
self.object:remove()
|
2014-10-30 03:47:08 +01:00
|
|
|
worldedit.marker1[self.player_name] = nil
|
2012-07-16 20:38:15 +02:00
|
|
|
end,
|
2020-03-06 21:20:15 +01:00
|
|
|
on_blast = function(self, damage)
|
|
|
|
return false, false, {} -- don't damage or knockback
|
|
|
|
end,
|
2012-07-16 20:38:15 +02:00
|
|
|
})
|
|
|
|
|
2012-10-14 03:45:50 +02:00
|
|
|
minetest.register_entity(":worldedit:pos2", {
|
2012-07-16 20:38:15 +02:00
|
|
|
initial_properties = {
|
|
|
|
visual = "cube",
|
|
|
|
visual_size = {x=1.1, y=1.1},
|
|
|
|
textures = {"worldedit_pos2.png", "worldedit_pos2.png",
|
|
|
|
"worldedit_pos2.png", "worldedit_pos2.png",
|
|
|
|
"worldedit_pos2.png", "worldedit_pos2.png"},
|
|
|
|
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
|
2013-07-31 06:02:37 +02:00
|
|
|
physical = false,
|
2020-04-16 23:50:15 +02:00
|
|
|
static_save = false,
|
2012-07-16 20:38:15 +02:00
|
|
|
},
|
2020-04-16 23:50:15 +02:00
|
|
|
on_activate = function(self, staticdata, dtime_s)
|
|
|
|
if staticdata ~= init_sentinel then
|
|
|
|
-- we were loaded from before static_save = false was added
|
2012-07-22 21:55:49 +02:00
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end,
|
2012-07-16 20:38:15 +02:00
|
|
|
on_punch = function(self, hitter)
|
|
|
|
self.object:remove()
|
2014-10-30 03:47:08 +01:00
|
|
|
worldedit.marker2[self.player_name] = nil
|
2013-12-24 20:07:42 +01:00
|
|
|
end,
|
2020-03-06 21:20:15 +01:00
|
|
|
on_blast = function(self, damage)
|
|
|
|
return false, false, {} -- don't damage or knockback
|
|
|
|
end,
|
2013-12-24 20:07:42 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_entity(":worldedit:region_cube", {
|
|
|
|
initial_properties = {
|
|
|
|
visual = "upright_sprite",
|
|
|
|
textures = {"worldedit_cube.png"},
|
|
|
|
visual_size = {x=10, y=10},
|
|
|
|
physical = false,
|
2020-04-16 23:50:15 +02:00
|
|
|
static_save = false,
|
2013-12-24 20:07:42 +01:00
|
|
|
},
|
2020-04-16 23:50:15 +02:00
|
|
|
on_activate = function(self, staticdata, dtime_s)
|
|
|
|
if staticdata ~= init_sentinel then
|
|
|
|
-- we were loaded from before static_save = false was added
|
2013-12-24 20:07:42 +01:00
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_punch = function(self, hitter)
|
2016-10-12 19:38:41 +02:00
|
|
|
local markers = worldedit.marker_region[self.player_name]
|
|
|
|
if not markers then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
for _, entity in ipairs(markers) do
|
2013-12-24 20:07:42 +01:00
|
|
|
entity:remove()
|
|
|
|
end
|
2014-10-30 03:47:08 +01:00
|
|
|
worldedit.marker_region[self.player_name] = nil
|
2012-07-16 20:38:15 +02:00
|
|
|
end,
|
2020-03-06 21:20:15 +01:00
|
|
|
on_blast = function(self, damage)
|
|
|
|
return false, false, {} -- don't damage or knockback
|
|
|
|
end,
|
2014-10-30 03:47:08 +01:00
|
|
|
})
|
|
|
|
|