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

put an item to the hand

Comments in 'Plugin Development' started by udwarf, Aug 15, 2016.

  1. udwarf
    Offline

    udwarf Active Member

    Joined:
    Apr 17, 2016
    Posts:
    61
    Minecraft User:
    1Zaza
    Hello, guys!
    I stuck out of the blue on the one very simple task.
    I want to give to the player an item to the hand.
    Sounds very simply to me and i did something like
    PHP:
            $ii $player->getInventory();
            
    $ii->clearAll();
            
    $fc Item::get(Item::DIAMOND);
            
    $ii->setItem(0$fc);
            
    $ii->setHeldItemIndex(0);
            
    $ii->setHeldItemSlot(0);
    But that doesn work! Item appear in the inventory, first slot in the Hotbar is selected but it's empty! So nothing in the hand!
    Just for test i've added such code right after clearAll:
    PHP:
            for ($i=0;$i<$ii->getSize(); $i++){
                
    $z Item::get(Item::GRASS);
                
    $z->setCount($i+1);
                
    $ii->setItem($i$z);
            }
            for (
    $i=0;$i<$ii->getHotbarSize();$i++) {
                
    $ii->setHotbarSlotIndex($i,$i);
            }
    Now inventory is full with Grass-blocks. And I was hoping that the hotbar will also be filled with grass blocks (from 1 to 9)
    No way! The Hotbar was still empty!
    Next attempt - I've added to the very end
    PHP:
            $ii->sendHeldItem($player);
    Nothing changed!
    That I've added
    PHP:
            $ii->sendContents($player);
    and voila! Everything looks fine! Hotbar is filled, item in the hand

    LOL. Looks like I've solved the issue while was writing this post.
    Remaining question:
    So, do I always have to call sendContents after inventory changes?
  2. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Sounds like a PocketMine bug that has existed since a very long time ago...
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You've researched whole PocketMine github? o_O

Share This Page

Advertisement