Entity field names?

Discussion in 'Spigot Plugin Development' started by Bombastickj, Jun 20, 2015.

  1. Hello Programmers!
    I need help at this :

    Code (Text):
        public PacketPlayOutSpawnEntity spawnMob(Location loc, int id) {

            PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity();

            packet.a = id; // Entity UDID
            packet.b = 50; // id for creeper
            packet.c = Math.floor(loc.getX() * 32d);
            packet.d = Math.floor(loc.getY() * 32d);
            packet.e = Math.floor(loc.getZ() * 32d);
            packet.f = (byte) loc.getYaw();
            packet.g = (byte) loc.getPitch();
            packet.h = packet.f;

            Field metadata = packet.getClass().getDeclaredField("s");
            metadata.setAccessible(true);
            metadata.set(packet, field);

            return packet;
        }

        public PacketPlayOutRelEntityMoveLook movePacket(Location move, int id) {
            PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook();
            packet.a = id;
            packet.b = (byte) move.getX();
            packet.c = (byte) move.getY();
            packet.d = (byte) move.getZ();
            packet.e = (byte) move.getYaw();
            packet.f = (byte) move.getPitch();

            return packet;
        }
    i dont know how to do this with fields. Have anyone a list of the fields with a description?
    Thankyou!
    Bombastickj :)
     
  2. What is the error?
     
  3. The Error is:
    "The field PacketPlayOutSpawnEntity.a is not visible"
     
  4. PacketPlayOutSpawnEntity allows 2 or 3 arguments if I recall, where 1 is the entity ID. you might be able to use that.

    Otherwise you need to use reflection.
     
  5. Oh no sorry the string "packet.a = entity.getEntityId();" and the other packet.a/b/c/d/ etc. create this error..
     
  6. Then I guess reflection is the only way ;_;
     
  7. No i think its not.. look at this code only one error comes in the console because the Field is not correct.. i dont know what field i should use.

    Code (Text):
        public static DataWatcher field;

        public static PacketPlayOutSpawnEntity spawnMob(Location loc, int id) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {

            PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity();

            packet.a(id); //id for entity
            packet.b((int) Math.floor(loc.getX() * 32d));
            packet.c((int) Math.floor(loc.getY() * 32d));
            packet.d((int) Math.floor(loc.getZ() * 32d));
            packet.e((byte) loc.getYaw());
            packet.f((byte) loc.getPitch());

            Field metadata = packet.getClass().getDeclaredField("s");
            metadata.setAccessible(true);
            metadata.set(packet, field);

            return packet;
        }
    this is wrong but waht can i use to fix it? "Field metadata = packet.getClass().getDeclaredField("s");"