mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-29 02:13:01 +00:00
Update a bunch of APi methods
This commit is contained in:
parent
21c5b9d483
commit
a3acf3b16e
7 changed files with 54 additions and 42 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
local wea_c = worldeditadditions_core
|
||||||
|
local Vector3 = wea_c.Vector3
|
||||||
|
|
||||||
--- Scales the defined region by the given scale factor in the given anchors.
|
--- Scales the defined region by the given scale factor in the given anchors.
|
||||||
-- Scale factor vectors containing both scale up and scale down operations are
|
-- Scale factor vectors containing both scale up and scale down operations are
|
||||||
|
@ -11,14 +13,14 @@
|
||||||
-- @param anchor Vector The anchor to scale in - as a vector. e.g. { x = -1, y = 1, z = -1 } would mean scale in the negative x, positive y, and negative z directions.
|
-- @param anchor Vector The anchor to scale in - as a vector. e.g. { x = -1, y = 1, z = -1 } would mean scale in the negative x, positive y, and negative z directions.
|
||||||
-- @return boolean, string|table Whether the operation was successful or not. If not, then an error messagea as a string is also passed. If it was, then a statistics object is returned instead.
|
-- @return boolean, string|table Whether the operation was successful or not. If not, then an error messagea as a string is also passed. If it was, then a statistics object is returned instead.
|
||||||
function worldeditadditions.scale(pos1, pos2, scale, anchor)
|
function worldeditadditions.scale(pos1, pos2, scale, anchor)
|
||||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
pos1, pos2 = Vector3.sort(pos1, pos2)
|
||||||
|
|
||||||
if scale.x == 0 or scale.y == 0 or scale.z == 0 then
|
if scale.x == 0 or scale.y == 0 or scale.z == 0 then
|
||||||
return false, "A component of the scale factoro was 0."
|
return false, "A component of the scale factoro was 0."
|
||||||
end
|
end
|
||||||
|
|
||||||
local scale_down = vector.new(1, 1, 1)
|
local scale_down = Vector3.new(1, 1, 1)
|
||||||
local scale_up = vector.new(1, 1, 1)
|
local scale_up = Vector3.new(1, 1, 1)
|
||||||
|
|
||||||
if scale.x > -1 and scale.x < 1 then scale_down.x = scale.x end
|
if scale.x > -1 and scale.x < 1 then scale_down.x = scale.x end
|
||||||
if scale.y > -1 and scale.y < 1 then scale_down.y = scale.y end
|
if scale.y > -1 and scale.y < 1 then scale_down.y = scale.y end
|
||||||
|
@ -49,7 +51,7 @@ function worldeditadditions.scale(pos1, pos2, scale, anchor)
|
||||||
pos2 = stats.pos2
|
pos2 = stats.pos2
|
||||||
end
|
end
|
||||||
|
|
||||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
pos1, pos2 = Vector3.sort(pos1, pos2)
|
||||||
|
|
||||||
stats_total.pos1 = pos1
|
stats_total.pos1 = pos1
|
||||||
stats_total.pos2 = pos2
|
stats_total.pos2 = pos2
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
local wea = worldeditadditions
|
local wea_c = worldeditadditions_core
|
||||||
|
local Vector3 = wea_c.Vector3
|
||||||
|
|
||||||
|
|
||||||
-- ███████ ██████ █████ ██ ███████ ██ ██ ██████
|
-- ███████ ██████ █████ ██ ███████ ██ ██ ██████
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
-- ███████ ██ ███████ ██ █████ ██ ██ ██████
|
-- ███████ ██ ███████ ██ █████ ██ ██ ██████
|
||||||
|
@ -12,7 +15,7 @@ local wea = worldeditadditions
|
||||||
-- @param anchor Vector The direction to scale in - as a vector. e.g. { x = -1, y = 1, z = -1 } would mean scale in the negative x, positive y, and nevative z directions.
|
-- @param anchor Vector The direction to scale in - as a vector. e.g. { x = -1, y = 1, z = -1 } would mean scale in the negative x, positive y, and nevative z directions.
|
||||||
-- @return boolean, string|table Whether the operation was successful or not. If not, then an error messagea as a string is also passed. If it was, then a statistics object is returned instead.
|
-- @return boolean, string|table Whether the operation was successful or not. If not, then an error messagea as a string is also passed. If it was, then a statistics object is returned instead.
|
||||||
function worldeditadditions.scale_up(pos1, pos2, scale, anchor)
|
function worldeditadditions.scale_up(pos1, pos2, scale, anchor)
|
||||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
pos1, pos2 = Vector3.sort(pos1, pos2)
|
||||||
if (scale.x < 1 and scale.x > -1) and (scale.y < 1 and scale.y > -1) and (scale.z < 1 and scale.z > -1) then
|
if (scale.x < 1 and scale.x > -1) and (scale.y < 1 and scale.y > -1) and (scale.z < 1 and scale.z > -1) then
|
||||||
return false, "Error: Scale factor vectors may not mix values -1 < factor < 1 and (1 < factor or factor < -1) - in other words, you can't scale both up and down at the same time (try worldeditadditions.scale, which automatically applies such scale factor vectors as 2 successive operations)"
|
return false, "Error: Scale factor vectors may not mix values -1 < factor < 1 and (1 < factor or factor < -1) - in other words, you can't scale both up and down at the same time (try worldeditadditions.scale, which automatically applies such scale factor vectors as 2 successive operations)"
|
||||||
end
|
end
|
||||||
|
@ -20,10 +23,10 @@ function worldeditadditions.scale_up(pos1, pos2, scale, anchor)
|
||||||
return false, "Error: One of the components of the anchor vector was 0 (anchor components should either be greater than or less than 0 to indicate the anchor to scale in.)"
|
return false, "Error: One of the components of the anchor vector was 0 (anchor components should either be greater than or less than 0 to indicate the anchor to scale in.)"
|
||||||
end
|
end
|
||||||
|
|
||||||
local size = vector.add(vector.subtract(pos2, pos1), 1)
|
local size = (pos2 - pos1) + 1
|
||||||
|
|
||||||
local pos1_big = vector.new(pos1)
|
local pos1_big = Vector3.new(pos1)
|
||||||
local pos2_big = vector.new(pos2)
|
local pos2_big = Vector3.new(pos2)
|
||||||
|
|
||||||
if anchor.x < 1 then pos1_big.x = pos1_big.x - (size.x * (scale.x - 1))
|
if anchor.x < 1 then pos1_big.x = pos1_big.x - (size.x * (scale.x - 1))
|
||||||
else pos2_big.x = pos2_big.x + (size.x * (scale.x - 1)) end
|
else pos2_big.x = pos2_big.x + (size.x * (scale.x - 1)) end
|
||||||
|
@ -32,9 +35,9 @@ function worldeditadditions.scale_up(pos1, pos2, scale, anchor)
|
||||||
if anchor.z < 1 then pos1_big.z = pos1_big.z - (size.z * (scale.z - 1))
|
if anchor.z < 1 then pos1_big.z = pos1_big.z - (size.z * (scale.z - 1))
|
||||||
else pos2_big.z = pos2_big.z + (size.z * (scale.z - 1)) end
|
else pos2_big.z = pos2_big.z + (size.z * (scale.z - 1)) end
|
||||||
|
|
||||||
local size_big = vector.add(vector.subtract(pos2_big, pos1_big), 1)
|
local size_big = (pos2_big - pos1_big) + 1
|
||||||
|
|
||||||
-- print("scale_up: scaling "..wea.vector.tostring(pos1).." to "..wea.vector.tostring(pos2).." (volume "..worldedit.volume(pos1, pos2).."; size "..wea.vector.tostring(size)..") to "..wea.vector.tostring(pos1_big).." to "..wea.vector.tostring(pos2_big).." (volume "..worldedit.volume(pos1_big, pos2_big).."; size "..wea.vector.tostring(size_big)..")")
|
-- print("scale_up: scaling "..pos1.." to "..pos2.." (volume "..worldedit.volume(pos1, pos2).."; size "..size..") to "..pos1_big.." to "..pos2_big.." (volume "..worldedit.volume(pos1_big, pos2_big).."; size "..size_big..")")
|
||||||
|
|
||||||
local manip_small, area_small = worldedit.manip_helpers.init(pos1, pos2)
|
local manip_small, area_small = worldedit.manip_helpers.init(pos1, pos2)
|
||||||
local manip_big, area_big = worldedit.manip_helpers.init(pos1_big, pos2_big)
|
local manip_big, area_big = worldedit.manip_helpers.init(pos1_big, pos2_big)
|
||||||
|
@ -47,18 +50,18 @@ function worldeditadditions.scale_up(pos1, pos2, scale, anchor)
|
||||||
for z = pos2.z, pos1.z, -1 do
|
for z = pos2.z, pos1.z, -1 do
|
||||||
for y = pos2.y, pos1.y, -1 do
|
for y = pos2.y, pos1.y, -1 do
|
||||||
for x = pos2.x, pos1.x, -1 do
|
for x = pos2.x, pos1.x, -1 do
|
||||||
local posi_rel = vector.subtract({ x = x, y = y, z = z }, pos1)
|
local posi_rel = Vector3.new(x, y, z) - pos1
|
||||||
|
|
||||||
local kern_anchor = {
|
local kern_anchor = Vector3.new(
|
||||||
x = pos1_big.x + (posi_rel.x * scale.x) + (scale.x - 1),
|
pos1_big.x + (posi_rel.x * scale.x) + (scale.x - 1),
|
||||||
y = pos1_big.y + (posi_rel.y * scale.y) + (scale.y - 1),
|
pos1_big.y + (posi_rel.y * scale.y) + (scale.y - 1),
|
||||||
z = pos1_big.z + (posi_rel.z * scale.z) + (scale.z - 1)
|
pos1_big.z + (posi_rel.z * scale.z) + (scale.z - 1)
|
||||||
}
|
)
|
||||||
|
|
||||||
-- print(
|
-- print(
|
||||||
-- "posi", wea.vector.tostring(vector.new(x, y, z)),
|
-- "posi", Vector3.new(x, y, z)),
|
||||||
-- "posi_rel", wea.vector.tostring(posi_rel),
|
-- "posi_rel", posi_rel,
|
||||||
-- "kern_anchor", wea.vector.tostring(kern_anchor)
|
-- "kern_anchor", kern_anchor
|
||||||
-- )
|
-- )
|
||||||
|
|
||||||
local source_val = data_source[area_small:index(x, y, z)]
|
local source_val = data_source[area_small:index(x, y, z)]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
local wea = worldeditadditions
|
local wea_c = worldeditadditions_core
|
||||||
local Vector3 = wea.Vector3
|
local Vector3 = wea_c.Vector3
|
||||||
|
|
||||||
-- ███████ ██████ ██ ██████ █████ ██
|
-- ███████ ██████ ██ ██████ █████ ██
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
@ -71,11 +71,12 @@ function worldeditadditions.spiral_circle(pos1, pos2, target_node, interval_init
|
||||||
if angle > math.pi / 2 then
|
if angle > math.pi / 2 then
|
||||||
acceleration_constant = (interval/angle * acceleration) * step
|
acceleration_constant = (interval/angle * acceleration) * step
|
||||||
end
|
end
|
||||||
radius = 1 + math.floor(interval*(angle / (math.pi*2)), 0)
|
-- BUG: MIGHT BE A BUG. We passed a 2nd param to math.floor, so I added a math.max --@sbrl 2022-09-18 the big upgrade
|
||||||
|
radius = 1 + math.floor(math.max(interval*(angle / (math.pi*2)), 0))
|
||||||
interval = interval_initial + acceleration_constant
|
interval = interval_initial + acceleration_constant
|
||||||
|
|
||||||
|
|
||||||
print("DEBUG cpos", pos_current:multiply(1000):floor():divide(1000), "angle", math.deg(angle), "step", wea.round(math.deg(step), 3), "radius", wea.round(radius, 3), "interval", wea.round(interval, 3), "accel_const", acceleration_constant)
|
print("DEBUG cpos", pos_current:multiply(1000):floor():divide(1000), "angle", math.deg(angle), "step", wea_c.round(math.deg(step), 3), "radius", wea_c.round(radius, 3), "interval", wea_c.round(interval, 3), "accel_const", acceleration_constant)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
local wea = worldeditadditions
|
local wea_c = worldeditadditions_core
|
||||||
local Vector3 = wea.Vector3
|
local Vector3 = wea_c.Vector3
|
||||||
|
|
||||||
-- ███████ ██████ ██ ██████ █████ ██
|
-- ███████ ██████ ██ ██████ █████ ██
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
-- ███████ ██ ██ ██████ ██ ██ ██ ██ ██ ██ ██ ██ █████
|
-- ███████ ██ ██ ██████ ██ ██ ██ ██ ██ ██ ██ ██ █████
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
-- ███████ ██████ ██████ ██████ ██ ████ ██ ██████ ███████
|
-- ███████ ██████ ██████ ██████ ██ ████ ██ ██████ ███████
|
||||||
|
local wea_c = worldeditadditions_core
|
||||||
local wea = worldeditadditions
|
local wea = worldeditadditions
|
||||||
|
|
||||||
-- Counts the number of chunks in the given area.
|
-- Counts the number of chunks in the given area.
|
||||||
|
@ -43,7 +44,7 @@ local function make_stats_obj(state)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function subdivide_step_complete(state)
|
local function subdivide_step_complete(state)
|
||||||
state.times.total = wea.get_ms_time() - state.times.start
|
state.times.total = wea_c.get_ms_time() - state.times.start
|
||||||
|
|
||||||
state.callback_complete(
|
state.callback_complete(
|
||||||
state.pos1,
|
state.pos1,
|
||||||
|
@ -77,18 +78,18 @@ local function subdivide_step_beforeload(state)
|
||||||
if state.cpos1.y < state.pos1.y then state.cpos1.y = state.pos1.y end
|
if state.cpos1.y < state.pos1.y then state.cpos1.y = state.pos1.y end
|
||||||
if state.cpos1.z < state.pos1.z then state.cpos1.z = state.pos1.z end
|
if state.cpos1.z < state.pos1.z then state.cpos1.z = state.pos1.z end
|
||||||
|
|
||||||
state.times.emerge_last = wea.get_ms_time()
|
state.times.emerge_last = wea_c.get_ms_time()
|
||||||
|
|
||||||
-- print("[BEFORE_EMERGE] c1", wea.vector.tostring(state.cpos1), "c2", wea.vector.tostring(state.cpos2), "volume", worldedit.volume(state.cpos1, state.cpos2))
|
-- print("[BEFORE_EMERGE] c1", state.cpos1, "c2", state.cpos2, "volume", worldedit.volume(state.cpos1, state.cpos2))
|
||||||
worldeditadditions.emerge_area(state.cpos1, state.cpos2, state.__afterload, state)
|
worldeditadditions.emerge_area(state.cpos1, state.cpos2, state.__afterload, state)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function subdivide_step_afterload(state_emerge, state_ours)
|
local function subdivide_step_afterload(state_emerge, state_ours)
|
||||||
-- print("[AFTER_EMERGE] c1", wea.vector.tostring(state_ours.cpos1), "c2", wea.vector.tostring(state_ours.cpos2), "volume", worldedit.volume(state_ours.cpos1, state_ours.cpos2))
|
-- print("[AFTER_EMERGE] c1", state_ours.cpos1, "c2", state_ours.cpos2, "volume", worldedit.volume(state_ours.cpos1, state_ours.cpos2))
|
||||||
state_ours.times.emerge_last = wea.get_ms_time() - state_ours.times.emerge_last
|
state_ours.times.emerge_last = wea_c.get_ms_time() - state_ours.times.emerge_last
|
||||||
table.insert(state_ours.times.emerge, state_ours.times.emerge_last)
|
table.insert(state_ours.times.emerge, state_ours.times.emerge_last)
|
||||||
if #state_ours.times.emerge > 25 then
|
if #state_ours.times.emerge > 25 then
|
||||||
state_ours.times.emerge = wea.table.get_last(state_ours.times.emerge, 100)
|
state_ours.times.emerge = wea_c.table.get_last(state_ours.times.emerge, 100)
|
||||||
end
|
end
|
||||||
state_ours.times.emerge_total = state_ours.times.emerge_total + state_ours.times.emerge_last
|
state_ours.times.emerge_total = state_ours.times.emerge_total + state_ours.times.emerge_last
|
||||||
|
|
||||||
|
@ -96,23 +97,23 @@ local function subdivide_step_afterload(state_emerge, state_ours)
|
||||||
|
|
||||||
state_ours.chunks_completed = state_ours.chunks_completed + 1
|
state_ours.chunks_completed = state_ours.chunks_completed + 1
|
||||||
|
|
||||||
local callback_last = wea.get_ms_time()
|
local callback_last = wea_c.get_ms_time()
|
||||||
state_ours.callback_subblock(
|
state_ours.callback_subblock(
|
||||||
state_ours.cpos1,
|
state_ours.cpos1,
|
||||||
state_ours.cpos2,
|
state_ours.cpos2,
|
||||||
make_stats_obj(state_ours)
|
make_stats_obj(state_ours)
|
||||||
)
|
)
|
||||||
state_ours.times.callback_last = wea.get_ms_time() - callback_last
|
state_ours.times.callback_last = wea_c.get_ms_time() - callback_last
|
||||||
table.insert(state_ours.times.callback, state_ours.times.callback_last)
|
table.insert(state_ours.times.callback, state_ours.times.callback_last)
|
||||||
|
|
||||||
state_ours.times.step_last = wea.get_ms_time() - state_ours.times.step_start_abs
|
state_ours.times.step_last = wea_c.get_ms_time() - state_ours.times.step_start_abs
|
||||||
table.insert(state_ours.times.steps, state_ours.times.step_last)
|
table.insert(state_ours.times.steps, state_ours.times.step_last)
|
||||||
if #state_ours.times.steps > 25 then
|
if #state_ours.times.steps > 25 then
|
||||||
state_ours.times.steps = wea.table.get_last(state_ours.times.steps, 100)
|
state_ours.times.steps = wea_c.table.get_last(state_ours.times.steps, 100)
|
||||||
end
|
end
|
||||||
state_ours.times.steps_total = state_ours.times.steps_total + state_ours.times.step_last
|
state_ours.times.steps_total = state_ours.times.steps_total + state_ours.times.step_last
|
||||||
state_ours.times.step_start_abs = wea.get_ms_time()
|
state_ours.times.step_start_abs = wea_c.get_ms_time()
|
||||||
state_ours.eta = wea.eta(
|
state_ours.eta = wea_c.eta(
|
||||||
state_ours.times.steps,
|
state_ours.times.steps,
|
||||||
state_ours.chunks_completed,
|
state_ours.chunks_completed,
|
||||||
state_ours.chunks_total
|
state_ours.chunks_total
|
||||||
|
@ -159,14 +160,14 @@ function worldeditadditions.subdivide(pos1, pos2, chunk_size, callback_subblock,
|
||||||
times = {
|
times = {
|
||||||
-- Total time per step
|
-- Total time per step
|
||||||
steps_total = 0,
|
steps_total = 0,
|
||||||
steps = {}, step_last = 0, step_start_abs = wea.get_ms_time(),
|
steps = {}, step_last = 0, step_start_abs = wea_c.get_ms_time(),
|
||||||
-- Time per step spent on mineteest.emerge_area()
|
-- Time per step spent on mineteest.emerge_area()
|
||||||
emerge_total = 0,
|
emerge_total = 0,
|
||||||
emerge = {}, emerge_last = 0,
|
emerge = {}, emerge_last = 0,
|
||||||
-- Timme per step spent running the callback
|
-- Timme per step spent running the callback
|
||||||
callback = {}, callback_last = 0,
|
callback = {}, callback_last = 0,
|
||||||
-- The start time (absolute)
|
-- The start time (absolute)
|
||||||
start = wea.get_ms_time(),
|
start = wea_c.get_ms_time(),
|
||||||
-- The eta (in ms) until we're done
|
-- The eta (in ms) until we're done
|
||||||
eta = 0
|
eta = 0
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
local wea_c = worldeditadditions_core
|
||||||
|
local Vector3 = wea_c.Vector3
|
||||||
|
|
||||||
--- Generates torus shapes.
|
--- Generates torus shapes.
|
||||||
-- @module worldeditadditions.torus
|
-- @module worldeditadditions.torus
|
||||||
|
|
||||||
|
@ -45,7 +48,7 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n
|
||||||
for x = -total_radius, total_radius do
|
for x = -total_radius, total_radius do
|
||||||
local x_sq = x*x
|
local x_sq = x*x
|
||||||
|
|
||||||
local sq = vector.new(x_sq, y_sq, z_sq)
|
local sq = Vector3.new(x_sq, y_sq, z_sq)
|
||||||
|
|
||||||
-- Default: xy
|
-- Default: xy
|
||||||
if axes == "xz" then
|
if axes == "xz" then
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
local wea_c = worldeditadditions_core
|
||||||
|
local Vector3 = wea_c.Vector3
|
||||||
|
|
||||||
-- ██ ██ █████ ██ ██ ███████
|
-- ██ ██ █████ ██ ██ ███████
|
||||||
-- ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██
|
||||||
|
@ -12,7 +14,7 @@
|
||||||
-- @param node_name string The name of the node to use to create the walls with.
|
-- @param node_name string The name of the node to use to create the walls with.
|
||||||
-- @param thickness number? The thickness of the walls to create. Default: 1
|
-- @param thickness number? The thickness of the walls to create. Default: 1
|
||||||
function worldeditadditions.walls(pos1, pos2, node_name, thickness)
|
function worldeditadditions.walls(pos1, pos2, node_name, thickness)
|
||||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
pos1, pos2 = Vector3.sort(pos1, pos2)
|
||||||
if not thickness then thickness = 1 end
|
if not thickness then thickness = 1 end
|
||||||
-- pos2 will always have the highest co-ordinates now
|
-- pos2 will always have the highest co-ordinates now
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue