Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 72c227a

Browse files
committed
Formatting Codes as Text Formatting
because idk,,...
1 parent 3e569c8 commit 72c227a

File tree

6 files changed

+60
-4
lines changed

6 files changed

+60
-4
lines changed

src/main/java/io/github/axolotlclient/AxolotlClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import net.minecraft.resource.Resource;
3131
import net.minecraft.resource.ResourcePack;
3232
import net.minecraft.scoreboard.Team;
33+
import net.minecraft.text.LiteralText;
34+
import net.minecraft.util.Formatting;
3335
import net.minecraft.util.Identifier;
3436
import org.apache.logging.log4j.LogManager;
3537
import org.apache.logging.log4j.Logger;
@@ -164,10 +166,11 @@ public static void addBadge(Entity entity, MatrixStack matrices){
164166
RenderSystem.color4f(1, 1, 1, 1);
165167

166168
if(AxolotlClient.CONFIG.customBadge.get()) {
169+
LiteralText badgeText = Util.formatFromCodes(AxolotlClient.CONFIG.badgeText.get());
167170
if(AxolotlClient.CONFIG.useShadows.get()) {
168-
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, AxolotlClient.CONFIG.badgeText.get(), x, 0, -1);
171+
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, badgeText, x, 0, -1);
169172
} else {
170-
MinecraftClient.getInstance().textRenderer.draw(matrices, AxolotlClient.CONFIG.badgeText.get(), x, 0, -1);
173+
MinecraftClient.getInstance().textRenderer.draw(matrices, badgeText, x, 0, -1);
171174
}
172175
}
173176
else DrawableHelper.drawTexture(matrices, x, 0, 0, 0, 8, 8, 8, 8);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.github.axolotlclient.mixin;
2+
3+
import io.github.axolotlclient.config.screen.OptionsScreenBuilder;
4+
import net.minecraft.SharedConstants;
5+
import net.minecraft.client.MinecraftClient;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
10+
11+
@Mixin(SharedConstants.class)
12+
public abstract class SharedConstantsMixin {
13+
14+
@Inject(method = "isValidChar", at = @At("HEAD"), cancellable = true)
15+
private static void noInvalidChars(char chr, CallbackInfoReturnable<Boolean> cir){
16+
if(chr=='§' && MinecraftClient.getInstance().currentScreen instanceof OptionsScreenBuilder){
17+
cir.setReturnValue(true);
18+
}
19+
}
20+
}

src/main/java/io/github/axolotlclient/modules/tnttime/TntTime.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void init() {
3232

3333
@Override
3434
public void tick() {
35-
if(decimalPlaces.get() != decimals){
35+
if(decimalPlaces.get() != decimals || format == null){
3636
StringBuilder string = new StringBuilder("#0");
3737
if (decimalPlaces.get() > 0) {
3838
string.append(".");

src/main/java/io/github/axolotlclient/util/Util.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
import net.minecraft.scoreboard.ScoreboardObjective;
2525
import net.minecraft.scoreboard.ScoreboardPlayerScore;
2626
import net.minecraft.scoreboard.Team;
27+
import net.minecraft.text.LiteralText;
2728
import net.minecraft.text.Text;
29+
import net.minecraft.util.Formatting;
2830
import net.minecraft.util.math.Vec3d;
2931
import org.lwjgl.opengl.GL11;
3032

3133
import java.net.InetAddress;
3234
import java.util.ArrayList;
35+
import java.util.Arrays;
3336
import java.util.Collection;
3437
import java.util.Collections;
3538
import java.util.List;
@@ -91,6 +94,33 @@ else if (MinecraftClient.getInstance().getCurrentServerEntry() != null && Minecr
9194
return game;
9295
}
9396

97+
public static LiteralText formatFromCodes(String formattedString){
98+
LiteralText text = new LiteralText("");
99+
String[] arr = formattedString.split("§");
100+
101+
List<Formatting> modifiers = new ArrayList<>();
102+
for (String s:arr){
103+
104+
Formatting formatting = Formatting.byCode(s.length()>0 ? s.charAt(0) : 0);
105+
if(formatting != null && formatting.isModifier()){
106+
modifiers.add(formatting);
107+
continue;
108+
}
109+
LiteralText part = new LiteralText(s.length()>0 ? s.substring(1):"");
110+
if(formatting != null){
111+
part.formatted(formatting);
112+
113+
if(!modifiers.isEmpty()){
114+
modifiers.forEach(part::formatted);
115+
modifiers.clear();
116+
}
117+
}
118+
text.append(part);
119+
}
120+
121+
return text;
122+
}
123+
94124
public static double calculateDistance(Vec3d pos1, Vec3d pos2){
95125
return calculateDistance(pos1.x, pos2.x, pos1.y, pos2.y, pos1.z, pos2.z);
96126
}

src/main/resources/assets/axolotlclient/lang/en_us.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@
219219
"green": "Green",
220220
"blue": "Blue",
221221

222+
"freelook": "Freelook",
223+
222224
"disableReason.crash.tooltip": "This option has been disabled <br>because it would crash your game.",
223225
"disableReason.ban_reason.tooltip": "This option is disabled <br>because it is known to be bannable on your current server.",
224226

src/main/resources/axolotlclient.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"MixinTitleScreen",
4747
"MixinTntEntityRenderer",
4848
"MixinWorldListWidgetEntry",
49-
"MixinWorldRenderer"
49+
"MixinWorldRenderer",
50+
"SharedConstantsMixin"
5051
],
5152
"server": [],
5253
"injectors": {

0 commit comments

Comments
 (0)