Skip to content

Commit

Permalink
Fixed screen buffering slot highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Nov 6, 2023
1 parent ff720fe commit 29cdd19
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package net.raphimc.immediatelyfast.injection.mixins.hud_batching.consumer;

import com.mojang.blaze3d.systems.RenderSystem;
import net.lenni0451.reflect.Objects;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.ColorHelper;
Expand All @@ -27,13 +29,18 @@
import net.raphimc.immediatelyfast.feature.batching.BlendFuncDepthFunc;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = DrawableHelper.class, priority = 500)
public abstract class MixinDrawableHelper {

@Shadow
protected static void fillGradient(Matrix4f matrix, BufferBuilder builder, int startX, int startY, int endX, int endY, int colorStart, int colorEnd, int z) {
}

@Inject(method = "fill(Lnet/minecraft/client/util/math/MatrixStack;IIIIII)V", at = @At("HEAD"), cancellable = true)
private static void fillIntoBuffer(MatrixStack matrices, int x1, int y1, int x2, int y2, int z, int color, CallbackInfo ci) {
if (BatchingBuffers.FILL_CONSUMER != null) {
Expand Down Expand Up @@ -64,6 +71,21 @@ private static void fillIntoBuffer(MatrixStack matrices, int x1, int y1, int x2,
}
}

@Inject(method = "fillGradient(Lnet/minecraft/client/util/math/MatrixStack;IIIIIII)V", at = @At("HEAD"), cancellable = true)
private static void fillIntoBuffer(MatrixStack matrices, int startX, int startY, int endX, int endY, int colorStart, int colorEnd, int z, CallbackInfo ci) {
if (BatchingBuffers.FILL_CONSUMER != null) {
ci.cancel();
final float[] shaderColor = RenderSystem.getShaderColor();
final int argb = (int) (shaderColor[3] * 255) << 24 | (int) (shaderColor[0] * 255) << 16 | (int) (shaderColor[1] * 255) << 8 | (int) (shaderColor[2] * 255);
colorStart = ColorHelper.Argb.mixColor(colorStart, argb);
colorEnd = ColorHelper.Argb.mixColor(colorEnd, argb);
RenderSystem.enableBlend();
final VertexConsumer vertexConsumer = BatchingBuffers.FILL_CONSUMER.getBuffer(BatchingRenderLayers.FILLED_QUAD.apply(BlendFuncDepthFunc.current()));
fillGradient(matrices.peek().getPositionMatrix(), Objects.cast(vertexConsumer, BufferBuilder.class), startX, startY, endX, endY, z, colorStart, colorEnd);
RenderSystem.disableBlend();
}
}

@Inject(method = "drawTexturedQuad(Lorg/joml/Matrix4f;IIIIIFFFF)V", at = @At("HEAD"), cancellable = true)
private static void drawTexturedQuadIntoBuffer(Matrix4f matrix, int x0, int x1, int y0, int y1, int z, float u0, float u1, float v0, float v1, CallbackInfo ci) {
if (BatchingBuffers.TEXTURE_CONSUMER != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,34 @@
package net.raphimc.immediatelyfast.injection.mixins.screen_batching;

import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.raphimc.immediatelyfast.feature.batching.BatchingBuffers;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = HandledScreen.class, priority = 500)
public abstract class MixinHandledScreen {

@Shadow
public static void drawSlotHighlight(MatrixStack matrices, int x, int y, int z) {
}

@Inject(method = "render", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;focusedSlot:Lnet/minecraft/screen/slot/Slot;", ordinal = 0))
private void beginBatching(CallbackInfo ci) {
BatchingBuffers.beginHudBatching();
}

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawSlotHighlight(Lnet/minecraft/client/util/math/MatrixStack;III)V"))
private void drawSlotHightlightOnTop(MatrixStack matrices, int x, int y, int z) {
BatchingBuffers.beginItemOverlayRendering();
drawSlotHighlight(matrices, x, y, z);
BatchingBuffers.endItemOverlayRendering();
}

@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawForeground(Lnet/minecraft/client/util/math/MatrixStack;II)V", shift = At.Shift.BEFORE))
private void endBatching(CallbackInfo ci) {
BatchingBuffers.endHudBatching();
Expand Down

0 comments on commit 29cdd19

Please sign in to comment.