Skip to content

Commit

Permalink
underlined links
Browse files Browse the repository at this point in the history
  • Loading branch information
RedthMC committed Jun 24, 2024
1 parent 7019229 commit 7cc80b2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/java/org/polyfrost/chatting/mixin/ChatStyleMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.polyfrost.chatting.mixin;

import net.minecraft.event.ClickEvent;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import org.polyfrost.chatting.config.ChattingConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ChatStyle.class)
public class ChatStyleMixin {
@Shadow
private ClickEvent chatClickEvent;

@Unique
private boolean chatting$hasURL() {
return ChattingConfig.INSTANCE.getUnderlinedLinks()
&& chatClickEvent != null
&& chatClickEvent.getAction() == ClickEvent.Action.OPEN_URL;
}

@Inject(method = "getUnderlined", at = @At("HEAD"), cancellable = true)
private void linkUnderline(CallbackInfoReturnable<Boolean> cir) {
if (chatting$hasURL()) {
cir.setReturnValue(true);
}
}

@Inject(method = "getColor", at = @At("HEAD"), cancellable = true)
private void linkColor(CallbackInfoReturnable<EnumChatFormatting> cir) {
if (chatting$hasURL()) {
cir.setReturnValue(EnumChatFormatting.BLUE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ object ChattingConfig : Config(
)
var peekMode = false

@Switch(
name = "Underlined Links", category = "General",
description = "Makes clickable links in chat blue and underlined.",
size = 1
)
var underlinedLinks = true

@Switch(
name = "Smooth Chat Messages",
category = "Animations", subcategory = "Messages",
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/mixins.chatting.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"GuiUtilsMixin",
"HUDUtilsMixin",
"InventoryPlayerMixin"
],
"mixins": [
"ChatStyleMixin"
]
}

0 comments on commit 7cc80b2

Please sign in to comment.