Jump to content

getEntitiesOnCursor doesn't find all entities


Hybris

Recommended Posts

Hey,

For some reason when I use mouse.getEntitiesOnCursor it only gives me one, even though the count says 2.c0985ac0b61234469a52d5a6e82fa409.png

The second entity is an NPC & I'm sure the mouse is placed right on the entity.
Any ideas?

Thanks in advance,
Hybris


P.S.: How would I accurately spam click an NPC? npc.interact() seems to move the mouse every time it clicks and mouse.click() can easily fail.

Link to comment
Share on other sites

How are you looping through the list to print the entitys?

For spam clicking an npc you can grab their bounding box and check if the mouse is within that than, just use mouse.click() else move the mouse to the npc.

Or you can try the hover() method instead of grabbing the bounding box. It might move the mouse though even if its already hovering, kinda like the interact() method. Haven't tested.

 

This wont work well with moving npcs.

NPC npc = getNpcs().closest("Banker");
boolean isMouseOverNPC = (npc != null) && npc.getModel().getBoundingBox(
        npc.getGridX(), npc.getGridY(), npc.getZ()).contains(getMouse().getPosition());
if (isMouseOverNPC)
    getMouse().click(false);
else if (npc != null)
    npc.hover();
Edited by BravoTaco
Link to comment
Share on other sites

25 minutes ago, BravoTaco said:

How are you looping through the list to print the entitys?

For spam clicking an npc you can grab their bounding box and check if the mouse is within that than, just use mouse.click() else move the mouse to the npc.

Or you can try the hover() method instead of grabbing the bounding box. It might move the mouse though even if its already hovering, kinda like the interact() method. Haven't tested.

 

This wont work well with moving npcs.


NPC npc = getNpcs().closest("Banker");
boolean isMouseOverNPC = (npc != null) && npc.getModel().getBoundingBox(
        npc.getGridX(), npc.getGridY(), npc.getZ()).contains(getMouse().getPosition());
if (isMouseOverNPC)
    getMouse().click(false);
else if (npc != null)
    npc.hover();

I'm not looping through the list, just printing the list object.

As for the spam clicking, I'm currently using the hover method which works, but sometimes the NPC is behind a door & it will click the door instead.

 

19 minutes ago, memelord123 said:

if (getMouse().isOnCursor(yourNpcHere)) {

    getMouse().click(false);

}

 

As long as your mouse is on the npc, the mouse will left click and not move.


I tried that but for some reason the "isOnCursor(npc)" method returns false even though the cursor is on my entity.
 

Link to comment
Share on other sites

14 minutes ago, Hybris said:

I'm not looping through the list, just printing the list object.

As for the spam clicking, I'm currently using the hover method which works, but sometimes the NPC is behind a door & it will click the door instead.
 

Aaaah to see each item inside the list you will have to loop through it and print each element.

You might have to check if there is more than one entity in the list, if their is than use the interact() method to interact, if not than you can just left click normally.

You can also move the camera instead if an entity in the list is not the same position as the NPC, as this would imply that the only reason the other entity is in the list is because of camera position and not because two entitys are stacked.

Edited by BravoTaco
  • Like 1
Link to comment
Share on other sites

17 minutes ago, BravoTaco said:

Aaaah to see each item inside the list you will have to loop through it and print each element.

You might have to check if there is more than one entity in the list, if their is than use the interact() method to interact, if not than you can just left click normally.

You can also move the camera instead if an entity in the list is not the same position as the NPC, as this would imply that the only reason the other entity is in the list is because of camera position and not because two entitys are stacked.

I'm pretty sure you can print a list & see all the elements 😛 But I tried it with looping through each of them and it still gives me the same, it will only show the Player entity even when the "mouse.getOnCursorCount()" shows 2...

Link to comment
Share on other sites

43 minutes ago, Hybris said:

I tried that but for some reason the "isOnCursor(npc)" method returns false even though the cursor is on my entity.
 

I'm assuming that's happening when 2 entities are on the same tile?

If so, this would work to spam click in the same spot unless another entity appears on the same tile in which case the mouse would interact with your npc by left clicking (where possible) otherwise right clicking.

 

if (getMouse().isOnCursor(yourNpcHere))

{

    if (getMouse().getOnCursorCount() < 2)

    {

         getMouse().click(false);

    }

    else

    {

        yourNpcHere.interact();

    }

}

Link to comment
Share on other sites

If your problem is with NPC.interact() failing then don’t you think the Mouse API might fail too?

NPC npc = getNpcs.closest(“name”);

if(npc != null) {

    If(npc.interact(“Bank”)) {

        // sleep until the bank interface is open

    } else {

        // handle the failure

}

Wouldnt it be easier with interacting with the specific NPC option like above? Code might not be exact, I wrote that off the top of my head.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...