Skip to content

Commit 179d03e

Browse files
committed
make emojis fade with the text box
1 parent f915e46 commit 179d03e

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

common/src/main/java/com/lambda/mixin/render/TextRendererMixin.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.spongepowered.asm.mixin.Shadow;
3434
import org.spongepowered.asm.mixin.Unique;
3535

36+
import java.awt.*;
3637
import java.util.List;
3738

3839
@Mixin(TextRenderer.class)
@@ -61,9 +62,9 @@ public int draw(
6162
int light,
6263
boolean rightToLeft
6364
) {
64-
if (LambdaMoji.INSTANCE.isDisabled()) return this.drawInternal(text, x, y, color, shadow, matrix, vertexConsumers, layerType, backgroundColor, light, rightToLeft);
65+
String parsed = neoLambda$parseEmojisAndRender(text, x, y, color);
6566

66-
return this.drawInternal(neoLambda$parseEmojisAndRender(text, x, y), x, y, color, shadow, matrix, vertexConsumers, layerType, backgroundColor, light, rightToLeft);
67+
return this.drawInternal(parsed, x, y, color, shadow, matrix, vertexConsumers, layerType, backgroundColor, light, rightToLeft);
6768
}
6869

6970
/**
@@ -83,22 +84,21 @@ public int draw(
8384
int backgroundColor,
8485
int light
8586
) {
86-
if (LambdaMoji.INSTANCE.isDisabled()) return this.drawInternal(text, x, y, color, shadow, matrix, vertexConsumers, layerType, backgroundColor, light);
87-
8887
StringBuilder builder = new StringBuilder();
8988
text.accept((index, style, c) -> {
9089
builder.appendCodePoint(c);
9190
return true;
9291
});
9392

94-
return this.drawInternal(
95-
Text.literal(neoLambda$parseEmojisAndRender(builder.toString(), x, y)).asOrderedText(),
96-
x, y, color, shadow, matrix, vertexConsumers, layerType, backgroundColor, light
97-
);
93+
String parsed = neoLambda$parseEmojisAndRender(builder.toString(), x, y, color);
94+
95+
return this.drawInternal(Text.literal(parsed).asOrderedText(), x, y, color, shadow, matrix, vertexConsumers, layerType, backgroundColor, light);
9896
}
9997

10098
@Unique
101-
private String neoLambda$parseEmojisAndRender(String raw, float x, float y) {
99+
private String neoLambda$parseEmojisAndRender(String raw, float x, float y, int color) {
100+
if (LambdaMoji.INSTANCE.isDisabled()) return raw;
101+
102102
List<String> emojis = LambdaEmoji.Twemoji.parse(raw);
103103

104104
for (String emoji : emojis) {
@@ -111,7 +111,13 @@ public int draw(
111111
int height = Lambda.getMc().textRenderer.fontHeight;
112112
int width = Lambda.getMc().textRenderer.getWidth(raw.substring(0, index));
113113

114-
LambdaMoji.INSTANCE.push(constructed, new Vec2d(x + width, y + (float) height / 2));
114+
// Dude I'm sick of working with the shitcode that is minecraft's codebase :sob:
115+
Color trueColor = switch (color) {
116+
case 0x00E0E0E0, 0 -> new Color(255, 255, 255, 255);
117+
default -> new Color(255, 255, 255, (color >> 24 & 0xFF));
118+
};
119+
120+
LambdaMoji.INSTANCE.push(constructed, new Vec2d(x + width, y + (float) height / 2), trueColor);
115121

116122
// Replace the emoji with whitespaces depending on the player's settings
117123
raw = raw.replaceFirst(constructed, neoLambda$getReplacement());

common/src/main/kotlin/com/lambda/graphics/texture/Texture.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ open class Texture(
6868
val height = image.height
6969

7070
// Set this mipmap to `offset` to define the original texture
71+
setupTexture(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR)
7172
glTexImage2D(GL_TEXTURE_2D, offset, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, readImage(image))
7273
glGenerateMipmap(GL_TEXTURE_2D) // This take the derived values GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL to generate the stack
73-
74-
setupTexture(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR)
7574
}
7675

7776
open fun update(image: BufferedImage, offset: Int = 0) {

common/src/main/kotlin/com/lambda/module/modules/client/LambdaMoji.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.lambda.gui.api.RenderLayer
2323
import com.lambda.module.Module
2424
import com.lambda.module.tag.ModuleTag
2525
import com.lambda.util.math.Vec2d
26+
import java.awt.Color
2627

2728
object LambdaMoji : Module(
2829
name = "LambdaMoji",
@@ -34,18 +35,18 @@ object LambdaMoji : Module(
3435
val suggestions by setting("Chat Suggestions", true)
3536

3637
private val renderer = RenderLayer()
37-
private val renderQueue = mutableListOf<Pair<String, Vec2d>>()
38+
private val renderQueue = mutableListOf<Triple<String, Vec2d, Color>>()
3839

3940
init {
4041
listen<RenderEvent.GUI.Scaled> {
41-
renderQueue.forEach { (text, position) ->
42-
renderer.font.build(text, position, scale = scale)
42+
renderQueue.forEach { (text, position, color) ->
43+
renderer.font.build(text, position, color, scale = scale)
4344
}
4445

4546
renderer.render()
4647
renderQueue.clear()
4748
}
4849
}
4950

50-
fun push(text: String, position: Vec2d) = renderQueue.add(Pair(text, position))
51+
fun push(text: String, position: Vec2d, color: Color) = renderQueue.add(Triple(text, position, color))
5152
}

0 commit comments

Comments
 (0)