generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scale emote height based on chat line spacing
- Loading branch information
Showing
6 changed files
with
60 additions
and
20 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
18 changes: 0 additions & 18 deletions
18
src/client/java/net/vinrobot/mcemote/client/mixin/MinecraftEmoteClientMixin.java
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
src/client/java/net/vinrobot/mcemote/client/mixin/TextRendererDrawerMixin.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,54 @@ | ||
package net.vinrobot.mcemote.client.mixin; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.font.FontStorage; | ||
import net.minecraft.client.font.Glyph; | ||
import net.minecraft.client.font.GlyphRenderer; | ||
import net.minecraft.client.font.TextRenderer; | ||
import net.minecraft.client.option.GameOptions; | ||
import net.minecraft.client.render.VertexConsumer; | ||
import net.vinrobot.mcemote.client.font.NativeImageGlyph; | ||
import org.joml.Matrix4f; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import static net.vinrobot.mcemote.client.font.CustomFontStorage.GLYPH_HEIGHT; | ||
|
||
@Mixin(TextRenderer.Drawer.class) | ||
public abstract class TextRendererDrawerMixin { | ||
@Accessor("x") | ||
abstract void setX(float x); | ||
|
||
@Unique | ||
private volatile Glyph localGlyph = null; // Used to catch the local variable in TextRenderer.Drawer#accept() | ||
|
||
@Redirect(method = "accept", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/FontStorage;getGlyph(IZ)Lnet/minecraft/client/font/Glyph;")) | ||
private Glyph acceptGetGlyph(final FontStorage instance, final int codePoint, final boolean validateAdvance) { | ||
return this.localGlyph = instance.getGlyph(codePoint, validateAdvance); | ||
} | ||
|
||
@Redirect(method = "accept", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;drawGlyph(Lnet/minecraft/client/font/GlyphRenderer;ZZFFFLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumer;FFFFI)V")) | ||
private void acceptDrawGlyph(final TextRenderer instance, final GlyphRenderer glyphRenderer, final boolean bold, final boolean italic, final float weight, final float x, final float y, final Matrix4f matrix, final VertexConsumer vertexConsumer, final float red, final float green, final float blue, final float alpha, final int light) { | ||
if (this.localGlyph instanceof NativeImageGlyph glyph) { | ||
final GameOptions options = MinecraftClient.getInstance().options; | ||
final float lineSpacing = options.getChatLineSpacing().getValue().floatValue(); | ||
final float scale = (lineSpacing + 1); | ||
|
||
final float newX = x / scale; | ||
// Align the glyph to the top of the line | ||
final float newY = (y - (lineSpacing * GLYPH_HEIGHT) / 2) / scale; | ||
|
||
matrix.scale(scale); | ||
instance.drawGlyph(glyphRenderer, bold, italic, weight, newX, newY, matrix, vertexConsumer, red, green, blue, alpha, light); | ||
matrix.scale(1 / scale); | ||
|
||
// Fix the spacing between glyphs | ||
this.setX(x + glyph.getAdvance(bold) * lineSpacing); | ||
} else { | ||
instance.drawGlyph(glyphRenderer, bold, italic, weight, x, y, matrix, vertexConsumer, red, green, blue, alpha, light); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
accessWidener v1 named | ||
|
||
accessible class net/minecraft/client/font/FontManager$ProviderIndex | ||
accessible class net/minecraft/client/font/TextRenderer$Drawer | ||
|
||
accessible method net/minecraft/client/font/FontStorage getGlyphRenderer (Lnet/minecraft/client/font/RenderableGlyph;)Lnet/minecraft/client/font/GlyphRenderer; | ||
accessible method net/minecraft/client/font/TextRenderer drawGlyph (Lnet/minecraft/client/font/GlyphRenderer;ZZFFFLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumer;FFFFI)V |