|
| 1 | +package com.teammoeg.frostedheart.mixin.ftb; |
| 2 | + |
| 3 | +import dev.ftb.mods.ftbteams.FTBTeams; |
| 4 | +import dev.ftb.mods.ftbteams.api.client.KnownClientPlayer; |
| 5 | +import dev.ftb.mods.ftbteams.data.ClientTeam; |
| 6 | +import dev.ftb.mods.ftbteams.data.ClientTeamManagerImpl; |
| 7 | +import net.minecraft.client.Minecraft; |
| 8 | +import org.spongepowered.asm.mixin.Final; |
| 9 | +import org.spongepowered.asm.mixin.Mixin; |
| 10 | +import org.spongepowered.asm.mixin.Shadow; |
| 11 | +import org.spongepowered.asm.mixin.injection.At; |
| 12 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 13 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 14 | + |
| 15 | +import java.nio.charset.StandardCharsets; |
| 16 | +import java.util.Map; |
| 17 | +import java.util.UUID; |
| 18 | +@Mixin(ClientTeamManagerImpl.class) |
| 19 | +public abstract class MixinCTManager { |
| 20 | + @Shadow private ClientTeam selfTeam; |
| 21 | + @Shadow private KnownClientPlayer selfKnownPlayer; |
| 22 | + @Shadow @Final |
| 23 | + private Map<UUID, ClientTeam> teamMap; |
| 24 | + @Shadow @Final |
| 25 | + private Map<UUID, KnownClientPlayer> knownPlayers; |
| 26 | + |
| 27 | + @Inject(method = "initSelfDetails", at = @At("HEAD"), cancellable = true, remap = false) |
| 28 | + private void onInitSelfDetails(UUID selfTeamID, CallbackInfo ci) { |
| 29 | + this.selfTeam = this.teamMap.get(selfTeamID); |
| 30 | + UUID userId = Minecraft.getInstance().getUser().getGameProfile().getId(); |
| 31 | + this.selfKnownPlayer = this.knownPlayers.get(userId); |
| 32 | + |
| 33 | + if (this.selfKnownPlayer == null) { |
| 34 | + String username = Minecraft.getInstance().getUser().getGameProfile().getName(); |
| 35 | + UUID offlineId = UUID.nameUUIDFromBytes( |
| 36 | + ("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8) |
| 37 | + ); |
| 38 | + this.selfKnownPlayer = this.knownPlayers.get(offlineId); |
| 39 | + } |
| 40 | + if (this.selfKnownPlayer == null) { |
| 41 | + FTBTeams.LOGGER.error( |
| 42 | + "Local player id {} was not found in the known players list [{}]!", |
| 43 | + userId, |
| 44 | + String.join(",", this.knownPlayers.keySet().stream() |
| 45 | + .map(UUID::toString).toList()) |
| 46 | + ); |
| 47 | + } |
| 48 | + ci.cancel(); |
| 49 | + } |
| 50 | +} |
0 commit comments