minecraft-src/net/minecraft/client/gui/spectator/PlayerMenuItem.java
2025-07-04 02:49:36 +03:00

46 lines
1.4 KiB
Java

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;
import net.minecraft.util.ARGB;
@Environment(EnvType.CLIENT)
public class PlayerMenuItem implements SpectatorMenuItem {
private final GameProfile profile;
private final Supplier<PlayerSkin> 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 brightness, float alpha) {
PlayerFaceRenderer.draw(guiGraphics, (PlayerSkin)this.skin.get(), 2, 2, 12, ARGB.white(alpha));
}
@Override
public boolean isEnabled() {
return true;
}
}