Making something similar to /locate from MC

I’m once again asking for yall’s help.

TL;DR : how would I locating an un-generated structure similar to how Minecraft’s /locate works

I’m making an entirely procedurally generated map, and the structures are giving me a hard time, since currently, I generate them separately from the terrain, it started bringing up issues such as holes entirely through the terrain when it clears an area for the structure, or the structure being buried.

Then I thought : “I can just make the terrain shape into the needed size for the structures”, but now there’s of course a new issue.

I originally just had it morph AFTER generating the structure, but with how my terrain system works, it only loads a “chunk” once unless it gets unloaded, which means, half the terrain is shaped correctly, while the other half is the same as it would have been without the structure, so I scraped that idea.

My second idea was to, every time I generate a chunk, check within a certain radius(I was using the largest structure’s size) using the same random noise that determines if a structure generates to see if I needed to start shaping it, which honestly, worked fairly well, HOWEVER, this was far from flaw free, for one thing, it took the average chunk loading/generating time up from like 2 seconds all the way to upwards of 25 seconds, which if I tried to speed it up, it would start timing out, since it pretty much just

local NearStructurePos = {}
for x = -Size / 2, Size / 2 do
   for z =  -Size / 2, Size / 2 do
      local StructureHere = RandomFunction(x, seed, z) > .9
      
      if StructureHere then
         table.insert(NearStructurePos, Vector2.new(x, z))
      end
      if z % 50 == 1 then task.wait() end
   end
end

And from there I would alter the terrain based off of those saved positions(yes I know it doesn’t deal with height, I’m only doing surface structures so it doesn’t matter yet)

So if any of you people who are smart with math and this sort of thing(or happen to have access to the MC source code for /locate) please share, I’m so stuck on what to do.(if you want/need more code to help, lemme know)

1 Like