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

Solved How to auto pickup items?

Discussion in 'Development' started by pxline, Feb 4, 2018.

  1. pxline

    pxline Creeper

    Messages:
    1
    Hey there. I'm trying to create an auto pickup plugin. That means if you break a block it doesn't drop but get's into your inventory. I'm working with the BlockBreakEvent.
     
  2. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    i think something like this onBreak, get the item in the event, and add to inventory, if inv is full, do nothing, and send player Make some more space!
     
    Diduhless likes this.
  3. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    PHP:
    public function onBreak(BlockBreakEvent $event) {
        
    $event->setDrops();
        
    $event->getPlayer()->getInventory->addItem(Item::get($event->getBlock()->getId()));
    }
    Tell me if it worked
     
    Last edited: Feb 13, 2018
  4. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    even better,
    PHP:
    public function onBreak(BlockBreakEvent $event) {
        foreach(
    $event->getDrops() as $drops) {
            
    $event->getPlayer()->getInventory()->addItem($drops);
        }
        
    $event->setDrops();
    }
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    But what if the player's inventory is full?

    Maybe this:
    PHP:
    //Make sure the priority is set to high and ignoreCancelled=true
    public function onBlockBreak(BlockBreakEvent $event) : void{
        
    $event->setDrops($event->getPlayer()->getInventory()->addItem(...$event->getDrops()));
    }
     
    Last edited: Feb 4, 2018
    xXNiceAssassinlo YT 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.