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)
102 -- Returns two vectors with the directions for volumetric expansion
103 worldedit.get_expansion_directions = function(mark1, mark2)
104 if mark1 == nil or mark2 == nil then
107 local dir1 = vector.new()
108 local dir2 = vector.new()
110 if mark1.x < mark2.x then
117 if mark1.y < mark2.y then
124 if mark1.z < mark2.z then
135 -- Return the marker that is closest to the player
136 worldedit.marker_get_closest_to_player = function(name)
137 local playerpos = minetest.get_player_by_name(name):get_pos()
138 local dist1 = vector.distance(playerpos, worldedit.pos1[name])
139 local dist2 = vector.distance(playerpos, worldedit.pos2[name])
141 if dist1 < dist2 then
149 -- Returns the closest marker to the specified axis and direction
150 worldedit.marker_get_closest_to_axis = function(name, axis, direction)
151 local pos1 = vector.new()
152 local pos2 = vector.new()
154 if direction ~= 1 and direction ~= -1 then
159 pos1.x = worldedit.pos1[name].x * direction
160 pos2.x = worldedit.pos2[name].x * direction
161 if pos1.x > pos2.x then
166 elseif axis == 'y' then
167 pos1.y = worldedit.pos1[name].y * direction
168 pos2.y = worldedit.pos2[name].y * direction
169 if pos1.y > pos2.y then
174 elseif axis == 'z' then
175 pos1.z = worldedit.pos1[name].z * direction
176 pos2.z = worldedit.pos2[name].z * direction
177 if pos1.z > pos2.z then
188 -- Translates up, down, left, right, front, back to their corresponding axes and
189 -- directions according to faced direction
190 worldedit.translate_direction = function(name, direction)
191 local axis, dir = worldedit.player_axis(name)
192 local resaxis, resdir
194 if direction == "up" then
198 if direction == "down" then
202 if direction == "front" then
212 if direction == "back" then
222 if direction == "left" then
226 elseif axis == 'z' then
232 if direction == "right" then
236 elseif axis == 'z' then
242 return resaxis, resdir