Skip to content

Commit

Permalink
Sync fixes with 1.21.4 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbuilder1961 committed Jan 21, 2025
1 parent f2f7e10 commit 92035b3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ version=202.7.0
cfId=560042
mrId=MOqt4Z5n

# Required dependencies - https://fabricmc.net/develop
# Required dependencies - https://fabricmc.net/develop and https://modrinth.com/mod/architectury-api/versions?l=fabric
minecraft=1.20.2
yarn=+build.4
loader=0.16.9
loader=0.16.10
api=0.91.6+1.20.2
arch_api=10.1.20
loom=1.8-SNAPSHOT
arch_api=10.1.20
# mpp: https://github.com/modmuss50/mod-publish-plugin?tab=readme-ov-file#basic-usage and stonecutter: -
publish_plugin=0.7.4
#stonecutter_plugin=1.3.1
publish_plugin=0.8.3
#stonecutter_plugin=0.5.1

# Dependencies - modmenu: https://modrinth.com/mod/modmenu/versions?l=fabric and yacl: https://modrinth.com/mod/yacl/versions?l=fabric
modmenu=8.0.1
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
53 changes: 28 additions & 25 deletions src/main/java/obro1961/chatpatches/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.OtherClientPlayerEntity;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.scoreboard.Team;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.*;
import net.minecraft.util.Util;
Expand Down Expand Up @@ -148,32 +149,34 @@ public Style makeHoverStyle(Date when) {
* player entity and have both a valid name and UUID.
*/
public MutableText formatPlayername(GameProfile profile) {
Style style = BLANK_STYLE.withColor(chatNameColor);
Style style = BLANK_STYLE.withColor(chatNameColor); // defaults to the config-specified color
try {
PlayerEntity entity = mc.world != null ? mc.world.getPlayerByUuid(profile.getId()) : null;
Team team = null;

if(entity != null) {
team = entity.getScoreboard().getPlayerTeam(profile.getName());
style = entity.getDisplayName().getStyle().withColor( entity.getTeamColorValue() != 0xffffff ? entity.getTeamColorValue() : chatNameColor );
}

if(team != null) {
// note: doesn't set the style on every append, as it's already set in the parent text. might cause issues?
// if the player is on a team, add the prefix and suffixes from the config AND team (if they exist) to the formatted name
MutableText playername = text(profile.getName());
String[] configFormat = chatNameFormat.split("\\$");
Text configPrefix = text(configFormat[0]);
Text configSuffix = text(configFormat[1] + " ");

return Text.empty().setStyle(style)
.append(configPrefix)
.append(team.getPrefix())
.append(playername)
.append(team.getSuffix())
.append(configSuffix);
// note: creating a new PlayerListEntry might cause issues?
Text teamName = mc.inGameHud.getPlayerListHud().getPlayerName( new PlayerListEntry(profile, false) );
String[] configFormat = chatNameFormat.split("\\$");

// override the custom color with the team one if it exists
if(teamName.getStyle().getColor() instanceof TextColor color)
style = style.withColor(color);


// uses a fake player entity to get the display name style (hover/click/insertion)
//noinspection DataFlowIssue: world should ALWAYS exist when executing this method
Text displayName = new OtherClientPlayerEntity(mc.world, profile).getDisplayName();
if(teamName.getSiblings().isEmpty()) {
return Text.empty().setStyle( style.withParent(displayName.getStyle()) )
.append( text(configFormat[0]) ) // config prefix
.append( text(profile.getName()) ) // playername
.append( text(configFormat[1] + " ") ); // config suffix
} else {
return Text.empty().setStyle( style.withParent(displayName.getStyle()) )
.append( text(configFormat[0]) ) // config prefix
.append( teamName.getSiblings().getFirst() ) // team prefix
.append( teamName.getSiblings().get(1) ) // team playername
.append( teamName.getSiblings().getLast() ) // team suffix
.append( text(configFormat[1] + " ") ); // config suffix
}
} catch(Exception e) {
} catch(RuntimeException e) {
LOGGER.error("[Config.formatPlayername] /!\\ An error occurred while trying to format '{}'s playername /!\\", profile.getName());
ChatPatches.logReportMsg(e);
}
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/obro1961/chatpatches/util/ChatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,13 @@ public static Text getMsgPart(Text message, int index) {
* Returns a {@link MutableText} representing the argument
* located at the given index of the given
* {@link TranslatableTextContent}. Needed because of a
* phenomenon where the {@link TranslatableTextContent#getArg(int)}
* weird phenomenon where the
* method can return a {@link String} or other non-Text related
* {@linkplain TranslatableTextContent#getArg(int) original
* object, which otherwise causes {@link ClassCastException}s.
* <code>getArg</code> method} can return a non-Text object, which
* <p>
* typically causes a {@link ClassCastException} to be thrown.
* Wraps {@link String}s in {@link Text#literal(String)}
* and nulls in {@link Text#empty()}.
*
*
* @implNote
* @return Regular {@link Text} objects as expected,
* If {@code index} is negative, it's added to the args array
* {@link String} arguments as {@linkplain Text#literal(String)
* length. In other words, passing index {@code -n} will
* literal texts}, and nulls as {@linkplain Text#empty() empty texts}.
*/
public static MutableText getArg(TranslatableTextContent content, int index) {
Expand Down Expand Up @@ -386,6 +376,7 @@ else if( config.counterCheckStyle && !copyWithoutContent(incoming).equals(copyWi
return TextUtils.newText(incoming.getContent(), siblings, incoming.getStyle());
}


/** Represents the metadata of a chat message. */
public record MessageData(GameProfile sender, Date timestamp, boolean vanilla) {}
}
4 changes: 4 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"JustALittleWolf (#118, #123, #131, #132)",
"SmajloSlovakian (#139-141)",
"LucunJi (#152, #154)",
"DylanKeir (#190)",
"Nooiee (ko_kr/#193)",
"suoyukii (zh_cn/#203)",
"demorogabrtz (pt_br/#204)",
"NotRyken (#215)"
],
"contact": {
Expand Down

0 comments on commit 92035b3

Please sign in to comment.