Make TEs invalidate capabilities when the chunk they are in unloads (#7529)

Fixed LazyOptional potentially notifying invalidation listeners multiple times.
This commit is contained in:
Richard Freimer authored and GitHub committed 2020-12-05 12:05:32 -08:00
1 parent 27220a5ad8
commit 1a539ffebc
2 files changed
+18 -7

No files matched your search

@@ -318,13 +318,17 @@ public class LazyOptional<T>
* call this, if they are covered with a microblock panel, thus cutting off pipe
* connectivity to this side.
* <p>
* Also should be called for all when a TE is invalidated, or a world/chunk
* unloads, or a entity dies, etc... This allows modders to keep a cache of
* capability objects instead of re-checking them every tick.
* Also should be called for all when a TE is invalidated (for example, when
* the TE is removed or unloaded), or a world/chunk unloads, or a entity dies,
* etc... This allows modders to keep a cache of capability objects instead of
* re-checking them every tick.
*/
public void invalidate()
{
this.isValid = false;
this.listeners.forEach(e -> e.accept(this));
if (this.isValid)
{
this.isValid = false;
this.listeners.forEach(e -> e.accept(this));
}
}
}