TelepathicGrunt / StructureTutorialMod

A short example showing how to register a structure and get it to generate in all biomes in NeoForge, Forge, and Fabric! (check the branches)
MIT License
261 stars 29 forks source link

Structure tries to spawn multiple times in the same location (causing world generation to take a lot more time) and sometimes spawns at level 0 #22

Closed Pyrix25633 closed 2 years ago

Pyrix25633 commented 2 years ago

Through logging I've noticed that spawnCheecks and so the getStructureLocation get called over and over again dozens of times for the same location in the same thread consecutively, causing the world generation to take a lot of time. Also I'm creating some end tree structures that should spawn on end islands Repo, but some spawns on Y=0 near the islands edges, and I could not figure out why. image1 image2 And I also get another error

Not all defined tags for registry ResourceKey[minecraft:root / minecraft:worldgen/biome] are present in data pack: improved_end:has_structure/end_highlands

I really hope you can help me out with this.

TelepathicGrunt commented 2 years ago

You have 3 structure sets all with spacing/separation of 1/2 which means each structure set tries to run the different structures for every other chunk. Thus the multiple running per chunk is not the same structure. It’s different structures of yours running for that chunk. https://github.com/Pyrix25633/Fabric-ImprovedEnd/tree/main/src/main/resources/data/improved_end/worldgen/structure_set

The check for the valid biome happens in the StructurePoolBasedGenerator.generate method as it needs the final position due to 3D biomes in overworlds. In end, you can get away with adding a biome check for starting position at y = 60 or so before the terrain checks because terrain checks are expensive and you’re doing it every other chunk.

You’re probably spawning at y=0 Because you never actually checked to make sure the center position fed into the generate method is actually at a terrain greater than 0.

I would say if your structure is spawning this frequently, it should be a feature instead. Structures are for larger stuff that are more uncommon. It is not very suited for these kinds of every or every other chunk spawning due to all the checks and all the piece boundary data that is saved into the chunk.

TelepathicGrunt commented 2 years ago

Your biome tag error is due to the tag name file being typoed here https://github.com/Pyrix25633/Fabric-ImprovedEnd/blob/main/src/main/resources/data/improved_end/tags/worldgen/biome/has_structure/end_higlands.json

Pyrix25633 commented 2 years ago

You’re probably spawning at y=0 Because you never actually checked to make sure the center position fed into the generate method is actually at a terrain greater than 0.

I've understood the rest, but how do I solve this? Because this blockPos.getY(), so startY, is always 0 if I'm not wrong image

TelepathicGrunt commented 2 years ago

Call getHeightOnGround for startBlockPos and make sure terrain y there is not world bottom

Pyrix25633 commented 2 years ago

image Now I see the problem, I'm checking for ground height at chunk center, but spawning it at chunk start, so given that some structures are smaller than 8 blocks they "fall" to y=0, I'll see if I've solved it

Pyrix25633 commented 2 years ago

Not completely solved, I'll let you know

Pyrix25633 commented 2 years ago

I made the structures bigger (added 16x16 circle base), but the problem is still not solved... Also what exactly are "max_distance_from_center" and "size"? Could they be the problem? 2022-09-24_15 36 30

TelepathicGrunt commented 2 years ago

I forgot that the vanilla jigsaw system picks a random piece from the structure pool, rotates it around passed in coordinate as if it is the corner of the piece, and finds the center of that piece, and that's where it snaps to heightmap. So I added a check for your thing to the end of the method https://github.com/Pyrix25633/Fabric-ImprovedEnd/pull/7

However, I looked at your trees. They are 100% not fit for a structure. They are perfect for a feature. This is because well, ever structure spawn has extra data saved into the chunk. Specifically the bounding box of every piece. Since you have no need for knowing if a chunk has a tree, or that a player entered a tree bounding box, and there are so many trees, they should be a feature because right now, the world save is getting bloated with a huge amount of data regarding the structure trees.

Before you ask, yes you can spawn nbt files as part of a feature like vanilla's fossils do. Bonus of this is you control exactly where the nbt file gets placed much easier, is faster to generate during worldgen, and is less memory/data intensive.

Here, you can take my nbt feature class and use/modify it for your purposes. (Note, I use Mojmap mappings so the names of the stuff I use in it may be called something different than in your workspace). https://github.com/TelepathicGrunt/RepurposedStructures-Quilt/blob/latest-released/src/main/java/com/telepathicgrunt/repurposedstructures/world/features/NbtFeature.java

https://github.com/TelepathicGrunt/RepurposedStructures-Quilt/blob/latest-released/src/main/resources/data/repurposed_structures/worldgen/configured_feature/wells/forest.json

Pyrix25633 commented 2 years ago

Oh, thank you very much. I think this issue can be considered now closed.