Posted September 29, 201411 yr 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.
September 29, 201411 yr Hi I'm not sure why TileEntity.onChunkUnload() doesn't work for you. If you have two linked blocks, A and B, then when B is unloaded, in b.onChunkUnload(), you need to call a.unlink(b); -TGG
October 1, 201411 yr Author 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.
October 1, 201411 yr As someone new to moding and programming in general I'd be interested in hearing about your solution.
October 1, 201411 yr Author @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.