2021-06-16 21:57:52 +02:00
|
|
|
package com.jozufozu.flywheel.mixin;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2021-06-25 04:37:31 +02:00
|
|
|
import java.util.Iterator;
|
2021-06-16 21:57:52 +02:00
|
|
|
|
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
2021-06-25 04:37:31 +02:00
|
|
|
import org.spongepowered.asm.mixin.injection.Group;
|
2021-06-16 21:57:52 +02:00
|
|
|
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;
|
2021-06-25 04:37:31 +02:00
|
|
|
import net.minecraft.util.ClassInheritanceMultiMap;
|
2021-06-16 21:57:52 +02:00
|
|
|
|
|
|
|
@Mixin(WorldRenderer.class)
|
|
|
|
public class CancelEntityRenderMixin {
|
|
|
|
|
2021-06-25 04:37:31 +02:00
|
|
|
@Group(name = "entityFilter", min = 1, max = 1)
|
2021-06-16 21:57:52 +02:00
|
|
|
@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();
|
2021-06-30 21:43:54 +02:00
|
|
|
if (Backend.getInstance()
|
|
|
|
.canUseInstancing()) {
|
2021-06-16 21:57:52 +02:00
|
|
|
|
|
|
|
ArrayList<Entity> filtered = Lists.newArrayList(entities);
|
2021-06-25 04:37:31 +02:00
|
|
|
filtered.removeIf(entity -> entity instanceof IInstanceRendered && !((IInstanceRendered) entity).shouldRenderNormally());
|
2021-06-16 21:57:52 +02:00
|
|
|
|
|
|
|
return filtered;
|
|
|
|
}
|
|
|
|
return entities;
|
|
|
|
}
|
2021-06-25 04:37:31 +02:00
|
|
|
|
|
|
|
@Group(name = "entityFilter")
|
|
|
|
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ClassInheritanceMultiMap;iterator()Ljava/util/Iterator;"))
|
|
|
|
private Iterator<Entity> filterEntitiesOF(ClassInheritanceMultiMap<Entity> classInheritanceMultiMap) {
|
2021-06-30 21:43:54 +02:00
|
|
|
if (Backend.getInstance()
|
|
|
|
.canUseInstancing()) {
|
2021-06-25 04:37:31 +02:00
|
|
|
|
|
|
|
ArrayList<Entity> filtered = Lists.newArrayList(classInheritanceMultiMap);
|
|
|
|
filtered.removeIf(entity -> entity instanceof IInstanceRendered && !((IInstanceRendered) entity).shouldRenderNormally());
|
|
|
|
|
|
|
|
return filtered.iterator();
|
|
|
|
}
|
|
|
|
return classInheritanceMultiMap.iterator();
|
|
|
|
}
|
2021-06-16 21:57:52 +02:00
|
|
|
}
|