mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
//subdivide: fix crash
This commit is contained in:
parent
ee4b3e09bb
commit
fd3ee43728
2 changed files with 18 additions and 12 deletions
|
@ -3,6 +3,11 @@ It's about time I started a changelog! This will serve from now on as the main c
|
||||||
|
|
||||||
Note to self: See the bottom of this file for the release template text.
|
Note to self: See the bottom of this file for the release template text.
|
||||||
|
|
||||||
|
|
||||||
|
## v1.14.2: The multipoint update, hotfix 2 (15th July 2023)
|
||||||
|
- Fix crash in `//subdivide`, again due to the new position system
|
||||||
|
|
||||||
|
|
||||||
## v1.14.1: The multipoint update, hotfix 1 (12th July 2023)
|
## v1.14.1: The multipoint update, hotfix 1 (12th July 2023)
|
||||||
- Fix issue #100, which caused a crash as `//pos1` and `//pos2` allowed non-integer positions to be set
|
- Fix issue #100, which caused a crash as `//pos1` and `//pos2` allowed non-integer positions to be set
|
||||||
|
|
||||||
|
|
|
@ -5,17 +5,18 @@
|
||||||
-- ███████ ██████ ██████ ██████ ██ ████ ██ ██████ ███████
|
-- ███████ ██████ ██████ ██████ ██ ████ ██ ██████ ███████
|
||||||
local wea_c = worldeditadditions_core
|
local wea_c = worldeditadditions_core
|
||||||
local wea = worldeditadditions
|
local wea = worldeditadditions
|
||||||
|
local Vector3 = wea_c.Vector3
|
||||||
|
|
||||||
-- Counts the number of chunks in the given area.
|
-- Counts the number of chunks in the given area.
|
||||||
-- Maths is now done properly. Values from this new implementation were tested
|
-- Maths is now done properly. Values from this new implementation were tested
|
||||||
-- with 1000 random pos1, pos2, and chunk_size combinations and found to be identical.
|
-- with 1000 random pos1, pos2, and chunk_size combinations and found to be identical.
|
||||||
local function count_chunks(pos1, pos2, chunk_size)
|
local function count_chunks(pos1, pos2, chunk_size)
|
||||||
-- Assume pos1 & pos2 are sorted
|
-- Assume pos1 & pos2 are sorted
|
||||||
local dimensions = {
|
local dimensions = Vector3.new(
|
||||||
x = pos2.x - pos1.x + 1,
|
pos2.x - pos1.x + 1,
|
||||||
y = pos2.y - pos1.y + 1,
|
pos2.y - pos1.y + 1,
|
||||||
z = pos2.z - pos1.z + 1,
|
pos2.z - pos1.z + 1
|
||||||
}
|
)
|
||||||
-- print("[new] dimensions", dimensions.x, dimensions.y, dimensions.z)
|
-- print("[new] dimensions", dimensions.x, dimensions.y, dimensions.z)
|
||||||
return math.ceil(dimensions.x / chunk_size.x)
|
return math.ceil(dimensions.x / chunk_size.x)
|
||||||
* math.ceil(dimensions.y / chunk_size.y)
|
* math.ceil(dimensions.y / chunk_size.y)
|
||||||
|
@ -68,12 +69,12 @@ local function subdivide_step_beforeload(state)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
state.cpos2 = { x = state.cpos.x, y = state.cpos.y, z = state.cpos.z }
|
state.cpos2 = Vector3.new(state.cpos.x, state.cpos.y, state.cpos.z)
|
||||||
state.cpos1 = {
|
state.cpos1 = Vector3.new(
|
||||||
x = state.cpos.x - state.chunk_size.x,
|
state.cpos.x - state.chunk_size.x,
|
||||||
y = state.cpos.y - state.chunk_size.y,
|
state.cpos.y - state.chunk_size.y,
|
||||||
z = state.cpos.z - state.chunk_size.z
|
state.cpos.z - state.chunk_size.z
|
||||||
}
|
)
|
||||||
if state.cpos1.x < state.pos1.x then state.cpos1.x = state.pos1.x end
|
if state.cpos1.x < state.pos1.x then state.cpos1.x = state.pos1.x end
|
||||||
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
|
||||||
|
@ -151,7 +152,7 @@ function worldeditadditions.subdivide(pos1, pos2, chunk_size, callback_subblock,
|
||||||
local state = {
|
local state = {
|
||||||
pos1 = pos1, pos2 = pos2,
|
pos1 = pos1, pos2 = pos2,
|
||||||
-- Note that we start 1 over on the Z axis because we increment *before* calling the callback, so if we don't fiddle it here, we'll miss the first chunk
|
-- Note that we start 1 over on the Z axis because we increment *before* calling the callback, so if we don't fiddle it here, we'll miss the first chunk
|
||||||
cpos = { x = pos2.x, y = pos2.y, z = pos2.z + chunk_size.z + 1 },
|
cpos = Vector3.new(pos2.x, pos2.y, pos2.z + chunk_size.z + 1),
|
||||||
-- The size of a single subblock
|
-- The size of a single subblock
|
||||||
chunk_size = chunk_size,
|
chunk_size = chunk_size,
|
||||||
-- The total number of nodes in the defined region
|
-- The total number of nodes in the defined region
|
||||||
|
|
Loading…
Reference in a new issue