Procházet zdrojové kódy

new head rendering system

Kajetan Johannes Hammerle před 2 roky
rodič
revize
8f63854106

+ 3 - 3
src/main/java/me/km/networking/ModPacketHandler.java

@@ -72,9 +72,9 @@ public class ModPacketHandler {
         sendToPlayer(p, new StatusDisplay((byte) 3, (byte) 0, ""));
     }
 
-    public static void sendToHead(ServerPlayerEntity p, byte action, byte index, String name, int x,
-            int y, byte scale) {
-        sendToPlayer(p, new PlayerHead(action, index, name, x, y, scale));
+    public static void sendToHead(ServerPlayerEntity p, byte action, byte index, String name,
+            float x, float y, float width, float height) {
+        sendToPlayer(p, new PlayerHead(action, index, name, x, y, width, height));
     }
 
     public static void sendLeftClickEmpty() {

+ 21 - 15
src/main/java/me/km/networking/PlayerHead.java

@@ -12,20 +12,23 @@ public class PlayerHead {
     private byte action;
     private byte index;
     private String name;
-    private int x;
-    private int y;
-    private byte scale;
+    private float x;
+    private float y;
+    private float width;
+    private float height;
 
     public PlayerHead() {
         action = -1;
         index = -1;
         name = "";
-        x = -1;
-        y = -1;
-        scale = -1;
+        x = 0.0f;
+        y = 0.0f;
+        width = 0.0f;
+        height = 0.0f;
     }
 
-    public PlayerHead(byte action, byte index, String name, int x, int y, byte scale) {
+    public PlayerHead(byte action, byte index, String name, float x, float y, float width,
+            float height) {
         this.action = action;
         this.index = index;
         if(name.length() > 16) {
@@ -35,16 +38,18 @@ public class PlayerHead {
         }
         this.x = x;
         this.y = y;
-        this.scale = scale;
+        this.width = width;
+        this.height = height;
     }
 
     public static void writeBytes(PlayerHead ph, PacketBuffer buf) {
         buf.writeByte(ph.action);
         switch(ph.action) {
             case 1:
-                buf.writeInt(ph.x);
-                buf.writeInt(ph.y);
-                buf.writeByte(ph.scale);
+                buf.writeFloat(ph.x);
+                buf.writeFloat(ph.y);
+                buf.writeFloat(ph.width);
+                buf.writeFloat(ph.height);
                 buf.writeByte(ph.index);
                 byte[] b = ph.name.getBytes(StandardCharsets.UTF_8);
                 buf.writeInt(b.length);
@@ -61,9 +66,10 @@ public class PlayerHead {
         ph.action = buf.readByte();
         switch(ph.action) {
             case 1:
-                ph.x = buf.readInt();
-                ph.y = buf.readInt();
-                ph.scale = buf.readByte();
+                ph.x = buf.readFloat();
+                ph.y = buf.readFloat();
+                ph.width = buf.readFloat();
+                ph.height = buf.readFloat();
                 ph.index = buf.readByte();
                 int length = buf.readInt();
                 ph.name = buf.readBytes(length).toString(StandardCharsets.UTF_8);
@@ -79,7 +85,7 @@ public class PlayerHead {
         context.get().enqueueWork(() -> {
             switch(ph.action) {
                 case 1:
-                    PlayerHeadGui.INSTANCE.add(ph.index, ph.x, ph.y, ph.scale, ph.name);
+                    PlayerHeadGui.INSTANCE.add(ph.index, ph.x, ph.y, ph.width, ph.height, ph.name);
                     break;
                 case 2:
                     PlayerHeadGui.INSTANCE.remove(ph.index);

+ 19 - 9
src/main/java/me/km/networking/PlayerHeadGui.java

@@ -15,15 +15,17 @@ public class PlayerHeadGui extends AbstractGui {
     public final static PlayerHeadGui INSTANCE = new PlayerHeadGui(Minecraft.getInstance());
 
     private class HeadData {
-        private final int x;
-        private final int y;
-        private final int scale;
+        private final float x;
+        private final float y;
+        private final float width;
+        private final float height;
         private final ResourceLocation rl;
 
-        public HeadData(int x, int y, int scale, ResourceLocation rl) {
+        public HeadData(float x, float y, float width, float height, ResourceLocation rl) {
             this.x = x;
             this.y = y;
-            this.scale = scale;
+            this.width = width;
+            this.height = height;
             this.rl = rl;
         }
 
@@ -31,8 +33,16 @@ public class PlayerHeadGui extends AbstractGui {
         public void paint(Minecraft mc, MatrixStack matrixStack) {
             RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
             mc.getTextureManager().bindTexture(rl);
-            AbstractGui.blit(matrixStack, x, y, 8 * scale, 8 * scale, 8.0f, 8.0f, 8, 8, 64, 64);
-            AbstractGui.blit(matrixStack, x, y, 8 * scale, 8 * scale, 40.0f, 8.0f, 8, 8, 64, 64);
+            int scaledWidth = mc.getMainWindow().getScaledWidth();
+            int scaledHeight = mc.getMainWindow().getScaledHeight();
+            int intX = (int) (x * scaledWidth);
+            int intY = (int) (y * scaledHeight);
+            int intWidth = (int) (width * scaledWidth);
+            int intHeight = (int) (height * scaledHeight);
+            AbstractGui.blit(matrixStack, intX, intY, intWidth, intHeight, 8.0f, 8.0f, 8, 8, 64,
+                    64);
+            AbstractGui.blit(matrixStack, intX, intY, intWidth, intHeight, 40.0f, 8.0f, 8, 8, 64,
+                    64);
         }
     }
 
@@ -44,10 +54,10 @@ public class PlayerHeadGui extends AbstractGui {
         this.data = new TreeMap<>();
     }
 
-    public void add(int i, int x, int y, int scale, String name) {
+    public void add(int i, float x, float y, float width, float height, String name) {
         NetworkPlayerInfo info = this.mc.player.connection.getPlayerInfo(name);
         if(info != null) {
-            data.put(i, new HeadData(x, y, scale, info.getLocationSkin()));
+            data.put(i, new HeadData(x, y, width, height, info.getLocationSkin()));
         }
     }
 

+ 12 - 7
src/main/java/me/km/snuviscript/commands/HeadCommands.java

@@ -9,26 +9,31 @@ import net.minecraft.entity.player.ServerPlayerEntity;
 import net.minecraft.server.MinecraftServer;
 
 public class HeadCommands {
-    public static void registerFunctions(ScriptManager sm, Scripts scripts, Permissions perms, MinecraftServer server) {
+    public static void registerFunctions(ScriptManager sm, Scripts scripts, Permissions perms,
+            MinecraftServer server) {
         sm.registerConsumer("head.add", (sc, in) -> {
             byte id = in[1].getByte(sc);
             String name = in[2].getString(sc);
-            int x = in[3].getInt(sc);
-            int y = in[4].getInt(sc);
-            byte scale = in[5].getByte(sc);
+            float x = in[3].getFloat(sc);
+            float y = in[4].getFloat(sc);
+            float width = in[5].getFloat(sc);
+            float height = in[6].getFloat(sc);
             doForGroup(server, scripts, perms, in[0].get(sc), sc, p -> {
-                ModPacketHandler.sendToHead((ServerPlayerEntity) p, (byte) 1, id, name, x, y, scale);
+                ModPacketHandler.sendToHead((ServerPlayerEntity) p, (byte) 1, id, name, x, y, width,
+                        height);
             });
         });
         sm.registerConsumer("head.remove", (sc, in) -> {
             byte id = in[1].getByte(sc);
             doForGroup(server, scripts, perms, in[0].get(sc), sc, p -> {
-                ModPacketHandler.sendToHead((ServerPlayerEntity) p, (byte) 2, id, "", -1, -1, (byte) -1);
+                ModPacketHandler.sendToHead((ServerPlayerEntity) p, (byte) 2, id, "", 0.0f, 0.0f,
+                        0.0f, 0.0f);
             });
         });
         sm.registerConsumer("head.reset", (sc, in) -> {
             doForGroup(server, scripts, perms, in[0].get(sc), sc, p -> {
-                ModPacketHandler.sendToHead((ServerPlayerEntity) p, (byte) 3, (byte) -1, "", -1, -1, (byte) -1);
+                ModPacketHandler.sendToHead((ServerPlayerEntity) p, (byte) 3, (byte) -1, "", 0.0f,
+                        0.0f, 0.0f, 0.0f);
             });
         });
     }