Skip to content

Commit 8d11e29

Browse files
committed
🐛 Fix emote processing and adjust custom image scale factor
1 parent f5f60dd commit 8d11e29

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/main/java/dev/renoux/emotes/mixins/TranslatableContentsMixin.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package dev.renoux.emotes.mixins;
2525

26+
import dev.renoux.emotes.utils.EmoteProcessor;
2627
import dev.renoux.emotes.utils.EmoteUtil;
2728
import net.fabricmc.api.EnvType;
2829
import net.fabricmc.loader.api.FabricLoader;
@@ -39,9 +40,6 @@
3940

4041
import java.util.Optional;
4142

42-
import static dev.renoux.emotes.Emotes.LOGGER;
43-
import static dev.renoux.emotes.Emotes.metadata;
44-
4543
@Mixin(TranslatableContents.class)
4644
public abstract class TranslatableContentsMixin {
4745
@Shadow public abstract String getKey();
@@ -56,9 +54,9 @@ private String getOrDefault(Language instance, String key, String fallback) {
5654

5755
@Redirect(method = "visit(Lnet/minecraft/network/chat/FormattedText$StyledContentConsumer;Lnet/minecraft/network/chat/Style;)Ljava/util/Optional;", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/chat/FormattedText;visit(Lnet/minecraft/network/chat/FormattedText$StyledContentConsumer;Lnet/minecraft/network/chat/Style;)Ljava/util/Optional;"))
5856
private <T> Optional<T> visit(FormattedText instance, FormattedText.StyledContentConsumer<T> tStyledContentConsumer, Style style) {
59-
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
60-
if (this.getKey().startsWith("emotes.")) {
61-
String[] splitEmote = instance.getString().split(":");
57+
if (this.getKey().startsWith("emotes.")) {
58+
String[] splitEmote = instance.getString().split(":");
59+
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
6260
Integer codepoint = EmoteUtil.getInstance().getCodepoint(splitEmote[0].replace("emotes.", ""));
6361
if (codepoint == null) {
6462
// Fix from @Juloos
@@ -67,6 +65,8 @@ private <T> Optional<T> visit(FormattedText instance, FormattedText.StyledConten
6765
String emote = Character.toString(codepoint);
6866
FormattedText newInstance = FormattedText.of(emote);
6967
return newInstance.visit(tStyledContentConsumer, style.withFont(EmoteUtil.CUSTOM_IMAGE_FONT_IDENTIFIER).withHoverEvent(new HoverEvent.ShowText(Component.literal(splitEmote[1]))));
68+
} else {
69+
return FormattedText.of(splitEmote[splitEmote.length - 1]).visit(tStyledContentConsumer, style);
7070
}
7171
}
7272
return instance.visit(tStyledContentConsumer, style);

src/main/java/dev/renoux/emotes/utils/CustomImageFont.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public float getAdvance() {
7070
return this.advance;
7171
}
7272

73+
@Override
74+
public float getShadowOffset() {
75+
return 0.0f;
76+
}
77+
7378
@Override
7479
public @NotNull BakedGlyph bake(Function<SheetGlyphInfo, BakedGlyph> function) {
7580
return function.apply(new CustomImageRenderableGlyph() {

src/main/java/dev/renoux/emotes/utils/EmoteProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434

3535
public class EmoteProcessor {
3636

37-
private static Map<String, String> EMOTES = new HashMap<>();
37+
public static Map<String, String> EMOTES = new HashMap<>();
3838

3939
public static void init() {
4040
EMOTES = new HashMap<>();
4141
ValueList<String> emotes = Emotes.serverConfig.emotes.getRealValue();
4242
for (String emote : emotes) {
4343
String[] splitedEmote = emote.split(":");
44-
if (splitedEmote[0] == "nul_") {
44+
if (splitedEmote[0].equals("nul_")) {
4545
EMOTES.put("nul", splitedEmote[1]);
4646
} else {
4747
EMOTES.put(splitedEmote[0], splitedEmote[1]);

src/main/java/dev/renoux/emotes/utils/EmoteUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class EmoteUtil {
3939
public static final ResourceLocation CUSTOM_IMAGE_FONT_IDENTIFIER = ResourceLocation.fromNamespaceAndPath(metadata.getId(), "emote_font");
4040

4141
// I've found this is a pretty good scale factor for 24x24px Twitch emotes.
42-
public static final float CUSTOM_IMAGE_SCALE_FACTOR = 0.08f;
42+
public static final float CUSTOM_IMAGE_SCALE_FACTOR = 0.07f;
4343

4444
private final CustomImageFont customImageFont;
4545
private final CustomImageFontStorage customImageFontStorage;

0 commit comments

Comments
 (0)