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

Solved getDirection with x and z?

Comments in 'Plugin Development' started by Legoboy0215, Dec 8, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    How would I know if I should add x or z from getDirection? Or other functions? I am trying to setBlock every air block in front of your face :)
    CraftYourBukkit likes this.
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    replace Player:: with the player.
    do you mean
    PHP:
    Player::getLevel()->setBlock(new Vector3(Player::getX()+1Player::getY()+1Player::getZ()));
    AndrewBit likes this.
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Did you even read my post? x and z is different. What if his x is on his sides?
    hoyinm14mc likes this.
  4. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    getDirection returns int 0-3
    0 = South(+x)
    1 = West(+z)
    2 = North(-x)
    3 = East(-z)
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    How would I do it in a blocks perspective? I have a block (dirt) and want to set 2 blocks towards the player looking at it.
  6. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Something like this?
    PHP:
        $x $player->x;
        
    $y $player->y;
        
    $z $player->z;
        switch(
    $player->getDirection()){
            case 
    0$x += 2; break;
            case 
    1$z += 2; break;
            case 
    2$x -= 2; break;
            case 
    3$z -= 2; break;
        }
        
    $level->setBlock(new Vector3($x,$y,$z),Block::get(0));
    AndrewBit likes this.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    But I want in a blocks perspective? So I want when a player is looking at a 2 block high pillar, the pillar extends (setBlock) towards the player.
  8. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Maybe you mean
    PHP:
    $x $player->x;
    $y $player->y;
    $z $player->z;
    switch(
    $player->getDirection()){
    case 
    0$x -= 1; break;
    case 
    1$z -= 1; break;
    case 
    2$x += 1; break;
    case 
    3$z += 1; break;
    }
    $blocks $player->getLineOfSight($distance);
    foreach(
    $blocks as $b)
    $level->setBlock(new Vector3($x,$y,$z),Block::get(1));
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    What does getLineOfSight do? And $b is useless :p
  10. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    It gets the blocks the player is looking at. And returns array of blocks so i just foreach it :p
    Legoboy0215 likes this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder

Share This Page

Advertisement