Flywheel/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java
2021-06-16 11:19:33 -07:00

32 lines
1.1 KiB
Java

package com.jozufozu.flywheel.mixin;
import java.util.ArrayList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import com.google.common.collect.Lists;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.IInstanceRendered;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
@Mixin(WorldRenderer.class)
public class CancelEntityRenderMixin {
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;getAllEntities()Ljava/lang/Iterable;"))
private Iterable<Entity> filterEntities(ClientWorld world) {
Iterable<Entity> entities = world.getAllEntities();
if (Backend.getInstance().canUseInstancing()) {
ArrayList<Entity> filtered = Lists.newArrayList(entities);
filtered.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderNormally());
return filtered;
}
return entities;
}
}