1 -- Expands or contracts the cuboid in all axes by amount (positive or negative)
2 worldedit.cuboid_volumetric_expand = function(name, amount)
3 local pos1 = worldedit.pos1[name]
4 local pos2 = worldedit.pos2[name]
6 if pos1 == nil or pos2 == nil then
7 return false, "Undefined cuboid"
10 local delta1 = vector.new()
11 local delta2 = vector.new()
15 delta1 = vector.add(delta1, amount)
16 delta2 = vector.add(delta2, amount)
17 delta_dir1, delta_dir2 = worldedit.get_expansion_directions(pos1, pos2)
18 delta1 = vector.multiply(delta1, delta_dir1)
19 delta2 = vector.multiply(delta2, delta_dir2)
20 worldedit.pos1[name] = vector.add(pos1, delta1)
21 worldedit.pos2[name] = vector.add(pos2, delta2)
27 -- Expands or contracts the cuboid in a single axis by amount (positive or negative)
28 worldedit.cuboid_linear_expand = function(name, axis, direction, amount)
29 local pos1 = worldedit.pos1[name]
30 local pos2 = worldedit.pos2[name]
32 if pos1 == nil or pos2 == nil then
33 return false, "undefined cuboid"
36 if direction ~= 1 and direction ~= -1 then
37 return false, "invalid marker"
40 local marker = worldedit.marker_get_closest_to_axis(name, axis, direction)
41 local deltavect = vector.new()
44 deltavect.x = amount * direction
45 elseif axis == 'y' then
46 deltavect.y = amount * direction
47 elseif axis == 'z' then
48 deltavect.z = amount * direction
50 return false, "invalid axis"
53 worldedit.marker_move(name, marker, deltavect)
58 -- Shifts the cuboid by '+-amount' in axis 'axis'
59 worldedit.cuboid_shift = function(name, axis, amount)
60 local pos1 = worldedit.pos1[name]
61 local pos2 = worldedit.pos2[name]
63 if pos1 == nil or pos2 == nil then
64 return false, "undefined cuboid"
68 worldedit.pos1[name].x = pos1.x + amount
69 worldedit.pos2[name].x = pos2.x + amount
70 elseif axis == 'y' then
71 worldedit.pos1[name].y = pos1.y + amount
72 worldedit.pos2[name].y = pos2.y + amount
73 elseif axis == 'z' then
74 worldedit.pos1[name].z = pos1.z + amount
75 worldedit.pos2[name].z = pos2.z + amount
77 return false, "invalid axis"
84 -- Moves the location of a single marker by adding deltavector
85 worldedit.marker_move = function(name, marker, deltavector)
86 if marker ~= 1 and marker ~= 2 then
91 local pos = worldedit.pos1[name]
92 worldedit.pos1[name] = vector.add(deltavector, pos)
94 local pos = worldedit.pos2[name]
95 worldedit.pos2[name] = vector.add(deltavector, pos)
101 -- Updates the location ingame of the markers
102 worldedit.marker_update = function(name, marker)
103 if marker == nil then
104 worldedit.mark_pos1(name)
105 worldedit.mark_pos2(name)
106 elseif marker == 1 then
107 worldedit.mark_pos1(name)
108 elseif marker == 2 then
109 worldedit.mark_pos2(name)
112 "worldedit: Invalid execution of function update_markers")
117 -- Returns two vectors with the directions for volumetric expansion
118 worldedit.get_expansion_directions = function(mark1, mark2)
119 if mark1 == nil or mark2 == nil then
122 local dir1 = vector.new()
123 local dir2 = vector.new()
125 if mark1.x < mark2.x then
132 if mark1.y < mark2.y then
139 if mark1.z < mark2.z then
150 -- Return the marker that is closest to the player
151 worldedit.marker_get_closest_to_player = function(name)
152 local playerpos = minetest.get_player_by_name(name):getpos()
153 local dist1 = vector.distance(playerpos, worldedit.pos1[name])
154 local dist2 = vector.distance(playerpos, worldedit.pos2[name])
156 if dist1 < dist2 then
164 -- Returns the closest marker to the specified axis and direction
165 worldedit.marker_get_closest_to_axis = function(name, axis, direction)
166 local pos1 = vector.new()
167 local pos2 = vector.new()
169 if direction ~= 1 and direction ~= -1 then
174 pos1.x = worldedit.pos1[name].x * direction
175 pos2.x = worldedit.pos2[name].x * direction
176 if pos1.x > pos2.x then
181 elseif axis == 'y' then
182 pos1.y = worldedit.pos1[name].y * direction
183 pos2.y = worldedit.pos2[name].y * direction
184 if pos1.y > pos2.y then
189 elseif axis == 'z' then
190 pos1.z = worldedit.pos1[name].z * direction
191 pos2.z = worldedit.pos2[name].z * direction
192 if pos1.z > pos2.z then
203 -- Translates up, down, left, right, front, back to their corresponding axes and
204 -- directions according to faced direction
205 worldedit.translate_direction = function(name, direction)
206 local axis, dir = worldedit.player_axis(name)
207 local resaxis, resdir
209 if direction == "up" then
213 if direction == "down" then
217 if direction == "front" then
227 if direction == "back" then
237 if direction == "left" then
241 elseif axis == 'z' then
247 if direction == "right" then
251 elseif axis == 'z' then
257 return resaxis, resdir