Solved Detect NPC Click

Discussion in 'Plugin Development' started by Corndogoz, Jul 26, 2016.

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

    Corndogoz

    Hi guys, so I'm making my own custom npcs with EntityPlayers, and I would like to know what event is triggered, when a player punches or right clicks the npc? I already tried PlayerInteractEntity, and it did nothing, and I cannot think of anything else. Any help?
     
  2. Take a look at this thread
     
    Last edited: Jul 26, 2016
  3. Offline

    mine-care

    @Corndogoz @FisheyLP If the player is spawned using packets, then there is no entity to represent it on the server side thus the API events wont fire... I may be wrong, so you can do a simple test before taking my word.

    If it is so, you will have to listen for packets, and more specifically the "PacketPlayInUseEntity", check if the entity ID matches the id of the fake player, check if the action (EnumEntityUseAction) is "INTERACT" and bingo! If both are true then you know who right clicked the custom entity ;)
     
  4. Offline

    Corndogoz

    Ahh thank you :) And by id, do you mean uuid?
     
  5. Offline

    mine-care

    Happy to help!
    No i actually mean the entity ID variable contained in the packet, as an int.
     
  6. Offline

    Corndogoz

    Ok, I have the ID, but have never had to listen for packets. Maybe some help, or links?
     
  7. Offline

    mine-care

  8. Offline

    Corndogoz

    Using this code:
    Code:
    public void registerListeners(){
            System.out.println("hi");
            protocolManager.addPacketListener(new PacketAdapter(this,ListenerPriority.NORMAL,PacketType.Play.Client.USE_ENTITY) {
            @Override
                public void onPacketReceiving(PacketEvent event) {
                    if (event.getPacketType() == PacketType.Play.Client.USE_ENTITY) {
                        PacketContainer packet = event.getPacket();
                        System.out.println(packet.getIntegers().read(0) + "");
                    }
                }
            });
        }
    I was able to check the entity id, however, by just normal clicking an entity, its clicked for so long, the message displays 4 times. Do you know how to stop that?
     
  9. Offline

    mine-care

    @Corndogoz the packet is received 4 times i supose :? You can add a per player cooldown of a few miliseconds, so if the next packet comes i.e. 10 miliseconds or less after the previous one, you dicard it. :p


    EDIT:
    Woo!!! I reached 4͈͈̘̘̣̔̊̿̆̾̃̊0̼͙̞̰̫̼̝̽̉͐̍̚0͚̞̹̙̗͕̆͑͐ͭͥͯ̌ͪ0̤͓̠̠͇̉̐ͦͬͪ̅̾t̤̺̟͓̰̪̲̗̫ͪͭ͌h̼͚͉̘̫̘ͧ͆͊̀̾͊͆ ̣̟͍̞̱̼͇̞̔̍͊ͅp̞̫͖̝̘͈̫͕ͩ̉ͣͧͪ̇ő̱̭̭̦̹̟̏̑ͪͬ̒̃s̻͇̭̟̏̃͐ͤͩ͒ͦ̆͂ͯṯ̠͔̩͎̜̯͈̏̄ͦ͆ͥͩ!̦͈̘̘͖͔̳̫̅̉̂̓ͣ̚!! :D


    -
     
    Last edited: Jul 27, 2016
  10. Offline

    Corndogoz

  11. Offline

    mine-care

    Glad it is solved!
    No worries ill have a look now, but may respond tomorrow as it is almost 3 am here xD
     
Thread Status:
Not open for further replies.

Share This Page