Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Distance on a chest

Comments in 'Plugin Development' started by Ritch, Jul 18, 2016.

  1. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    how to find the distance between the player and the chest ? Up to 100 meter ?
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    I would compare two Vector3 distances.
    PHP:
    // $block is the Chest block object.
    // $player is the Player object.
    $v1 = new Vector3($block->getX(), $block->getY(), $block->getZ());
    $v2 $player->getPosition();
    $v1->distance($v2); //should return the chest's distance from the player.
    Vaivez66 and Ritch like this.
  3. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    Thank You so much solved
    I add $player->sendMessage("".round($v1,0)."");
    HotFireyDeath likes this.
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    The "" . "" aren't needed.
    Ritch likes this.
  5. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Simply do
    PHP:
     $player->sendMessage (round ($v1,0)); 
  6. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    I know xD :)
  7. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    i use task $block = what ? sorry
  8. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    If you really want to convert to string, just use (string). But it really isn't needed.
    The coordinates of the chest block you want, represented by an object of type Vector3. Can also be of type Block. However, from your wording in the OP, it seems like you just want to hardcode the coordinates with new Vector3(...).
  9. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    No... Round $v1->distance($v2), not $v1 itself! $v1 is an object, not a scalar!
    Ritch, HotFireyDeath and jojoe77777 like this.
  10. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    Ok @PEMapModder :D
  11. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    HotFireyDeath likes this.
  12. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    You could simply do
    PHP:
    $v = new Vector3($block->x$block->y$block->z);
    $v->distance($player);
    because the Player class is instanceof Vector3.
    Ritch and Survingo like this.
  13. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    You could simply do
    PHP:
    $block->distance($player)
    // OR //
    $player->distance($v)
    Obviously $block is also a Vector3.

Share This Page

Advertisement