-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wrapped chat lines missing colors
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...va/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinGuiNewChat_FixColorWrapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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; | ||
|
||
import com.mitchej123.hodgepodge.util.StringUtil; | ||
|
||
@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 StringUtil.getFormatFromString(this.hodgepodge$s1) + s2; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/mitchej123/hodgepodge/util/StringUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.mitchej123.hodgepodge.util; | ||
|
||
// Methods stolen from FontRenderer | ||
public class StringUtil { | ||
|
||
/** | ||
* Checks if the char code is a hexadecimal character, used to set colour. | ||
*/ | ||
public static boolean isFormatColor(char colorChar) { | ||
return colorChar >= 48 && colorChar <= 57 || colorChar >= 97 && colorChar <= 102 | ||
|| colorChar >= 65 && colorChar <= 70; | ||
} | ||
|
||
/** | ||
* Checks if the char code is O-K...lLrRk-o... used to set special formatting. | ||
*/ | ||
public static boolean isFormatSpecial(char formatChar) { | ||
return formatChar >= 107 && formatChar <= 111 || formatChar >= 75 && formatChar <= 79 | ||
|| formatChar == 114 | ||
|| formatChar == 82; | ||
} | ||
|
||
/** | ||
* Digests a string for nonprinting formatting characters then returns a string containing only that formatting. | ||
*/ | ||
public static String getFormatFromString(String p_78282_0_) { | ||
String s1 = ""; | ||
int i = -1; | ||
int j = p_78282_0_.length(); | ||
while ((i = p_78282_0_.indexOf(167, i + 1)) != -1) { | ||
if (i < j - 1) { | ||
char c0 = p_78282_0_.charAt(i + 1); | ||
if (isFormatColor(c0)) { | ||
s1 = "\u00a7" + c0; | ||
} else if (isFormatSpecial(c0)) { | ||
s1 = s1 + "\u00a7" + c0; | ||
} | ||
} | ||
} | ||
return s1; | ||
} | ||
|
||
} |