Quick thinking

- Decide not to render entities directly in the renderEntity method
- Prevents allocating large lists every frame to filter entities from
  the client level
This commit is contained in:
Jozufozu 2024-09-28 23:37:49 -07:00
parent 0a01b82647
commit 22b5676e47
3 changed files with 10 additions and 33 deletions

View file

@ -1,32 +0,0 @@
package dev.engine_room.flywheel.impl.mixin;
import java.util.ArrayList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.google.common.collect.Lists;
import dev.engine_room.flywheel.api.visualization.VisualizationManager;
import dev.engine_room.flywheel.lib.visualization.VisualizationHelper;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.entity.Entity;
@Mixin(ClientLevel.class)
abstract class ClientLevelMixin {
@Inject(method = "entitiesForRendering()Ljava/lang/Iterable;", at = @At("RETURN"), cancellable = true)
private void flywheel$filterEntities(CallbackInfoReturnable<Iterable<Entity>> cir) {
if (!VisualizationManager.supportsVisualization((ClientLevel) (Object) this)) {
return;
}
Iterable<Entity> entities = cir.getReturnValue();
ArrayList<Entity> filtered = Lists.newArrayList(entities);
filtered.removeIf(VisualizationHelper::skipVanillaRender);
cir.setReturnValue(filtered);
}
}

View file

@ -19,14 +19,17 @@ import com.mojang.blaze3d.vertex.PoseStack;
import dev.engine_room.flywheel.api.visualization.VisualizationManager;
import dev.engine_room.flywheel.impl.FlwImplXplat;
import dev.engine_room.flywheel.impl.event.RenderContextImpl;
import dev.engine_room.flywheel.lib.visualization.VisualizationHelper;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderBuffers;
import net.minecraft.server.level.BlockDestructionProgress;
import net.minecraft.world.entity.Entity;
@Mixin(value = LevelRenderer.class, priority = 1001) // Higher priority to go after Sodium
abstract class LevelRendererMixin {
@ -120,4 +123,11 @@ abstract class LevelRendererMixin {
}
}
}
@Inject(method = "renderEntity", at = @At("HEAD"), cancellable = true)
private void flywheel$decideNotToRenderEntity(Entity pEntity, double pCamX, double pCamY, double pCamZ, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBufferSource, CallbackInfo ci) {
if (VisualizationManager.supportsVisualization(pEntity.level()) && VisualizationHelper.skipVanillaRender(pEntity)) {
ci.cancel();
}
}
}

View file

@ -7,7 +7,6 @@
"client": [
"BlockEntityTypeMixin",
"ClientChunkCacheMixin",
"ClientLevelMixin",
"EntityTypeMixin",
"LevelMixin",
"LevelRendererMixin",