From 195a7348f397cb7da14a5b7bfe6ba18f006d2adc Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 24 Jun 2021 19:37:31 -0700 Subject: [PATCH] Instanced entities are compatible with optifine - Fix mixin related crash on startup - Change defaultRequire to 0 --- .../mixin/CancelEntityRenderMixin.java | 19 ++++++++++++++++++- src/main/resources/flywheel.mixins.json | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java index 069563702..01aaa75ea 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java @@ -1,9 +1,11 @@ package com.jozufozu.flywheel.mixin; import java.util.ArrayList; +import java.util.Iterator; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Group; import org.spongepowered.asm.mixin.injection.Redirect; import com.google.common.collect.Lists; @@ -13,20 +15,35 @@ import com.jozufozu.flywheel.backend.instancing.IInstanceRendered; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; +import net.minecraft.util.ClassInheritanceMultiMap; @Mixin(WorldRenderer.class) public class CancelEntityRenderMixin { + @Group(name = "entityFilter", min = 1, max = 1) @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;getAllEntities()Ljava/lang/Iterable;")) private Iterable filterEntities(ClientWorld world) { Iterable entities = world.getAllEntities(); if (Backend.getInstance().canUseInstancing()) { ArrayList filtered = Lists.newArrayList(entities); - filtered.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderNormally()); + filtered.removeIf(entity -> entity instanceof IInstanceRendered && !((IInstanceRendered) entity).shouldRenderNormally()); return filtered; } return entities; } + + @Group(name = "entityFilter") + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ClassInheritanceMultiMap;iterator()Ljava/util/Iterator;")) + private Iterator filterEntitiesOF(ClassInheritanceMultiMap classInheritanceMultiMap) { + if (Backend.getInstance().canUseInstancing()) { + + ArrayList filtered = Lists.newArrayList(classInheritanceMultiMap); + filtered.removeIf(entity -> entity instanceof IInstanceRendered && !((IInstanceRendered) entity).shouldRenderNormally()); + + return filtered.iterator(); + } + return classInheritanceMultiMap.iterator(); + } } diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index b2632dec9..42f08b576 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -19,6 +19,6 @@ "light.NetworkLightUpdateMixin" ], "injectors": { - "defaultRequire": 1 + "defaultRequire": 0 } }