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

Solved Get item transfered from chest to player inventory

Comments in 'Plugin Development' started by wolfdale, Jul 9, 2015.

  1. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    How to get the item id or item name of the item which is transferred from chest to player inventory?
  2. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Use the "InventoryTransactionEvent" ;)
    ahoj_truhliku likes this.
  3. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    getTransaction() returns a TransactionGroup, but how to get the item from the TransactionGroup?
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    TransactionGroup->getTransactions()[n]->getTargetItem()
    wolfdale likes this.
  5. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    what value should n be?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    0, or foreach the array.
    wolfdale likes this.
  7. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Thank you very much!
    One more question. Is it possible to get the position of the chest where the transaction occurred?
    And maybe also the player object?
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Find out the transaction which has a ChestInventory item, and get the holder of the ChestInventory. The holder should be a pocketmine\tile\Chest object, which is an instance of Vector3.
    wolfdale likes this.
  9. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Sorry, im quite new to plugin making, could you show me how to do it by code?
  10. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Solved it myself, here is the code
    PHP:
    public function InventoryTransfer(InventoryTransactionEvent $event){
            
    $trans $event->getTransaction()->getTransactions();
            
    $inv $event->getTransaction()->getInventories();
            foreach(
    $trans as $t){
                foreach(
    $inv as $chest){
                    if (!(
    $chest instanceof ChestInventory)){
                        return;
                    }
                    
    $chest $chest->getHolder();
                    if(!(
    $chest instanceof Chest)){
                        return;
                    }
                    
    $x $chest->x;
                    
    $y $chest->y;
                    
    $z $chest->z;
                    
    $l $chest->getBlock()->getLevel()->getName();               
                   
                
    $i $t->getTargetItem();
                
    $i2 $t->getSourceItem();
                if (
    $i->getId() === 0){
                    
    $i $i2;
                }
                
    $n $i->getName();
                
    $d $i->getDamage();
                
    $c $i->getCount();
                
    var_dump($n.":".$d." ".$c." at ".$x." ".$y." ".$z." ".$l);
                }
            }
        }

    Is it possible to get the player who initiated the transaction?
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    There is a participating inventory called PlayerInventory. The holder is the player.
    wolfdale likes this.
  12. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Thank you!
  13. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    When I do if($chest instanceof PlayerInventory){
    $this->player = $chest->getHolder();
    }
    It says that player is null, any way to bypass it?
  14. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    403
    Plugins:
    2
    Bumping thread!
  15. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    And whats the problem?
  16. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    403
    Plugins:
    2
    If you want to ask some question, you should make a new thread for that, because the problem in this thread already solved few months ago
  17. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    But it takes long to define this problem
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then link to this thread. Only reply to an old thread when you want to provide additional information or correct some serious mistakes.
    Vaivez66 likes this.

Share This Page

Advertisement