The Twilight Forest

The Twilight Forest

140M Downloads

[Suggestion] Do not loop over entire structure registry every mob spawn attempt

TelepathicGrunt opened this issue ยท 3 comments

commented

The Suggestion

This seems inefficient and will perform increasingly worse the larger the pack is as more and more structures are added to the registry.

Iterable<Structure> structures = structureManager.registryAccess().registryOrThrow(Registries.STRUCTURE);

Why Should It Be in the Mod?

The solution would be to either cache the structures that you're interested in from the registry or use a structure tag to collect your structure together and then grab the entries of the tag when needed instead of looping the whole registry. Example:
https://github.com/TelepathicGrunt/RepurposedStructures/blob/8b65df28e4ef45a0a2918b0cf93485921218299b/common/src/main/java/com/telepathicgrunt/repurposedstructures/mixins/features/NoVinesInStructuresMixin.java#L41

Please Read and Confirm the Following

  • I have confirmed this suggestion is unique and has not been suggested already.
commented

There's a cache

commented

Hmm I miss read the code. Does the cache bust on world exit and re-entering?

commented

It's a WeakHashMap