Skip to content

Commit

Permalink
Fixed character size calculation with OptiFine
Browse files Browse the repository at this point in the history
Co-authored-by: Juan Patricio <juanmuscaria@gmail.com>
  • Loading branch information
brunoxkk0 and juanmuscaria committed Aug 25, 2023
1 parent e6b5cf4 commit 82d3f5a
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Group;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand All @@ -33,11 +34,21 @@ public class FontRenderer2Mixin {
@Shadow
private float alpha;

@Inject(method = "Lnet/minecraft/client/gui/FontRenderer;getCharWidth(C)I", at = @At("HEAD"), cancellable = true)
@Group(name = "necrotempus_fontRenderer_chatWidth", min = 1)
@Inject(method = "Lnet/minecraft/client/gui/FontRenderer;getCharWidth(C)I", at = @At("HEAD"), cancellable = true, expect = 0)
public void getCharWidth(char character, CallbackInfoReturnable<Integer> cir) {
CustomGlyphs customGlyphs = GlyphsRegistry.getCandidate(character);
if (customGlyphs != null) {
cir.setReturnValue(customGlyphs.getFinalCharacterWidth());
cir.setReturnValue(customGlyphs.getFinalCharacterWidth());
}
}

@Group(name = "necrotempus_fontRenderer_chatWidth", min = 1)
@Inject(method = "Lnet/minecraft/client/gui/FontRenderer;getCharWidthFloat(C)F", at = @At("HEAD"), cancellable = true, remap = false, expect = 0)
public void getCharWidthFloat(char character, CallbackInfoReturnable<Float> cir) {
CustomGlyphs customGlyphs = GlyphsRegistry.getCandidate(character);
if (customGlyphs != null) {
cir.setReturnValue((float) customGlyphs.getFinalCharacterWidth());
}
}

Expand Down

0 comments on commit 82d3f5a

Please sign in to comment.