diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 52bfb4fe8..88c5b0194 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -7,6 +7,7 @@ import java.util.function.Function; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.content.contraptions.components.structureMovement.render.SBBContraptionManager; import com.simibubi.create.content.contraptions.relays.encased.CasingConnectivity; import com.simibubi.create.content.curiosities.armor.CopperBacktankArmorLayer; import com.simibubi.create.content.curiosities.bell.SoulPulseEffectHandler; @@ -94,7 +95,7 @@ public class CreateClient { public static void clientInit(FMLClientSetupEvent event) { BUFFER_CACHE.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); - BUFFER_CACHE.registerCompartment(ContraptionRenderDispatcher.CONTRAPTION, 20); + BUFFER_CACHE.registerCompartment(SBBContraptionManager.CONTRAPTION, 20); BUFFER_CACHE.registerCompartment(WorldSectionElement.DOC_WORLD_SECTION, 20); AllKeys.register(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index f74968039..98e5e9fbb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -44,7 +44,16 @@ public class ContraptionRenderDispatcher { private static WorldAttached> WORLDS = new WorldAttached<>(SBBContraptionManager::new); - public static final Compartment> CONTRAPTION = new Compartment<>(); + /** + * Reset a contraption's renderer. + * @param contraption The contraption to invalidate. + * @return true if there was a renderer associated with the given contraption. + */ + public static boolean invalidate(Contraption contraption) { + World level = contraption.entity.level; + + return WORLDS.get(level).invalidate(contraption); + } public static void tick(World world) { if (Minecraft.getInstance().isPaused()) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java index 2b628393e..861db5c41 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java @@ -68,4 +68,8 @@ public class ContraptionRenderInfo { public ContraptionMatrices getMatrices() { return matrices; } + + public void invalidate() { + + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java index 735d569f1..5bc3abed3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java @@ -29,6 +29,20 @@ public abstract class ContraptionRenderManager this.world = (World) world; } + public boolean invalidate(Contraption contraption) { + int entityId = contraption.entity.getId(); + + C removed = renderInfos.remove(entityId); + + if (removed != null) { + removed.invalidate(); + visible.remove(removed); + return true; + } + + return false; + } + public void renderLayer(RenderLayerEvent event) { for (C c : visible) { c.setupMatrices(event.stack, event.camX, event.camY, event.camZ); @@ -85,6 +99,9 @@ public abstract class ContraptionRenderManager } public void delete() { + for (C renderer : renderInfos.values()) { + renderer.invalidate(); + } renderInfos.clear(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java index efd42ad70..05485d3ad 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java @@ -94,12 +94,4 @@ public class FlwContraptionManager extends ContraptionRenderManager { + public static final Compartment> CONTRAPTION = new Compartment<>(); + public SBBContraptionManager(IWorld world) { super(world); } @@ -25,6 +26,14 @@ public class SBBContraptionManager extends ContraptionRenderManager renderContraptionLayerSBB(event, info)); } + @Override + public boolean invalidate(Contraption contraption) { + for (RenderType chunkBufferLayer : RenderType.chunkBufferLayers()) { + CreateClient.BUFFER_CACHE.invalidate(CONTRAPTION, Pair.of(contraption, chunkBufferLayer)); + } + return super.invalidate(contraption); + } + @Override protected ContraptionRenderInfo create(Contraption c) { PlacementSimulationWorld renderWorld = ContraptionRenderDispatcher.setupRenderWorld(world, c);