Skip to content

Commit

Permalink
Merge pull request #93 from KJNine/1.19.4
Browse files Browse the repository at this point in the history
Fix crash when opening KeyBinds menu (#90 #91)
  • Loading branch information
Andrew6rant authored May 28, 2023
2 parents 46155ed + 663175e commit 2de5f9f
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.kqp.inventorytabs.mixin;

import java.util.Objects;

import com.kqp.inventorytabs.init.InventoryTabsClient;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.MutableText;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -11,9 +11,8 @@

import net.minecraft.client.gui.screen.option.ControlsListWidget;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;
import org.spongepowered.asm.mixin.injection.Redirect;

/**
* The 'Tab' keybinding conflicts with the multiplayer player list keybind, but since you can only see the player list when outside the inventory
Expand All @@ -23,14 +22,19 @@
public class ControlsListWidget$KeyBindingEntryMixin_SoftConflict {
@Shadow @Final private KeyBinding binding;

@ModifyArg(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/ButtonWidget;setMessage(Lnet/minecraft/text/Text;)V"))
public Text setMessage(Text text) {
TextColor c = text.getStyle().getColor();
if(c != null && c.getRgb() == Objects.requireNonNull(Formatting.RED.getColorValue())) {
if(this.binding == InventoryTabsClient.NEXT_TAB_KEY_BIND) {
text = text.copy().formatted(Formatting.GOLD);
}
@ModifyArg(method = "render", index = 5, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawableHelper;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V"))
public int fill(MatrixStack matrices, int x1, int y1, int x2, int y2, int color) {
if(this.binding == InventoryTabsClient.NEXT_TAB_KEY_BIND) {
return Formatting.GOLD.getColorValue() | 0xFF000000;
}
return color;
}

@Redirect(method="update", at=@At(value="INVOKE", target="Lnet/minecraft/text/MutableText;formatted(Lnet/minecraft/util/Formatting;)Lnet/minecraft/text/MutableText;"))
public MutableText formatText(MutableText instance, Formatting formatting) {
if(formatting == Formatting.RED && this.binding == InventoryTabsClient.NEXT_TAB_KEY_BIND) {
return instance.formatted(Formatting.GOLD);
}
return text;
return instance.formatted(formatting);
}
}

0 comments on commit 2de5f9f

Please sign in to comment.