aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java
blob: 4adf97a8ca405919725700f7f03c60919ab3c3e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package de.hysky.skyblocker.skyblock.tabhud.widget.component;

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.PlayerSkinDrawer;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.scoreboard.Team;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

/**
 * Component that consists of a player's skin icon and their name
 */
public class PlayerComponent extends Component {

    private static final int SKIN_ICO_DIM = 8;

    private final Text name;
    private final Identifier tex;

    public PlayerComponent(PlayerListEntry ple) {

    	boolean plainNames = SkyblockerConfigManager.get().uiAndVisuals.tabHud.plainPlayerNames;
        Team team = ple.getScoreboardTeam();
        String username = ple.getProfile().getName();
        name = (team != null && !plainNames) ? Text.empty().append(team.getPrefix()).append(Text.literal(username).formatted(team.getColor())).append(team.getSuffix()) : Text.of(username);
        tex = ple.getSkinTextures().texture();

        this.width = SKIN_ICO_DIM + PAD_S + txtRend.getWidth(name);
        this.height = txtRend.fontHeight;
    }

    @Override
    public void render(DrawContext context, int x, int y) {
        PlayerSkinDrawer.draw(context, tex, x, y, SKIN_ICO_DIM);
        context.drawText(txtRend, name, x + SKIN_ICO_DIM + PAD_S, y, 0xffffffff, false);
    }

}