From 6dc4a18ed34e5f4c6a69318ee73634fb0e74ac8e Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 25 Feb 2021 17:16:22 -0800 Subject: [PATCH] Extra safety checks. --- .../instancing/InstancedTileRenderer.java | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java index 9c3c1ced0..524d36a91 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java @@ -2,7 +2,6 @@ package com.simibubi.create.foundation.render.backend.instancing; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import javax.annotation.Nullable; @@ -10,14 +9,13 @@ import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.render.backend.gl.BasicProgram; import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.WorldAttached; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.world.ClientWorld; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; public abstract class InstancedTileRenderer

{ protected Map> instances = new HashMap<>(); @@ -42,6 +40,17 @@ public abstract class InstancedTileRenderer

{ } } + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) { + render(layer, viewProjection, camX, camY, camZ, null); + } + + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, ShaderCallback

callback) { + for (RenderMaterial material : materials.values()) { + if (material.canRenderInLayer(layer)) + material.render(layer, viewProjection, camX, camY, camZ, callback); + } + } + @SuppressWarnings("unchecked") public > RenderMaterial getMaterial(MaterialType materialType) { return (RenderMaterial) materials.get(materialType); @@ -55,7 +64,7 @@ public abstract class InstancedTileRenderer

{ @SuppressWarnings("unchecked") @Nullable public TileEntityInstance getInstance(T tile, boolean create) { - if (!Backend.canUseInstancing()) return null; + if (!Backend.canUseInstancing() || isTileUnloaded(tile)) return null; TileEntityInstance instance = instances.get(tile); @@ -128,14 +137,17 @@ public abstract class InstancedTileRenderer

{ instances.clear(); } - public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) { - render(layer, viewProjection, camX, camY, camZ, null); - } + public boolean isTileUnloaded(TileEntity tile) { + if (tile.isRemoved()) return true; - public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, ShaderCallback

callback) { - for (RenderMaterial material : materials.values()) { - if (material.canRenderInLayer(layer)) - material.render(layer, viewProjection, camX, camY, camZ, callback); - } + World world = tile.getWorld(); + + if (world == null) return true; + + BlockPos pos = tile.getPos(); + + IBlockReader existingChunk = world.getExistingChunk(pos.getX() >> 4, pos.getZ() >> 4); + + return existingChunk == null; } }