PlayerHeadGui.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package me.km.networking;
  2. import com.mojang.blaze3d.matrix.MatrixStack;
  3. import com.mojang.blaze3d.systems.RenderSystem;
  4. import java.util.TreeMap;
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.client.gui.AbstractGui;
  7. import net.minecraft.client.network.play.NetworkPlayerInfo;
  8. import net.minecraft.util.ResourceLocation;
  9. import net.minecraftforge.api.distmarker.Dist;
  10. import net.minecraftforge.api.distmarker.OnlyIn;
  11. @OnlyIn(Dist.CLIENT)
  12. public class PlayerHeadGui extends AbstractGui {
  13. public final static PlayerHeadGui INSTANCE = new PlayerHeadGui(Minecraft.getInstance());
  14. private class HeadData {
  15. private final float x;
  16. private final float y;
  17. private final float width;
  18. private final float height;
  19. private final ResourceLocation rl;
  20. public HeadData(float x, float y, float width, float height, ResourceLocation rl) {
  21. this.x = x;
  22. this.y = y;
  23. this.width = width;
  24. this.height = height;
  25. this.rl = rl;
  26. }
  27. @SuppressWarnings("deprecation")
  28. public void paint(Minecraft mc, MatrixStack matrixStack) {
  29. RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  30. mc.getTextureManager().bind(rl);
  31. int scaledWidth = mc.getWindow().getGuiScaledWidth();
  32. int scaledHeight = mc.getWindow().getGuiScaledHeight();
  33. int intX = (int) (x * scaledWidth);
  34. int intY = (int) (y * scaledHeight);
  35. int intWidth = (int) (width * scaledWidth);
  36. int intHeight = (int) (height * scaledHeight);
  37. AbstractGui.blit(matrixStack, intX, intY, intWidth, intHeight, 8.0f, 8.0f, 8, 8, 64,
  38. 64);
  39. AbstractGui.blit(matrixStack, intX, intY, intWidth, intHeight, 40.0f, 8.0f, 8, 8, 64,
  40. 64);
  41. }
  42. }
  43. private final TreeMap<Integer, HeadData> data;
  44. private final Minecraft mc;
  45. public PlayerHeadGui(Minecraft mc) {
  46. this.mc = mc;
  47. this.data = new TreeMap<>();
  48. }
  49. public void add(int i, float x, float y, float width, float height, String name) {
  50. NetworkPlayerInfo info = this.mc.player.connection.getPlayerInfo(name);
  51. if(info != null) {
  52. data.put(i, new HeadData(x, y, width, height, info.getSkinLocation()));
  53. }
  54. }
  55. public void remove(int i) {
  56. data.remove(i);
  57. }
  58. public void clear() {
  59. data.clear();
  60. }
  61. public void paint(MatrixStack matrixStack) {
  62. data.values().forEach(head -> head.paint(mc, matrixStack));
  63. }
  64. }