package net.minecraft.client.gui.spectator; import com.mojang.authlib.GameProfile; import java.util.function.Supplier; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.PlayerFaceRenderer; import net.minecraft.client.resources.PlayerSkin; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ServerboundTeleportToEntityPacket; @Environment(EnvType.CLIENT) public class PlayerMenuItem implements SpectatorMenuItem { private final GameProfile profile; private final Supplier skin; private final Component name; public PlayerMenuItem(GameProfile profile) { this.profile = profile; this.skin = Minecraft.getInstance().getSkinManager().lookupInsecure(profile); this.name = Component.literal(profile.getName()); } @Override public void selectItem(SpectatorMenu menu) { Minecraft.getInstance().getConnection().send(new ServerboundTeleportToEntityPacket(this.profile.getId())); } @Override public Component getName() { return this.name; } @Override public void renderIcon(GuiGraphics guiGraphics, float shadeColor, int alpha) { guiGraphics.setColor(1.0F, 1.0F, 1.0F, alpha / 255.0F); PlayerFaceRenderer.draw(guiGraphics, (PlayerSkin)this.skin.get(), 2, 2, 12); guiGraphics.setColor(1.0F, 1.0F, 1.0F, 1.0F); } @Override public boolean isEnabled() { return true; } }