Solved Get player you are looking at

Discussion in 'Plugin Development' started by MinecraftMart, Jun 18, 2014.

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

    MinecraftMart

    Does someone know a method to get the player you are looking at? Ive searched around but couldnt find anything.
     
  2. You could check the bukkit source code at the endermen on how they check if you look at them. You can then just use something relative to that but with players.
     
  3. Offline

    MinecraftMart

    Bram0101

    Nothing found on that. Its not implemented in the Bukkit API, there has to be a way but i just dont know how.
     
  4. The bukkit api on github is confusing. Sometimes you need to go to the craftbukkit project, and take a look in the packages net.minecraft.server
     
  5. Offline

    cs475x

    MinecraftMart net.minecraft.server.EntityEnderman.java:
    Code:java
    1. protected Entity findTarget() {
    2. EntityHuman entityhuman = this.world.findNearbyVulnerablePlayer(this, 64.0D);
    3.  
    4. if (entityhuman != null) {
    5. if (this.f(entityhuman)) {
    6. this.bv = true;
    7. if (this.bt == 0) {
    8. this.world.makeSound(entityhuman.locX, entityhuman.locY, entityhuman.locZ, "mob.endermen.stare", 1.0F, 1.0F);
    9. }
    10.  
    11. if (this.bt++ == 5) {
    12. this.bt = 0;
    13. this.a(true);
    14. return entityhuman;
    15. }
    16. } else {
    17. this.bt = 0;
    18. }
    19. }
    20.  
    21. return null;
    22. }
    23.  
    24. private boolean f(EntityHuman entityhuman) {
    25. ItemStack itemstack = entityhuman.inventory.armor[3];
    26.  
    27. if (itemstack != null && itemstack.getItem() == Item.getItemOf(Blocks.PUMPKIN)) {
    28. return false;
    29. } else {
    30. Vec3D vec3d = entityhuman.j(1.0F).a();
    31. Vec3D vec3d1 = this.world.getVec3DPool().create(this.locX - entityhuman.locX, this.boundingBox.b + (double) (this.length / 2.0F) - (entityhuman.locY + (double) entityhuman.getHeadHeight()), this.locZ - entityhuman.locZ);
    32. double d0 = vec3d1.b();
    33.  
    34. vec3d1 = vec3d1.a();
    35. double d1 = vec3d.b(vec3d1);
    36.  
    37. return d1 > 1.0D - 0.025D / d0 ? entityhuman.o(this) : false;
    38. }
    39. }
     
  6. Offline

    thepaperboy99

  7. Offline

    MinecraftMart

    Okay thx, but it doesnt show me how to get the player i am looking at :/

    Does nobody really know this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page