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

is there a function to see if player's inventory is full?

Discussion in 'Help' started by Levi, Oct 10, 2017.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    is there a function to see if player's inventory is full?
     
  2. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    Maybe you can do it this way:
    PHP:
    $empty $inventory->firstEmpty();
    if(
    $empty === -1){
    //Inventory is full
    }else{
    //$empty is the first slot which is empty
    }
    Notice: I havent tested it
     
    Levi likes this.
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    That will fail is the player's inventory is filled with... let's say steak (x64) but one of the slots has steak (x1).

    But most importantly, why do you want to check if the player's inventory is full?
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    so there is something to warn them that their inventory is full and their mining won't be a waste if their inventory is full
     
  5. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    is there a fix to it?
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You can use canAddItem() where $item is the item you want to add. That function will check for item count and do all the required math.
    PHP:
    if($player->getInventory()->canAddItem($item)){
        
    //not full
    }else{
        
    //full
    }
     
    famima65536 likes 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.