Packet Change Trouble

Discussion in 'Plugin Development' started by dylanisawesome1, Dec 14, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    dylanisawesome1

    Hello, I've been working very hard recently to fix a problem I have with mob/player packets... This is my current code:
    Code:
        public static Packet20NamedEntitySpawn namedEntityPacket(Byte entityID, Location loc, String name, int iteminhand) {
            DataWatcher tmp = new DataWatcher();
            tmp.a(0, (byte) 0);
            tmp.a(12, 0);
            Packet20NamedEntitySpawn packet = new Packet20NamedEntitySpawn();
            packet.a = entityID;
            packet.b = name;
            packet.c = MathHelper.floor(loc.getX() * 32.0D);
            packet.d = MathHelper.floor(loc.getY() * 32.0D);
            packet.e = MathHelper.floor(loc.getZ() * 32.0D);
            packet.f = (byte) ((int) loc.getYaw() * 256.0F / 360.0F);
            packet.g =  getByteFromDegree(loc.getPitch());
            packet.h =(short)iteminhand;
            Field datawatcher;
            try {
                datawatcher = packet.getClass().getDeclaredField("i");
                datawatcher.setAccessible(true);
                datawatcher.set(packet, tmp);
                datawatcher.setAccessible(false);
            } catch (Exception e) {
                  System.out.println("Error making packet?!");
                  e.printStackTrace();
                return null;
            }
            return packet;
        }
     
        public static Packet24MobSpawn mobPacket(Location loc, int id, int entityid) {
                DataWatcher tmp = new DataWatcher();
                tmp.a(0, (byte) 0);
                tmp.a(12, (int)0);
                Packet24MobSpawn packet = new Packet24MobSpawn();
                packet.a = entityid;
                packet.b = id;
                packet.c = (int)Math.floor(loc.getX() * 32.0D);
                packet.d = (int)Math.floor(loc.getY() * 32.0D);
                packet.e = (int)Math.floor(loc.getZ() * 32.0D);
                packet.f = getByteFromDegree(loc.getYaw());
                packet.g = getByteFromDegree(loc.getPitch());
                packet.h = packet.f;
               
                Field datawatcher;
                try {
                    datawatcher = packet.getClass().getDeclaredField("i");
                    datawatcher.setAccessible(true);
                    datawatcher.set(packet, tmp);
                    datawatcher.setAccessible(false);
                } catch (Exception e) {
                      System.out.println("Error making packet?!");
                      e.printStackTrace();
                    return null;
                }
                return packet;
            }
    This always seems to give me an end of stream when sent. I know it has something to do with the metadata, but I can't figure out how I would use the new metadata system in my code. Any help?
     
Thread Status:
Not open for further replies.

Share This Page