Skip to content

Commit 324047b

Browse files
committed
(1.8.9) fix edge-case issue with text formatting
1 parent 8538c5c commit 324047b

File tree

13 files changed

+141
-80
lines changed

13 files changed

+141
-80
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/AxolotlClient.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,21 @@ public void onInitializeClient() {
175175
configManager.suppressName("y");
176176
configManager.suppressName(config.getName());
177177

178-
ConfigUI.getInstance().runWhenLoaded(() -> {
179-
modules.forEach(Module::lateInit);
180-
181-
ClientTickEvents.END_CLIENT_TICK.register(client -> modules.forEach(Module::tick));
182-
183-
FeatureDisabler.init();
184-
});
178+
ConfigUI.getInstance().runWhenLoaded(this::postConfigLoad);
185179

186180
LOGGER.debug("Debug Output activated, Logs will be more verbose!");
187181

188182
LOGGER.info("AxolotlClient Initialized");
189183
}
184+
185+
private boolean configLoaded;
186+
private void postConfigLoad() {
187+
if (configLoaded) return;
188+
configLoaded = true;
189+
modules.forEach(Module::lateInit);
190+
191+
ClientTickEvents.END_CLIENT_TICK.register(client -> modules.forEach(Module::tick));
192+
193+
FeatureDisabler.init();
194+
}
190195
}

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/PotionsHud.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,19 @@ public PotionsHud() {
7878
@Override
7979
public void renderComponent(MatrixStack matrices, float delta) {
8080
List<StatusEffectInstance> effects = new ArrayList<>(client.player.getStatusEffects());
81-
if (effects.isEmpty()) {
82-
return;
83-
}
8481
renderEffects(matrices, effects);
8582
}
8683

8784
private void renderEffects(MatrixStack matrices, List<StatusEffectInstance> effects) {
88-
int calcWidth = calculateWidth(effects);
89-
int calcHeight = calculateHeight(effects);
85+
int calcWidth;
86+
int calcHeight;
87+
if (effects.isEmpty()) {
88+
calcWidth = 0;
89+
calcHeight = 0;
90+
} else {
91+
calcWidth = calculateWidth(effects);
92+
calcHeight = calculateHeight(effects);
93+
}
9094
boolean changed = false;
9195
if (calcWidth != width) {
9296
setWidth(calcWidth);

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,22 @@ public void onInitializeClient() {
178178
configManager.suppressName("y");
179179
configManager.suppressName(config.getName());
180180

181-
ConfigUI.getInstance().runWhenLoaded(() -> {
182-
modules.forEach(Module::lateInit);
183-
184-
ClientTickEvents.END_CLIENT_TICK.register(client -> modules.forEach(Module::tick));
185-
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(SkyResourceManager.getInstance());
186-
187-
FeatureDisabler.init();
188-
});
181+
ConfigUI.getInstance().runWhenLoaded(this::postConfigLoad);
189182

190183
LOGGER.debug("Debug Output activated, Logs will be more verbose!");
191184

192185
LOGGER.info("AxolotlClient Initialized");
193186
}
187+
188+
private boolean configLoaded;
189+
private void postConfigLoad() {
190+
if (configLoaded) return;
191+
configLoaded = true;
192+
modules.forEach(Module::lateInit);
193+
194+
ClientTickEvents.END_CLIENT_TICK.register(client -> modules.forEach(Module::tick));
195+
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(SkyResourceManager.getInstance());
196+
197+
FeatureDisabler.init();
198+
}
194199
}

1.20/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/PotionsHud.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,19 @@ public PotionsHud() {
7575
@Override
7676
public void renderComponent(GuiGraphics graphics, float delta) {
7777
List<StatusEffectInstance> effects = new ArrayList<>(client.player.getStatusEffects());
78-
if (effects.isEmpty()) {
79-
return;
80-
}
8178
renderEffects(graphics, effects, delta);
8279
}
8380

8481
private void renderEffects(GuiGraphics graphics, List<StatusEffectInstance> effects, float tickDelta) {
85-
int calcWidth = calculateWidth(effects);
86-
int calcHeight = calculateHeight(effects);
82+
int calcWidth;
83+
int calcHeight;
84+
if (effects.isEmpty()) {
85+
calcWidth = 0;
86+
calcHeight = 0;
87+
} else {
88+
calcWidth = calculateWidth(effects);
89+
calcHeight = calculateHeight(effects);
90+
}
8791
boolean changed = false;
8892
if (calcWidth != width) {
8993
setWidth(calcWidth);

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,21 @@ public void onInitializeClient() {
175175
configManager.suppressName("y");
176176
configManager.suppressName(config.getName());
177177

178-
ConfigUI.getInstance().runWhenLoaded(() -> {
179-
modules.forEach(Module::lateInit);
180-
181-
ClientTickEvents.END_CLIENT_TICK.register(client -> modules.forEach(Module::tick));
182-
183-
FeatureDisabler.init();
184-
});
178+
ConfigUI.getInstance().runWhenLoaded(this::postConfigLoad);
185179

186180
LOGGER.debug("Debug Output activated, Logs will be more verbose!");
187181

188182
LOGGER.info("AxolotlClient Initialized");
189183
}
184+
185+
private boolean configLoaded;
186+
private void postConfigLoad() {
187+
if (configLoaded) return;
188+
configLoaded = true;
189+
modules.forEach(Module::lateInit);
190+
191+
ClientTickEvents.END_CLIENT_TICK.register(client -> modules.forEach(Module::tick));
192+
193+
FeatureDisabler.init();
194+
}
190195
}

1.21.7/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/PotionsHud.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,23 @@ public PotionsHud() {
7676
@Override
7777
public void renderComponent(GuiGraphics graphics, float delta) {
7878
List<MobEffectInstance> effects = new ArrayList<>(client.player.getActiveEffects());
79-
if (effects.isEmpty()) {
79+
/*if (effects.isEmpty()) {
8080
return;
81-
}
81+
}*/
8282
renderEffects(graphics, effects, delta);
8383
}
8484

8585
private void renderEffects(GuiGraphics graphics, List<MobEffectInstance> effects, float tickDelta) {
8686
float tickrate = client.level != null ? client.level.tickRateManager().tickrate() : 1;
87-
int calcWidth = calculateWidth(effects, tickrate);
88-
int calcHeight = calculateHeight(effects);
87+
int calcWidth;
88+
int calcHeight;
89+
if (effects.isEmpty()) {
90+
calcWidth = 0;
91+
calcHeight = 0;
92+
} else {
93+
calcWidth = calculateWidth(effects, tickrate);
94+
calcHeight = calculateHeight(effects);
95+
}
8996
boolean changed = false;
9097
if (calcWidth != width) {
9198
setWidth(calcWidth);

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,21 @@ public void onInitializeClient() {
173173
configManager.suppressName("y");
174174
configManager.suppressName(config.getName());
175175

176-
ConfigUI.getInstance().runWhenLoaded(() -> {
177-
modules.forEach(Module::lateInit);
178-
179-
ClientTickEvents.END_CLIENT_TICK.register(client -> modules.forEach(Module::tick));
180-
181-
FeatureDisabler.init();
182-
});
176+
ConfigUI.getInstance().runWhenLoaded(this::postConfigLoad);
183177

184178
LOGGER.debug("Debug Output activated, Logs will be more verbose!");
185179

186180
LOGGER.info("AxolotlClient Initialized");
187181
}
182+
183+
private boolean configLoaded;
184+
private void postConfigLoad() {
185+
if (configLoaded) return;
186+
configLoaded = true;
187+
modules.forEach(Module::lateInit);
188+
189+
ClientTickEvents.END_CLIENT_TICK.register(client -> modules.forEach(Module::tick));
190+
191+
FeatureDisabler.init();
192+
}
188193
}

1.21/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/PotionsHud.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,20 @@ public PotionsHud() {
7676
@Override
7777
public void renderComponent(GuiGraphics graphics, float delta) {
7878
List<StatusEffectInstance> effects = new ArrayList<>(client.player.getStatusEffects());
79-
if (effects.isEmpty()) {
80-
return;
81-
}
8279
renderEffects(graphics, effects, delta);
8380
}
8481

8582
private void renderEffects(GuiGraphics graphics, List<StatusEffectInstance> effects, float tickDelta) {
8683
float tickrate = client.world != null ? client.world.getTickManager().getTickRate() : 1;
87-
int calcWidth = calculateWidth(effects, tickrate);
88-
int calcHeight = calculateHeight(effects);
84+
int calcWidth;
85+
int calcHeight;
86+
if (effects.isEmpty()) {
87+
calcWidth = 0;
88+
calcHeight = 0;
89+
} else {
90+
calcWidth = calculateWidth(effects, tickrate);
91+
calcHeight = calculateHeight(effects);
92+
}
8993
boolean changed = false;
9094
if (calcWidth != width) {
9195
setWidth(calcWidth);

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,21 @@ public void onInitializeClient() {
175175
configManager.suppressName("y");
176176
configManager.suppressName(config.getName());
177177

178-
ConfigUI.getInstance().runWhenLoaded(() -> {
179-
modules.forEach(Module::lateInit);
180-
181-
MinecraftClientEvents.TICK_END.register(client -> modules.forEach(Module::tick));
182-
183-
FeatureDisabler.init();
184-
});
178+
ConfigUI.getInstance().runWhenLoaded(this::postConfigLoad);
185179

186180
LOGGER.debug("Debug Output enabled, Logs will be quite verbose!");
187181

188182
LOGGER.info("AxolotlClient Initialized");
189183
}
184+
185+
private boolean configLoaded;
186+
private void postConfigLoad() {
187+
if (configLoaded) return;
188+
configLoaded = true;
189+
modules.forEach(Module::lateInit);
190+
191+
MinecraftClientEvents.TICK_END.register(client -> modules.forEach(Module::tick));
192+
193+
FeatureDisabler.init();
194+
}
190195
}

1.8.9/src/main/java/io/github/axolotlclient/mixin/TextRenderUtilsMixin.java

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ private static Text formatFromCodes(String formattedString) {
114114
String[] arr = CODE_PATTERN.split(formattedString);
115115

116116
List<Formatting> modifiers = new ArrayList<>();
117+
Formatting color = null;
117118
for (int i = 0, length = arr.length; i < length; i++) {
118119
String s = arr[i];
119120
if (s.isEmpty()) {
@@ -123,27 +124,39 @@ private static Text formatFromCodes(String formattedString) {
123124
continue;
124125
}
125126
Formatting formatting = byCodeOfFirstChar(s);
127+
if (formatting == null) {
128+
text.append(s);
129+
continue;
130+
}
126131

127-
if (formatting != null && formatting.isModifier()) {
132+
Text part;
133+
int pL = s.length();
134+
if (formatting.equals(Formatting.RESET)) {
135+
modifiers.clear();
136+
color = null;
137+
} else if (formatting.isModifier()) {
128138
modifiers.add(formatting);
139+
} else {
140+
color = formatting;
129141
}
130-
Text part = new LiteralText(formatting != null ? s.substring(1) : s);
131-
if (formatting != null) {
132-
part.getStyle().setColor(formatting);
133-
134-
if (!modifiers.isEmpty()) {
135-
for (Formatting mod : modifiers) {
136-
switch (mod) {
137-
case OBFUSCATED -> part.getStyle().setObfuscated(true);
138-
case BOLD -> part.getStyle().setBold(true);
139-
case ITALIC -> part.getStyle().setItalic(true);
140-
case UNDERLINE -> part.getStyle().setUnderlined(true);
141-
case STRIKETHROUGH -> part.getStyle().setStrikethrough(true);
142-
default -> AxolotlClient.LOGGER.warn("Unexpected modifier: " + mod);
143-
}
144-
}
145-
if (formatting.equals(Formatting.RESET)) {
146-
modifiers.clear();
142+
if (pL == 1) {
143+
continue;
144+
}
145+
part = new LiteralText(s.substring(1));
146+
147+
if (color != null) {
148+
part.getStyle().setColor(color);
149+
}
150+
151+
if (!modifiers.isEmpty()) {
152+
for (Formatting mod : modifiers) {
153+
switch (mod) {
154+
case OBFUSCATED -> part.getStyle().setObfuscated(true);
155+
case BOLD -> part.getStyle().setBold(true);
156+
case ITALIC -> part.getStyle().setItalic(true);
157+
case UNDERLINE -> part.getStyle().setUnderlined(true);
158+
case STRIKETHROUGH -> part.getStyle().setStrikethrough(true);
159+
default -> AxolotlClient.LOGGER.warn("Unexpected modifier: " + mod);
147160
}
148161
}
149162
}

0 commit comments

Comments
 (0)