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

Inventory menu problem

Discussion in 'Development' started by ivanRU, Sep 10, 2017.

  1. ivanRU

    ivanRU Creeper

    Messages:
    5
    Hi, I apologize in advance for my English.
    I'm trying to make inventory menu, here's code:

    PHP:
        public function createChest(Player $player, array $itemsint $idstring $title$double false)
        {
            
    $this->clearData($player);

            
    $this->inv[$player->getName()] = $player->getInventory()->getContents();

            
    $v3 $this->getVector($player);
            
    $this->chest[$player->getName()] = [$id$v3];
            
    $this->updateBlock($player54$v3);

            
    $nbt = new NBT(NBT::LITTLE_ENDIAN);
            if (
    $double) {
                
    $this->chest[$player->getName()][2] = true;
                
    $this->updateBlock($player54, new Vector3($v3->1$v3->y$v3->z));
                
    $nbt->setData(new CompoundTag(
                    
    "", [
                        new 
    StringTag("CustomName"$title),
                        new 
    IntTag("pairx"$v3->1),
                        new 
    IntTag("pairz"$v3->z)
                    ]
                ));
            } else {
                
    $nbt->setData(new CompoundTag(
                    
    "", [
                        new 
    StringTag("CustomName"$title)
                    ]
                ));
            }
            
    $pk = new BlockEntityDataPacket();
            
    $pk->$v3->x;
            
    $pk->$v3->y;
            
    $pk->$v3->z;
            
    $pk->namedtag $nbt->write(true);

            
    $pk1 = new ContainerOpenPacket();
            
    $pk1->windowid 10;
            
    $pk1->type 0;
            
    $pk1->$v3->x;
            
    $pk1->$v3->y;
            
    $pk1->$v3->z;

            
    $pk2 = new ContainerSetContentPacket();
            
    $pk2->windowid 10;
            
    $pk2->slots $items;

            
    $player->dataPacket($pk);
            
    $player->dataPacket($pk1);
            
    $player->dataPacket($pk2);
        }
    But when I create a double chest can sometimes be a problem: first opening 27-slot chest and immediately closes, then if I repeat this code again works. If you do a little sleep() after sending BlockEntityDataPacket, then everything will work. How to make immediately opened a double chest without sleep()?
    Thank you.
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yeah you will need to delay sending ContainerOpenPacket by 0.25s (5 ticks). Aside from that, are you aware about the consequences of using pure packets to handle inventory transactions? You will end up having many bugs if you don't handle the transactions properly.
     
  3. ivanRU

    ivanRU Creeper

    Messages:
    5
    Ok, how can i make this delay not using sleep()?..
     
  4. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Task
     
    Teamblocket 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.