Solved EntityVelocity Packet not working [ProtocolLib]

Discussion in 'Spigot Plugin Development' started by Gerolmed, Apr 15, 2018.

  1. Im trying to boost up an Entity via packets using protocolLib. Other packets work perfectly fine, just the velocity not.
    Method Call:
    Code (Text):
    plugin.getEntityUtils().addVelocity(entityId, new Vector(0.2, 0.9, 0.2), nearPlayers);
    In EntityUtils:
    Code (Text):
    public void addVelocity(int entityId, Vector vel, Player... receivers) {
            if(receivers == null || receivers.length == 0)
                return;
            PacketContainer velocity = plugin.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_VELOCITY);
         
            velocity.getIntegers().write(0, entityId);
         
            velocity.getIntegers().write(1, (int) (vel.getX()*8000));
            velocity.getIntegers().write(2, (int) (vel.getY()*8000));
            velocity.getIntegers().write(3, (int) (vel.getZ()*8000));
         
         
       
         
            sendPacket(velocity, receivers);
        }
    Im using * 8000 because the wiki says it is later used as: value(this has to be an int) / 8000 per 20 ticks
     
    #1 Gerolmed, Apr 15, 2018
    Last edited: Apr 15, 2018
  2. show the sendPacket mathod.

    and why are you using packets for this?
     
  3. Because the Entity only is clientsided and only exists for a few players
    sendPacket:
    Code (Text):
    private void sendPacket(PacketContainer packet, Player[] receivers) {
            for(Player player : receivers) {
                try {
                    plugin.getProtocolManager().sendServerPacket(player, packet);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
     
  4. Does Protocollib has a method getShorts? Use that instead.
     
  5. What does removeId(entityId); do exactly?

    Have you tried sending another packet like an Entity Equipment packet with this exact id?

    And like ysl3000 said, try to use shorts instead of the ints you are currently using.
     
  6. It does, but the wiki isn't up to date they changed the values to integers. I tried shorts before, but after that causing an error I looked in the nms method just to find that they now use ints.
     
  7. I already removed that method from my code. Was just a mistake that that was in there
     
  8. Still isn't working... maybe this helps: I'm trying to show dmg values through the name of armor stands. I want to keep this client sided because the name depends on the selected user language(I haven't added this in this case yet). The armourstands are spawned client sided with a deepClone (I'm on my phone) are small, have no gravity, show their custom name and have collision to false. BUT I tried applying the upper method to the damaged entity with no result.
     
  9. I don't get it. What are you trying to do. In the initial post you said you wanted to do stuff with entity velocity but now you are going towards a clientside armorstand name if I am right?

    Can you please explain it again so I might be able to help. thnx
     
  10. I'm creating the armourstand and setting the name with out a problem and than I try pushing it up into the air. I just added the upper explanation to give some background information.
     
  11. The client does not calculate positions of entities and other players itself based on velocity.
     
    • Like Like x 1

Share This Page