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;
|
2021-07-13 00:02:08 +02:00
|
|
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
|
2021-06-16 21:57:52 +02:00
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
import net.minecraft.client.renderer.LevelRenderer;
|
|
|
|
import net.minecraft.client.multiplayer.ClientLevel;
|
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
import net.minecraft.util.ClassInstanceMultiMap;
|
2021-06-16 21:57:52 +02:00
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
@Mixin(LevelRenderer.class)
|
2021-06-16 21:57:52 +02:00
|
|
|
public class CancelEntityRenderMixin {
|
|
|
|
|
2021-06-25 04:37:31 +02:00
|
|
|
@Group(name = "entityFilter", min = 1, max = 1)
|
2021-07-15 20:36:24 +02:00
|
|
|
@Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;entitiesForRendering()Ljava/lang/Iterable;"))
|
2021-09-15 08:45:29 +02:00
|
|
|
private Iterable<Entity> filterEntities(ClientLevel world) {
|
2021-07-15 20:36:24 +02:00
|
|
|
Iterable<Entity> entities = world.entitiesForRendering();
|
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-07-09 22:24:26 +02:00
|
|
|
|
|
|
|
InstancedRenderRegistry r = InstancedRenderRegistry.getInstance();
|
|
|
|
filtered.removeIf(r::shouldSkipRender);
|
2021-06-16 21:57:52 +02:00
|
|
|
|
|
|
|
return filtered;
|
|
|
|
}
|
|
|
|
return entities;
|
|
|
|
}
|
2021-06-25 04:37:31 +02:00
|
|
|
|
|
|
|
@Group(name = "entityFilter")
|
2021-07-15 20:36:24 +02:00
|
|
|
@Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ClassInheritanceMultiMap;iterator()Ljava/util/Iterator;"))
|
2021-09-15 08:45:29 +02:00
|
|
|
private Iterator<Entity> filterEntitiesOF(ClassInstanceMultiMap<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);
|
2021-07-09 22:24:26 +02:00
|
|
|
|
|
|
|
InstancedRenderRegistry r = InstancedRenderRegistry.getInstance();
|
|
|
|
filtered.removeIf(r::shouldSkipRender);
|
2021-06-25 04:37:31 +02:00
|
|
|
|
|
|
|
return filtered.iterator();
|
|
|
|
}
|
|
|
|
return classInheritanceMultiMap.iterator();
|
|
|
|
}
|
2021-06-16 21:57:52 +02:00
|
|
|
}
|