From 56150b2645f9cb2d37188acb18d1fd2cadd6dc90 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sun, 12 Dec 2021 22:30:46 -0800 Subject: [PATCH] Fix vanishing minecarts --- .../flywheel/backend/instancing/InstanceWorld.java | 11 +++++++++++ .../backend/instancing/InstancedRenderDispatcher.java | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java index 47bf41aa4..278fbe7cf 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java @@ -12,6 +12,7 @@ import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.event.RenderLayerEvent; import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.block.entity.BlockEntity; @@ -100,4 +101,14 @@ public class InstanceWorld { public void renderLayer(RenderLayerEvent event) { engine.render(event, event.buffers.bufferSource()); } + + /** + * Instantiate all the necessary instances to render the given world. + */ + public void loadEntities(ClientLevel world) { + // Block entities are loaded while chunks are baked. + // Entities are loaded with the world, so when chunks are reloaded they need to be re-added. + world.entitiesForRendering() + .forEach(entityInstanceManager::add); + } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java index 8e59f6f15..426ff035b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java @@ -93,7 +93,8 @@ public class InstancedRenderDispatcher { } public static void resetInstanceWorld(ClientLevel world) { - instanceWorlds.replace(world, InstanceWorld::delete); + instanceWorlds.replace(world, InstanceWorld::delete) + .loadEntities(world); } }