1 worldedit.marker1 = {}
\r
2 worldedit.marker2 = {}
\r
3 worldedit.marker_region = {}
\r
5 --marks worldedit region position 1
\r
6 worldedit.mark_pos1 = function(name, region_too)
\r
7 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
10 --make area stay loaded
\r
11 local manip = minetest.get_voxel_manip()
\r
12 manip:read_from_map(pos1, pos1)
\r
14 if worldedit.marker1[name] ~= nil then --marker already exists
\r
15 worldedit.marker1[name]:remove() --remove marker
\r
16 worldedit.marker1[name] = nil
\r
20 worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1")
\r
21 if worldedit.marker1[name] ~= nil then
\r
22 worldedit.marker1[name]:get_luaentity().player_name = name
\r
25 if region_too == nil or region_too then
\r
26 worldedit.mark_region(name)
\r
30 --marks worldedit region position 2
\r
31 worldedit.mark_pos2 = function(name, region_too)
\r
32 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
35 --make area stay loaded
\r
36 local manip = minetest.get_voxel_manip()
\r
37 manip:read_from_map(pos2, pos2)
\r
39 if worldedit.marker2[name] ~= nil then --marker already exists
\r
40 worldedit.marker2[name]:remove() --remove marker
\r
41 worldedit.marker2[name] = nil
\r
45 worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2")
\r
46 if worldedit.marker2[name] ~= nil then
\r
47 worldedit.marker2[name]:get_luaentity().player_name = name
\r
50 if region_too == nil or region_too then
\r
51 worldedit.mark_region(name)
\r
55 worldedit.mark_region = function(name)
\r
56 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
58 if worldedit.marker_region[name] ~= nil then --marker already exists
\r
59 --wip: make the area stay loaded somehow
\r
60 for _, entity in ipairs(worldedit.marker_region[name]) do
\r
63 worldedit.marker_region[name] = nil
\r
66 if pos1 ~= nil and pos2 ~= nil then
\r
67 local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
\r
69 local vec = vector.subtract(pos2, pos1)
\r
70 local maxside = math.max(vec.x, math.max(vec.y, vec.z))
\r
71 local limit = tonumber(minetest.settings:get("active_object_send_range_blocks")) * 16
\r
72 if maxside > limit * 1.5 then
\r
73 -- The client likely won't be able to see the plane markers as intended anyway,
\r
74 -- thus don't place them and also don't load the area into memory
\r
78 local thickness = 0.2
\r
79 local sizex, sizey, sizez = (1 + pos2.x - pos1.x) / 2, (1 + pos2.y - pos1.y) / 2, (1 + pos2.z - pos1.z) / 2
\r
81 --make area stay loaded
\r
82 local manip = minetest.get_voxel_manip()
\r
83 manip:read_from_map(pos1, pos2)
\r
88 for _, z in ipairs({pos1.z - 0.5, pos2.z + 0.5}) do
\r
89 local marker = minetest.add_entity({x=pos1.x + sizex - 0.5, y=pos1.y + sizey - 0.5, z=z}, "worldedit:region_cube")
\r
90 if marker ~= nil then
\r
91 marker:set_properties({
\r
92 visual_size={x=sizex * 2, y=sizey * 2},
\r
93 collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
\r
95 marker:get_luaentity().player_name = name
\r
96 table.insert(markers, marker)
\r
101 for _, x in ipairs({pos1.x - 0.5, pos2.x + 0.5}) do
\r
102 local marker = minetest.add_entity({x=x, y=pos1.y + sizey - 0.5, z=pos1.z + sizez - 0.5}, "worldedit:region_cube")
\r
103 if marker ~= nil then
\r
104 marker:set_properties({
\r
105 visual_size={x=sizez * 2, y=sizey * 2},
\r
106 collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
\r
108 marker:set_yaw(math.pi / 2)
\r
109 marker:get_luaentity().player_name = name
\r
110 table.insert(markers, marker)
\r
114 worldedit.marker_region[name] = markers
\r
118 --convenience function that calls everything
\r
119 worldedit.marker_update = function(name)
\r
120 worldedit.mark_pos1(name, false)
\r
121 worldedit.mark_pos2(name, false)
\r
122 worldedit.mark_region(name)
\r
125 minetest.register_entity(":worldedit:pos1", {
\r
126 initial_properties = {
\r
128 visual_size = {x=1.1, y=1.1},
\r
129 textures = {"worldedit_pos1.png", "worldedit_pos1.png",
\r
130 "worldedit_pos1.png", "worldedit_pos1.png",
\r
131 "worldedit_pos1.png", "worldedit_pos1.png"},
\r
132 collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
\r
135 on_step = function(self, dtime)
\r
136 if worldedit.marker1[self.player_name] == nil then
\r
137 self.object:remove()
\r
140 on_punch = function(self, hitter)
\r
141 self.object:remove()
\r
142 worldedit.marker1[self.player_name] = nil
\r
144 on_blast = function(self, damage)
\r
145 return false, false, {} -- don't damage or knockback
\r
149 minetest.register_entity(":worldedit:pos2", {
\r
150 initial_properties = {
\r
152 visual_size = {x=1.1, y=1.1},
\r
153 textures = {"worldedit_pos2.png", "worldedit_pos2.png",
\r
154 "worldedit_pos2.png", "worldedit_pos2.png",
\r
155 "worldedit_pos2.png", "worldedit_pos2.png"},
\r
156 collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
\r
159 on_step = function(self, dtime)
\r
160 if worldedit.marker2[self.player_name] == nil then
\r
161 self.object:remove()
\r
164 on_punch = function(self, hitter)
\r
165 self.object:remove()
\r
166 worldedit.marker2[self.player_name] = nil
\r
168 on_blast = function(self, damage)
\r
169 return false, false, {} -- don't damage or knockback
\r
173 minetest.register_entity(":worldedit:region_cube", {
\r
174 initial_properties = {
\r
175 visual = "upright_sprite",
\r
176 textures = {"worldedit_cube.png"},
\r
177 visual_size = {x=10, y=10},
\r
180 on_step = function(self, dtime)
\r
181 if worldedit.marker_region[self.player_name] == nil then
\r
182 self.object:remove()
\r
186 on_punch = function(self, hitter)
\r
187 local markers = worldedit.marker_region[self.player_name]
\r
188 if not markers then
\r
191 for _, entity in ipairs(markers) do
\r
194 worldedit.marker_region[self.player_name] = nil
\r
196 on_blast = function(self, damage)
\r
197 return false, false, {} -- don't damage or knockback
\r