im working on a script to merge blocks that are the same colour, they currently merge in invalid spots though, any ideas on how i could implement a check for this in my --y code?
relevant snippet:
-- x
for x = 2, GRIDSIZE do
for z = 1, GRIDSIZE do
for y, size in pairs(sizes[x][z]) do
if sizes[x - 1][z][y] == nil then continue end
if size.X ~= sizes[x - 1][z][y].X then continue end
if blocks[x][z][y].Colour ~= blocks[x - 1][z][y].Colour then continue end
sizes[x][z][y].X += sizes[x-1][z][y].X
sizes[x-1][z][y] = nil
end
end
end
-- z
for x = 1, GRIDSIZE do
for z = 2, GRIDSIZE do
for y, size in pairs(sizes[x][z]) do
if sizes[x][z-1][y] == nil then continue end
if size.Z ~= sizes[x][z-1][y].Z then continue end
if blocks[x][z].Colour ~= blocks[x][z - 1][y].Colour then continue end
sizes[x][z][y].Z += sizes[x][z - 1][y].Z
sizes[x][z - 1][y] = nil
end
end
end
-- y
for x = 1, GRIDSIZE do
for z = 1, GRIDSIZE do
for y, size in pairs(sizes[x][z]) do
if sizes[x][z][y-1] == nil then continue end
if size.Y ~= sizes[x][z][y-1].Y then continue end
if blocks[x][z][y].Colour ~= blocks[x][z][y-1].Colour then continue end
sizes[x][z][y].Y = sizes[x][z][y].Y + sizes[x][z][y-1].Y
sizes[x][z][y-1] = nil
end
end
end