|
| 1 | +package org.polyfrost.oneconfig.internal.mixin.events; |
| 2 | + |
| 3 | +import com.llamalad7.mixinextras.sugar.Local; |
| 4 | +import dev.deftu.omnicore.api.client.render.OmniRenderTicks; |
| 5 | +import dev.deftu.omnicore.api.client.render.OmniRenderingContext; |
| 6 | +import net.minecraft.client.DeltaTracker; |
| 7 | +import net.minecraft.client.gui.GuiGraphics; |
| 8 | +import net.minecraft.client.renderer.GameRenderer; |
| 9 | +import org.objectweb.asm.Opcodes; |
| 10 | +import org.polyfrost.oneconfig.api.event.v1.EventManager; |
| 11 | +import org.polyfrost.oneconfig.api.event.v1.events.RenderEvent; |
| 12 | +import org.spongepowered.asm.mixin.Mixin; |
| 13 | +import org.spongepowered.asm.mixin.Unique; |
| 14 | +import org.spongepowered.asm.mixin.injection.At; |
| 15 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 16 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 17 | + |
| 18 | +@Mixin(GameRenderer.class) |
| 19 | +public class Mixin_RenderEvent { |
| 20 | + @Unique private GuiGraphics oneconfig$lastGraphics; |
| 21 | + |
| 22 | + @Inject( |
| 23 | + method = "render", |
| 24 | + at = @At( |
| 25 | + value = "FIELD", |
| 26 | + target = "Lnet/minecraft/client/Minecraft;level:Lnet/minecraft/client/multiplayer/ClientLevel;", |
| 27 | + opcode = Opcodes.GETFIELD, |
| 28 | + ordinal = 3, |
| 29 | + shift = At.Shift.BEFORE |
| 30 | + ) |
| 31 | + ) |
| 32 | + private void renderTickStartCallback( |
| 33 | + DeltaTracker arg, |
| 34 | + boolean bl, |
| 35 | + CallbackInfo ci, |
| 36 | + @Local GuiGraphics guigraphics |
| 37 | + ) { |
| 38 | + this.oneconfig$lastGraphics = guigraphics; |
| 39 | + |
| 40 | + RenderEvent e = RenderEvent.Pre.INSTANCE; |
| 41 | + e.deltaTicks = OmniRenderTicks.get(); |
| 42 | + e.ctx = OmniRenderingContext.from(guigraphics); |
| 43 | + EventManager.INSTANCE.post(e); |
| 44 | + } |
| 45 | + |
| 46 | + @Inject( |
| 47 | + method = "render", |
| 48 | + at = @At( |
| 49 | + value = "INVOKE", |
| 50 | + target = "Lnet/minecraft/client/gui/render/GuiRenderer;render(Lcom/mojang/blaze3d/buffers/GpuBufferSlice;)V", |
| 51 | + shift = At.Shift.AFTER |
| 52 | + ) |
| 53 | + ) |
| 54 | + private void renderTickEndCallback( |
| 55 | + DeltaTracker arg, |
| 56 | + boolean bl, |
| 57 | + CallbackInfo ci |
| 58 | + ) { |
| 59 | + GuiGraphics guigraphics = this.oneconfig$lastGraphics; |
| 60 | + if (guigraphics == null) { |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + RenderEvent e = RenderEvent.Post.INSTANCE; |
| 65 | + e.deltaTicks = OmniRenderTicks.get(); |
| 66 | + e.ctx = OmniRenderingContext.from(guigraphics); |
| 67 | + EventManager.INSTANCE.post(e); |
| 68 | + |
| 69 | + this.oneconfig$lastGraphics = null; |
| 70 | + } |
| 71 | +} |
0 commit comments