1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Get block under

Discussion in 'Development' started by Kyd, Oct 14, 2018.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    How to detect when player walk on stairs, slabs?
    I used
    PHP:
    /** @var Player $player */
    $player->getLevel()->getBlock(new \pocketmine\math\Vector3($player->x$player->0.5$player->z))->getId());
    but it's not efficient because it does not detect stairs when you start standing on them, or even slabs & fences.
    Is there any better way?
     
  2. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    PHP:
    /** @var Player $player */
    $block $player->getLevel()->getBlock(new \pocketmine\math\Vector3($player->getX(), $player->getY() - 0.5$player->getZ()));
    if(
    $block instanceof \pocketmine\block\Slab){
        
    //code
    }
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    You don't understand my question, when I use your code it does not detect when I start walking on stairs, slabs, it detect one block before until you are not fully on the stair,slab
     
  4. Darku

    Darku Spider Jockey

    Messages:
    49
    GitHub:
    DarkWav
    You might want to work with arrays here...
    You can check multiple blocks arround the player, not just one if that solves you problem.
     
    Sandertv likes this.
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    floor(), intval() or round() the x, the y and the z.

    EDIT: floor() returns float, so use intval() or round().
     
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Check if the player is collided, then check what the player is collided with. Entity::getBlocksAround() should return the blocks you're looking for, then compare each to the coordinate where the slab is expected to be.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.