The game crashed whilst ticking entity

Discussion in 'Spigot Plugin Development' started by nokoa, May 19, 2017.

  1. I am having an issue when spawning NPCs in 1.11.2, the client player appears to crash with this error:

    Code (Text):
    The game crashed whilst ticking entity
    Error: java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.Byte
    This is what I am doing to spawn the NPC

    Code (Text):
            PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
            setValue(packet, "a", entityID);
            setValue(packet, "b", gameprofile.getId());
            setValue(packet, "c", location.getX());
            setValue(packet, "d", location.getY());
            setValue(packet, "e", location.getZ());
            setValue(packet, "f", getFixRotation(location.getYaw()));
            setValue(packet, "g", getFixRotation(location.getPitch()));
            DataWatcher w = new DataWatcher(null);
            w.register(new DataWatcherObject<>(6, DataWatcherRegistry.c), 20f);
            w.register(new DataWatcherObject<>(10, DataWatcherRegistry.a),  (byte)127);
            setValue(packet, "h", w);

            sendNpcInfo(player);
            sendPacket(packet, player);
    I believe the issue is with the DataWatcher, but have no clue how to resolve this. This used to work, I was using protocol support which allowed previous versions to join as well, and it worked fine with 1.11.2 the spigot version used, but as I removed the plugin, the client crashes.
     
  2. The error says you are casting a float to a byte. If you believe the problem is DataWatcher then see what value it outputs, and if it is a float add a byte cast over the value w when calling setValue.
     
  3. Could you please post the full stacktrace of the error?
     
  4. your answer is right here