package org.chrisoft.trashyaddon.mixin; import meteordevelopment.meteorclient.utils.render.color.Color; import meteordevelopment.meteorclient.utils.render.postprocess.PostProcessShaders; import net.minecraft.client.gl.Framebuffer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.WorldRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; import meteordevelopment.meteorclient.utils.render.postprocess.EntityShader; import org.chrisoft.trashyaddon.commands.EntityHighlightCommand; import org.chrisoft.trashyaddon.misc.AddonPostProcessingShaders; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = WorldRenderer.class, priority = 999) public abstract class WorldRendererMixin { @Shadow private Framebuffer entityOutlinesFramebuffer; @Shadow protected abstract void renderEntity(Entity entity, double cameraX, double cameraY, double cameraZ, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers); @Inject(method = "renderEntity", at = @At("HEAD")) private void renderEntity(Entity entity, double cameraX, double cameraY, double cameraZ, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, CallbackInfo info) { for (EntityShader es : AddonPostProcessingShaders.entityShaders) { drawShaded(entity, cameraX, cameraY, cameraZ, tickDelta, vertexConsumers, matrices, es, EntityHighlightCommand.getEntityColor(entity)); } } @Unique private void drawShaded(Entity entity, double cameraX, double cameraY, double cameraZ, float tickDelta, VertexConsumerProvider vertexConsumers, MatrixStack matrices, EntityShader shader, Color color) { if (shader.shouldDraw(entity) && !PostProcessShaders.isCustom(vertexConsumers) && color != null) { Framebuffer prevBuffer = this.entityOutlinesFramebuffer; this.entityOutlinesFramebuffer = shader.framebuffer; PostProcessShaders.rendering = true; shader.vertexConsumerProvider.setColor(color.r, color.g, color.b, color.a); renderEntity(entity, cameraX, cameraY, cameraZ, tickDelta, matrices, shader.vertexConsumerProvider); PostProcessShaders.rendering = false; this.entityOutlinesFramebuffer = prevBuffer; } } }