Jump to content

Recommended Posts

Posted

Hi!

 

I'm having two linked blocks in different dimensions. Each of these blocks is a connector which tries to behave on some of its sides like a tile which is adjacent to its partner's opposite side. For performance reasons, I'm caching those tiles being represented by partners by reference.

Here's the question goes. How can I detect that some instance of TileEntity object is invalid in the sense that some chunk was unloaded, then loaded, and so I need to reacquire TE reference.

The problem is, TE in question and connector might reside in different chunks. So I cannot rely on connector's onChunkUnload.

I cannot also rely on isInvalid, since TE isn't invalidated on unload.

Maybe there's some way to detect chunk unload of adjacent tile?

 

Thanks.

 

Posted

The case is, I'm interested not in linked blocks themselves, but in their immediate neighbors. So I can't rely on my linkers' onChunkUnload, because their neighbor blocks might reside in different chunk.

 

Anyway, I've already devised a not so bad logic, with ChunkEvent.Unload and a custom chunk watcher. This allowed me to watch for tiles of interest right from the linker on the other side.

Posted

@rypofalem Thanks for your interest. Though I can't call my solution very elegant.

 

Code is here https://github.com/target-san/Gateway

The main problem is - it's Scala, and not very clean.

The classes of interest are TileSatellite, ChunkWatcher and EventHandler.

 

The main idea:

1. Satellite TE (the watcher) asks ChunkWatcher to register itself as a watcher for specific block. In fact, a whole chunk is added to its internal multimap.

2. EventHandler catches ChunkEvent.Unload, then calls ChunkWatcher.onChunkUnload. The latter finds set of watcher 4D coordinates by their chunk coordinate key, then calls onWatchedChunkUnload for those which are loaded at the moment.

 

Please note that there's a bug in my code elsewhere, so you won't be able to run the whole mod from master now.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.