| 1 | package net.minecraft.client.gui.screens.inventory.tooltip;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.gui.Font;
|
| 7 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 8 | import net.minecraft.client.gui.components.PlayerFaceExtractor;
|
| 9 | import net.minecraft.client.renderer.PlayerSkinRenderCache;
|
| 10 | import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
| 11 |
|
| 12 | @Environment(EnvType.CLIENT)
|
| 13 | public class ClientActivePlayersTooltip implements ClientTooltipComponent {
|
| 14 | private static final int SKIN_SIZE = 10;
|
| 15 | private static final int PADDING = 2;
|
| 16 | private final List<PlayerSkinRenderCache.RenderInfo> activePlayers;
|
| 17 |
|
| 18 | public ClientActivePlayersTooltip(final ClientActivePlayersTooltip.ActivePlayersTooltip activePlayersTooltip) {
|
| 19 | this.activePlayers = activePlayersTooltip.profiles();
|
| 20 | }
|
| 21 |
|
| 22 | @Override
|
| 23 | public int getHeight(final Font font) {
|
| 24 | return this.activePlayers.size() * 12 + 2;
|
| 25 | }
|
| 26 |
|
| 27 | private static String getName(final PlayerSkinRenderCache.RenderInfo activePlayer) {
|
| 28 | return activePlayer.gameProfile().name();
|
| 29 | }
|
| 30 |
|
| 31 | @Override
|
| 32 | public int getWidth(final Font font) {
|
| 33 | int widest = 0;
|
| 34 |
|
| 35 | for (PlayerSkinRenderCache.RenderInfo activePlayer : this.activePlayers) {
|
| 36 | int width = font.width(getName(activePlayer));
|
| 37 | if (width > widest) {
|
| 38 | widest = width;
|
| 39 | }
|
| 40 | }
|
| 41 |
|
| 42 | return widest + 10 + 6;
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | public void extractImage(final Font font, final int x, final int y, final int w, final int h, final GuiGraphicsExtractor graphics) {
|
| 47 | for (int i = 0; i < this.activePlayers.size(); i++) {
|
| 48 | PlayerSkinRenderCache.RenderInfo activePlayer = this.activePlayers.get(i);
|
| 49 | int y1 = y + 2 + i * 12;
|
| 50 | PlayerFaceExtractor.extractRenderState(graphics, activePlayer.playerSkin(), x + 2, y1, 10);
|
| 51 | graphics.text(font, getName(activePlayer), x + 10 + 4, y1 + 2, -1);
|
| 52 | }
|
| 53 | }
|
| 54 |
|
| 55 | @Environment(EnvType.CLIENT)
|
| 56 | public record ActivePlayersTooltip(List<PlayerSkinRenderCache.RenderInfo> profiles) implements TooltipComponent {
|
| 57 | }
|
| 58 | }
|
| 59 |
|