Fix nullpointer when contraptions stop

This commit is contained in:
Jozufozu 2021-08-02 00:08:26 -07:00
parent c674b5df8d
commit 468435e1a0
2 changed files with 19 additions and 8 deletions

View File

@ -50,13 +50,17 @@ public abstract class ContraptionRenderManager<C extends ContraptionRenderInfo>
}
public void beginFrame(BeginFrameEvent event) {
visible.clear();
renderInfos.int2ObjectEntrySet()
.stream()
.map(Map.Entry::getValue)
.forEach(renderInfo -> renderInfo.beginFrame(event));
collectVisible();
}
protected void collectVisible() {
visible.clear();
renderInfos.int2ObjectEntrySet()
.stream()
.map(Map.Entry::getValue)
@ -80,6 +84,9 @@ public abstract class ContraptionRenderManager<C extends ContraptionRenderInfo>
renderInfos.clear();
}
/**
* Remove all render infos associated with dead/removed contraptions.
*/
public void removeDeadRenderers() {
renderInfos.values().removeIf(ContraptionRenderInfo::isDead);
}

View File

@ -80,13 +80,17 @@ public class FlwContraptionManager extends ContraptionRenderManager<RenderedCont
@Override
public void removeDeadRenderers() {
renderInfos.values().removeIf(renderer -> {
if (renderer.isDead()) {
renderer.invalidate();
return true;
}
return false;
});
boolean removed = renderInfos.values()
.removeIf(renderer -> {
if (renderer.isDead()) {
renderer.invalidate();
return true;
}
return false;
});
// we use visible in #tick() so we have to re-evaluate it if any were removed
if (removed) collectVisible();
}
@Override