Team-EnderIO / EnderIO

EnderIO Rewritten for Modern Minecraft.
https://enderio.com
The Unlicense
341 stars 108 forks source link

ChunkBoundLookup for Obelisk Managers #747

Closed Rover656 closed 4 months ago

Rover656 commented 4 months ago

Description

Implements a fast way to lookup objects based on ChunkPos.

Uses this to implement Obelisk Manager's - these are used to handle event-based obelisks where we can gather a subset of obelisks that are in effect on a certain point in the world, without having to check all obelisks in the world.

I've implemented this as a level attachment, removing the need for explicit dimension checks.

Closes #742

Breaking Changes

No public API or gameplay breaking changes.

Checklist

HenryLoenwind commented 4 months ago

BTW: In 1.12 we made sure the event handler got only registered when the first Obelisk was loaded because of the typical amount of Obelisks placed in a world (0). This may not be obvious from the code, as it uses classloading and registering in a static block to accomplish that.

Rover656 commented 4 months ago

BTW: In 1.12 we made sure the event handler got only registered when the first Obelisk was loaded because of the typical amount of Obelisks placed in a world (0). This may not be obvious from the code, as it uses classloading and registering in a static block to accomplish that.

That's a good shout, I'll look at registering the event after the first obelisk is placed :)

Rover656 commented 4 months ago

I was looking into making this change, but honestly I don't think there's much overhead here to be worried about - just to help with it though, I've added an explicit check for the level attachment high up in each event handler - if the attachment exists, then an obelisk has been placed at some point.

If this does prove to be a performance concern down the line, then we can explore alternative ways of not registering the event :)