You see problem for me is not with your logic
Problem for me is I SUCK WITH ARRAYS
That is why i am able to only give you logic advice and not actual events how to do it
Like i can explain to you how your phone is detecting exact place where you touch the screen (electric short is sent trough largest point touching screen so center of place where you make touch) BUT that does not mean i could build you a touch screen
Other thing you are generating your world
I only need to store it and load it on 2D grid i would split into chunks
Like i said i know how to make grid with shape painter like dynamic one generated from few values
YET idk how to give each grid cel some number and or X and Y pos and use that in array to reference it by its position
But don’t worry one day i will figure it out
Screenshot from you will for sure help me understand something
So lets forget it for now
And about arrays and performance even looping from whole array
FOR EXAMPLE
Right now you are looping trough whole array to check if something is somewhere
So basically you check X and Y pos of something (In your case most likely also Z)
So you have loop trough 3 variables to check if they match with what you need
But to simplify imagine its 2D and let’s use my example
Look i check 2 things IF array X and Y is in some range (basically viewport + padding)
If it should be in that range then i create it
Simple to understand
NOW i am looping trough X and Y of every single object that is stored in my array
I cannot check some range of childs i need to loop trough whole damn array
So i have one main folder with a lot files to check
What if i could make in my main folder many sub folders and loop trough them instead?
I do not need to check every single object all the time
I only need to check if chunk that is in range i care to have objects
Is equal to some X and Y
So instead of checking 2000 vars for X and Y
I could check FOR EXAMPLE 40 sub folders or 40 childs for their X and Y and if their X and Y match what i need then check what is inside of them and inside would be X and Y of all blocks that such chunk should have
For example
Imagine i have 2000 stones here that is like x2 so 4000 child vars to check
What if i could do this
As you see i have here as most top child Chunk and its number next to it
With its X and Y 1st is at 0 0 2nd is at 200 0
So my chunks are 200 pixels wide (well height would be the same)
BUT under it you have multiple child vars representing each object such chunk holds
So instead of looping trough all 8 objects
I would loop trough 4 objects if i would only check X and Y range of single chunk
Imagine if in one chunk i would store 500 objects
Imagine how many chunks i could have before it would start to lag
Now you get the idea?
YET i do not know how to do it with arrays or does it even possible via events