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

Solved Skip Certain Blocks With getHighestBlock

Discussion in 'Development' started by notdrewdev, May 14, 2019.

  1. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    39
    GitHub:
    drewsucksatlife
    I've been using getHighestBlock as methods to get the ground, but the maps I use have glass domes, which players spawn on. How can I skip the glass?
     
  2. mm899

    mm899 Spider Jockey

    Messages:
    32
    (This is probably very inconvenient) Uhhhh I think the world height is 256 so get players position in a variable. Run a loop which checks the players position but the the Y position starting from 256, until a block (which isn’t air, glass, water etc) keep taking away the Y by 1 till a valid block is found then return that block position
     
  3. mm899

    mm899 Spider Jockey

    Messages:
    32
    I hope you understand what I’m getting at considering I explained that terribly lool
     
  4. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    39
    GitHub:
    drewsucksatlife
    Code example? I've tried to make something like that and it ends up breaking @mm899
     
  5. mm899

    mm899 Spider Jockey

    Messages:
    32
    hmm
     
  6. mm899

    mm899 Spider Jockey

    Messages:
    32
    PHP:
    public function getCustomRoof(Player $player){
            
    $position $player->getPosition();

            
    $count 256;
            
    $check true;

            while(
    $check){
                
    $position->$count;
                
    $block $player->getLevel()->getBlock($position);
                if(
    $block->getId() != 20 && $block->getId() != 0){ //block isnt glass or air :p - add water/laval(stationary/flowing)
                    
    $check false;
                }
                else{
                    
    $count--;
                }
            }

            return 
    $position;
        }
    I haven't tested this, try this I guess....
     
    Last edited: May 15, 2019
  7. mm899

    mm899 Spider Jockey

    Messages:
    32
    Do let me know if it worked ;)
     
  8. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Don't hardcode block IDs. It's a terrible idea and it makes your code impossible to read.
     
  9. mm899

    mm899 Spider Jockey

    Messages:
    32
    Il bare that in mind thanks for the tip :)
     
    jasonwynn10 and Sandertv like this.
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    y=256 is one block outside the world, replace $count's value with (Level::Y_MAX - 1) or you could do something like
    PHP:
    $y Level::Y_MAX;
    while(--
    $y >= 0){
        
    $position->$y;
    }
     
  11. mm899

    mm899 Spider Jockey

    Messages:
    32
    I hadn’t realised the world height (last time I played was 1.11 when it was 128)
     
  12. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    39
    GitHub:
    drewsucksatlife
    I fixed the item ids and the $count value like what @Muqsit said, and it works fine, thanks!
     
    OnTheVerge and mm899 like this.
  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.