Skip to content

Commit

Permalink
Merge branch '1.19.1' into 1.19.3
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	src/main/java/eu/pb4/styledchat/StyledChatUtils.java
  • Loading branch information
Patbox committed Apr 9, 2023
2 parents 3973054 + b8f3a8b commit a85ee63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabric_version=0.68.1+1.19.3

# Mod Properties

mod_version = 2.1.3+1.19.3
mod_version = 2.1.4+1.19.3
maven_group = eu.pb4
archives_base_name = styled-chat

Expand Down
27 changes: 21 additions & 6 deletions src/main/java/eu/pb4/styledchat/mixin/PlayerEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.pb4.styledchat.mixin;

import eu.pb4.styledchat.StyledChatStyles;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand All @@ -11,16 +12,30 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerEntity.class)
public class PlayerEntityMixin {
public abstract class PlayerEntityMixin {
@Unique
private boolean ignoreNextCalls = false;
private Text styledChat$cachedName = Text.empty();

@Unique
private int styledChat$cachedAge = -1234568;

@Unique
private boolean styledChat$ignoreNextCalls = false;

@Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true)
private void styledChat_replaceDisplayName(CallbackInfoReturnable<Text> cir) {
if (!this.ignoreNextCalls && ((Object) this) instanceof ServerPlayerEntity player) {
this.ignoreNextCalls = true;
cir.setReturnValue(StyledChatStyles.getDisplayName(player, cir.getReturnValue()));
this.ignoreNextCalls = false;
if (!this.styledChat$ignoreNextCalls && ((Object) this).getClass() == ServerPlayerEntity.class) {
if (this.styledChat$cachedAge == ((Entity) (Object) this).age) {
cir.setReturnValue(this.styledChat$cachedName);
return;
}

this.styledChat$ignoreNextCalls = true;
var name = StyledChatStyles.getDisplayName((ServerPlayerEntity) (Object) this, cir.getReturnValue());
this.styledChat$ignoreNextCalls = false;
this.styledChat$cachedName = name;
this.styledChat$cachedAge = ((Entity) (Object) this).age;
cir.setReturnValue(name);
}
}
}

0 comments on commit a85ee63

Please sign in to comment.