Skip to content

Commit

Permalink
Fix wrapped chat lines missing colors (#246)
Browse files Browse the repository at this point in the history
Fix wrapped chat lines missing colors
  • Loading branch information
Alexdoru authored Sep 17, 2023
1 parent 7fbd93a commit 2870646
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class LoadingConfig {
public boolean enlargePotionArray;
public boolean fixBibliocraftPackets;
public boolean fixBibliocraftPathSanitization;
public boolean fixChatWrappedColors;
public boolean fixComponentsPoppingOff;
public boolean fixContainerPutStacksInSlots;
public boolean fixDebugBoundingBox;
Expand Down Expand Up @@ -211,6 +212,7 @@ public LoadingConfig(File file) {

changeSprintCategory = config.get(Category.TWEAKS.toString(), "changeSprintCategory", true, "Moves the sprint keybind to the movement category").getBoolean();
fixContainerPutStacksInSlots = config.get(Category.FIXES.toString(), "fixContainerPutStacksInSlots", true, "Prevents crash if server sends container with wrong itemStack size").getBoolean();
fixChatWrappedColors = config.get(Category.FIXES.toString(), "fixChatWrappedColors", true, "Fix wrapped chat lines missing colors").getBoolean();
fixComponentsPoppingOff = config.get(Category.TWEAKS.toString(), "fixComponentsPoppingOff", true, "Fix Project Red components popping off on unloaded chunks").getBoolean();
fixDebugBoundingBox = config.get(Category.FIXES.toString(), "fixDebugBoundingBox", true, "Fixes the debug hitbox of the player beeing offset").getBoolean();
fixDimensionChangeHearts = config.get(Category.FIXES.toString(), "fixDimensionChangeHearts", true, "Fix losing bonus hearts on dimension change").getBoolean();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ public enum Mixins {
DISABLE_CREATIVE_TAB_ALL_SEARCH(new Builder("Disable the creative tab with search bar").setPhase(Phase.EARLY)
.addMixinClasses("minecraft.MixinGuiContainerCreative").setSide(Side.CLIENT)
.setApplyIf(() -> Common.config.removeCreativeSearchTab).addTargetedMod(TargetedMod.VANILLA)),
FIX_CHAT_COLOR_WRAPPING(new Builder("Fix wrapped chat lines missing colors").setPhase(Phase.EARLY)
.addMixinClasses("minecraft.MixinGuiNewChat_FixColorWrapping", "minecraft.FontRendererAccessor")
.setSide(Side.CLIENT).setApplyIf(() -> Common.config.fixChatWrappedColors)
.addTargetedMod(TargetedMod.VANILLA)),
COMPACT_CHAT(new Builder("Compact chat").setPhase(Phase.EARLY)
.addMixinClasses("minecraft.MixinGuiNewChat_CompactChat").setSide(Side.CLIENT)
.setApplyIf(() -> Common.config.compactChat).addTargetedMod(TargetedMod.VANILLA)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import net.minecraft.client.gui.FontRenderer;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(FontRenderer.class)
public interface FontRendererAccessor {

@Invoker("getFormatFromString")
static String callGetFormatFromString(String s) {
throw new IllegalStateException("Mixin stub invoked");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import net.minecraft.client.gui.GuiNewChat;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(GuiNewChat.class)
public class MixinGuiNewChat_FixColorWrapping {

@Unique
private String hodgepodge$s1;

@ModifyVariable(
method = "func_146237_a",
at = @At(
value = "NEW",
target = "(Ljava/lang/String;)Lnet/minecraft/util/ChatComponentText;",
ordinal = 2,
shift = At.Shift.BEFORE),
name = "s1")
private String hodgepodge$captureS1(String s1) {
this.hodgepodge$s1 = s1;
return s1;
}

@ModifyVariable(
method = "func_146237_a",
at = @At(
value = "NEW",
target = "(Ljava/lang/String;)Lnet/minecraft/util/ChatComponentText;",
ordinal = 2,
shift = At.Shift.BEFORE),
name = "s2")
private String hodgepodge$fixColorWrapping(String s2) {
return FontRendererAccessor.callGetFormatFromString(this.hodgepodge$s1) + s2;
}

}

0 comments on commit 2870646

Please sign in to comment.