Dragon Breath packet

Discussion in 'Spigot Plugin Development' started by cocoraid, May 29, 2016.

  1. Hello,

    I was interested in the dragon's breath, so I tried to make it with packet:

    Code (Text):

    public class DragonBreath {

       private Location location;
       private EntityEnderDragon dragon;

       public DragonBreath(Location location) {
         this.location = location;
       }

       public void spawnDragon() {
         WorldServer s = ((CraftWorld)location.getWorld()).getHandle();
         dragon = new EntityEnderDragon(s);
         dragon.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
         Reflection.getField(dragon.getClass(), DragonControllerManager.class, 0).get(dragon).a(DragonControllerPhase.f);
         PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(dragon);
         Bukkit.getOnlinePlayers().forEach(cur -> NMS.sendPacket(cur, packet));
       }

       public void breath() {
         DataWatcher d = new DataWatcher(null);
         d.register(DataWatcher.a(EntityEnderDragon.class, DataWatcherRegistry.b), Integer.valueOf(DragonControllerPhase.f.b()));
         PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(dragon.getId(), d, true);
         Bukkit.getOnlinePlayers().forEach(cur -> NMS.sendPacket(cur, packet));
       }

    }
     
    upload_2016-5-29_12-8-26.gif

    I have started to use reflection:

    Reflection.getField(dragon.getClass(), DragonControllerManager.class, 0).get(dragon).a(DragonControllerPhase.f);

    //phase f -> public static final DragonControllerPhase<DragonControllerLandedFlame> f = a(DragonControllerLandedFlame.class, "SittingFlaming");

    It works, but the dragon breath 1 time and you can't call the method after the dragon is spawned.


    So I used entity metadata packet like the spigot nms code in EntityEnderDragon.class:

    Code (Text):

      protected void i() {
        super.i();
        getDataWatcher().register(a, Integer.valueOf(DragonControllerPhase.k.b()));
      }
     
    Code (Text):

    public void breath() {
         DataWatcher d = new DataWatcher(null);
         d.register(DataWatcher.a(EntityEnderDragon.class, DataWatcherRegistry.b), Integer.valueOf(DragonControllerPhase.f.b()));
         PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(dragon.getId(), d, true);
         Bukkit.getOnlinePlayers().forEach(cur -> NMS.sendPacket(cur, packet));
       }
     
    but nothing happens

    And I have this error:

    Code (Text):

    [14:22:32 WARN]: java.lang.IllegalArgumentException: Data value id is too big with 255! (Max is 254)
    [14:22:32 WARN]:     at net.minecraft.server.v1_9_R1.DataWatcher.a(DataWatcher.java:50)
    [14:22:32 WARN]:     at fr.cocoraid.test.tests.DragonBreath.breath(DragonBreath.java:39)
    [14:22:32 WARN]:     at fr.cocoraid.test.listeners.event.Breath.updater(Breath.java:17)
    [14:22:32 WARN]:     at sun.reflect.GeneratedMethodAccessor157.invoke(Unknown Source)
    [14:22:32 WARN]:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [14:22:32 WARN]:     at java.lang.reflect.Method.invoke(Method.java:497)
    [14:22:32 WARN]:     at fr.arkemis.api.updater.UpdateHandler.callUpdates(UpdateHandler.java:48)
    [14:22:32 WARN]:     at fr.arkemis.api.updater.Counter.run(Counter.java:15)
    [14:22:32 WARN]:     at org.bukkit.craftbukkit.v1_9_R1.scheduler.CraftTask.run(CraftTask.java:71)
    [14:22:32 WARN]:     at org.bukkit.craftbukkit.v1_9_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350)
    [14:22:32 WARN]:     at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:729)
    [14:22:32 WARN]:     at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400)
    [14:22:32 WARN]:     at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:660)
    [14:22:32 WARN]:     at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:559)
    [14:22:32 WARN]:     at java.lang.Thread.run(Thread.java:745)
     
     

    Attached Files:

  2. Is it that hard to read?

    java.lang.IllegalArgumentException: Data value id is too big with 255! (Max is 254)
     
  3. Bukkit.broadcastMessage("id: " + Integer.valueOf(DragonControllerPhase.f.b()));
    id = 5....
     
  4. Somehow is gets up to 255? Debug the ID see if that changes.
     
  5. I used : d.register(DataWatcher.a(EntityEnderDragon.class, DataWatcherRegistry.b),5);
    now, I don"t have error, but nothing happens
     
  6. Use the old method and debug the ID, Somehow it goes up to 255
     
  7. Bukkit.broadcastMessage("id: " + Integer.valueOf(DragonControllerPhase.f.b()));
    id = 5....
    Already debugged it
     
  8. Doesn't it change?

    Mind giving me these lines:

    DragonBreath.java:39)
    Breath.java:17)
     
    #8 TheBlackTeddy, May 29, 2016
    Last edited: May 29, 2016
  9. This really weird 0_o
    I no longer have the error
    Code (Text):

    public void breath() {
         DataWatcher d = new DataWatcher(null);
         //Bukkit.broadcastMessage("id: " + Integer.valueOf(DragonControllerPhase.f.b()));
       l39  d.register(DataWatcher.a(EntityEnderDragon.class, DataWatcherRegistry.b), Integer.valueOf(DragonControllerPhase.f.b()));
         PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(dragon.getId(), d, true);
         Bukkit.getOnlinePlayers().forEach(cur -> NMS.sendPacket(cur, packet));
       }
     
    Every second, I call the breath method
    But after a few seconds the error appears.
    If I call the method every 5 seconds I don"t have errors
     
  10. Is it possible to unregister it? So you register it > use it > Unregister > repeat.
    I have not much knowledge with packets so yeah :p
     
  11. If I call the method every 5 seconds I don"t have errors .. and the id does not change (id = 5)
     
  12. [14:22:32 WARN]: at fr.arkemis.api.updater.UpdateHandler.callUpdates(UpdateHandler.java:48)
    [14:22:32 WARN]: at fr.arkemis.api.updater.Counter.run(Counter.java:15)
    Think it has something to do with the api :/
     
  13. nope, there is no problem with the api, I think I do not correctly use the packet
     
  14. Well, it has something to do with the API else it won't be called at the api, hmm. Strange, you seem to use the packets fine.
     
  15. No API has nothing , it is like a scheduler
     
  16. Please don't bump within 24 hours, just be patient ;)