Added Hide Team Prefix/Suffix option to player right-click menu

This commit is contained in:
Moulberry committed 2025-02-11 17:46:20 +08:00
1 parent ab9b9d4a99
commit f8406e428e
4 files changed
+102 -1

No files matched your search

@@ -2,6 +2,10 @@ package com.moulberry.flashback;
import com.moulberry.flashback.playback.ReplayServer;
import it.unimi.dsi.fastutil.objects.Object2FloatFunction;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.contents.PlainTextContents;
import org.jetbrains.annotations.Nullable;
import java.lang.reflect.Field;
@@ -160,6 +164,31 @@ public class Utils {
}
}
public static boolean isComponentEmpty(Component component) {
if (component == CommonComponents.EMPTY) {
return true;
}
boolean isSelfEmpty = false;
if (component.getContents() == PlainTextContents.EMPTY) {
isSelfEmpty = true;
} else if (component.getContents() instanceof PlainTextContents plainTextContents) {
isSelfEmpty = ChatFormatting.stripFormatting(plainTextContents.text()).isEmpty();
}
if (isSelfEmpty) {
for (Component sibling : component.getSiblings()) {
if (!isComponentEmpty(sibling)) {
return false;
}
}
return true;
}
return false;
}
public static int exportSequenceCount = 1;
public static String resolveFilenameTemplate(String template) {
LocalDateTime dateTime = LocalDateTime.now();
@@ -4,6 +4,7 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.yggdrasil.ProfileResult;
import com.moulberry.flashback.FilePlayerSkin;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.Utils;
import com.moulberry.flashback.editor.ui.ImGuiHelper;
import com.moulberry.flashback.exporting.AsyncFileDialogs;
import com.moulberry.flashback.state.EditorState;
@@ -13,9 +14,12 @@ import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Team;
import java.nio.file.Path;
import java.util.UUID;
@@ -99,6 +103,32 @@ public class SelectedEntityPopup {
editorState.nameOverride.put(entity.getUUID(), string);
}
}
if (editorState.hideTeamPrefix.contains(player.getUUID())) {
if (ImGui.checkbox("Hide Team Prefix", true)) {
editorState.hideTeamPrefix.remove(player.getUUID());
}
} else {
PlayerTeam team = player.getTeam();
if (team != null && !Utils.isComponentEmpty(team.getPlayerPrefix())) {
if (ImGui.checkbox("Hide Team Prefix", false)) {
editorState.hideTeamPrefix.add(player.getUUID());
}
}
}
if (editorState.hideTeamSuffix.contains(player.getUUID())) {
if (ImGui.checkbox("Hide Team Suffix", true)) {
editorState.hideTeamSuffix.remove(player.getUUID());
}
} else {
PlayerTeam team = player.getTeam();
if (team != null && !Utils.isComponentEmpty(team.getPlayerSuffix())) {
if (ImGui.checkbox("Hide Team Suffix", false)) {
editorState.hideTeamSuffix.add(player.getUUID());
}
}
}
}
ImGuiHelper.separatorWithText("Change Skin & Cape (UUID)");
@@ -1,13 +1,21 @@
package com.moulberry.flashback.mixin.visuals;
import com.mojang.authlib.GameProfile;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.moulberry.flashback.Utils;
import com.moulberry.flashback.state.EditorState;
import com.moulberry.flashback.state.EditorStateManager;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.PlayerModelPart;
import net.minecraft.world.level.Level;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Team;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@@ -32,4 +40,36 @@ public abstract class MixinPlayer extends LivingEntity {
}
}
@WrapOperation(method = "getDisplayName", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/scores/PlayerTeam;formatNameForTeam(Lnet/minecraft/world/scores/Team;Lnet/minecraft/network/chat/Component;)Lnet/minecraft/network/chat/MutableComponent;"))
public MutableComponent getDisplayName_formatNameForTeam(Team team, Component component, Operation<MutableComponent> original) {
EditorState editorState = EditorStateManager.getCurrent();
if (editorState != null && team instanceof PlayerTeam playerTeam) {
boolean hidePrefix = editorState.hideTeamPrefix.contains(this.uuid) && !Utils.isComponentEmpty(playerTeam.getPlayerPrefix());
boolean hideSuffix = editorState.hideTeamSuffix.contains(this.uuid) && !Utils.isComponentEmpty(playerTeam.getPlayerSuffix());
if (hidePrefix || hideSuffix) {
MutableComponent mutableComponent = Component.empty();
if (!hidePrefix) {
mutableComponent = mutableComponent.append(playerTeam.getPlayerPrefix());
}
mutableComponent = mutableComponent.append(component);
if (!hideSuffix) {
mutableComponent = mutableComponent.append(playerTeam.getPlayerSuffix());
}
ChatFormatting chatFormatting = playerTeam.getColor();
if (chatFormatting != ChatFormatting.RESET) {
mutableComponent.withStyle(chatFormatting);
}
return mutableComponent;
}
}
return original.call(team, component);
}
}
@@ -51,6 +51,8 @@ public class EditorState {
public Map<UUID, GameProfile> skinOverride = new HashMap<>();
public Map<UUID, FilePlayerSkin> skinOverrideFromFile = new HashMap<>();
public Map<UUID, String> nameOverride = new HashMap<>();
public Set<UUID> hideTeamPrefix = new HashSet<>();
public Set<UUID> hideTeamSuffix = new HashSet<>();
public EditorState() {
this.scenes = new ArrayList<>();