diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IFlywheelWorld.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IFlywheelWorld.java new file mode 100644 index 000000000..91684c428 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IFlywheelWorld.java @@ -0,0 +1,13 @@ +package com.simibubi.create.foundation.render.backend.instancing; + +/** + * A marker interface custom worlds can override to indicate + * that tiles inside the world should render with Flywheel. + * + * Minecraft.getInstance().world will always support Flywheel. + */ +public interface IFlywheelWorld { + default boolean supportsFlywheel() { + return true; + } +} 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 4cd6ce646..ef3a3aeea 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 @@ -4,11 +4,13 @@ import java.util.*; import javax.annotation.Nullable; +import com.simibubi.create.foundation.ponder.PonderWorld; 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 net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; import net.minecraft.tileentity.TileEntity; @@ -69,7 +71,7 @@ public abstract class InstancedTileRenderer

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

{ tickableInstances.clear(); } - public boolean isTileUnloaded(TileEntity tile) { - if (tile.isRemoved()) return true; + public boolean canCreateInstance(TileEntity tile) { + if (tile.isRemoved()) return false; World world = tile.getWorld(); - if (world == null) return true; + if (world == null) return false; - BlockPos pos = tile.getPos(); + if (world == Minecraft.getInstance().world) { + BlockPos pos = tile.getPos(); - IBlockReader existingChunk = world.getExistingChunk(pos.getX() >> 4, pos.getZ() >> 4); + IBlockReader existingChunk = world.getExistingChunk(pos.getX() >> 4, pos.getZ() >> 4); - return existingChunk == null; + return existingChunk != null; + } + + return world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel(); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java index 8e8d71b3c..9e548cf46 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.function.Predicate; +import com.simibubi.create.foundation.render.backend.instancing.IFlywheelWorld; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.tileentity.TileEntity; @@ -13,7 +14,7 @@ import net.minecraft.util.math.SectionPos; import net.minecraft.world.World; import net.minecraft.world.lighting.WorldLightManager; -public class PlacementSimulationWorld extends WrappedWorld { +public class PlacementSimulationWorld extends WrappedWorld implements IFlywheelWorld { public HashMap blocksAdded; public HashMap tesAdded;