Added back the tablist dimension indicator

This commit is contained in:
2025-03-25 21:17:12 +01:00
parent 7d4dca66f0
commit 83cc3a38e9
11 changed files with 73 additions and 155 deletions

View File

@ -0,0 +1,34 @@
package wtf.hak.survivalfabric.mixin;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import wtf.hak.survivalfabric.commands.SpectatorCommand;
import wtf.hak.survivalfabric.utils.Messages;
@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin {
@Inject(method = "getPlayerListName", at = @At("HEAD"), cancellable = true)
private void changePlayerListName(CallbackInfoReturnable<Text> cir) {
ServerPlayerEntity p = (ServerPlayerEntity) (Object) this;
String world = p.getServerWorld().getRegistryKey().getValue().toTranslationKey();
String finalName;
if(!SpectatorCommand.spectating.containsKey(p)) {
finalName = switch (world) {
case "minecraft.overworld" -> Messages.OVERWORLD_PREFIX;
case "minecraft.the_nether" -> Messages.NETHER_PREFIX;
case "minecraft.the_end" -> Messages.END_PREFIX;
default -> Messages.UNKNOWN_PREFIX;
};
} else
finalName = Messages.SPECTATOR_PREFIX;
finalName += "§7" + p.getName().getString();
cir.setReturnValue(Text.of(finalName));
}
}