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

Solved [PMMP 4.9.0] When changing current window it won't open and block player inventory opening.

Discussion in 'Development' started by BloodyJohnRus, Oct 10, 2022.

  1. BloodyJohnRus

    BloodyJohnRus Silverfish

    Messages:
    19
    GitHub:
    GDSHNIK
    Hello!

    Problem:
    Created DoubleChestInventory, changed window to this inventory. No chest window, and player inventory won't opening. Even if i tap on chest it wont open.
    But if i don't change window, i can easily open chest by tapping on him.
    Here's an code:
    PHP:
           $x intval($p->getX());
           
    $y intval($p->getY()+2);
           
    $z intval($p->getZ());
           
    $p->getWorld()->setBlockAt($x-1,$y,$z,VanillaBlocks::CHEST());
           
    $p->getWorld()->setBlockAt($x,$y,$z,VanillaBlocks::CHEST());
           
    /** @var Chest */
           
    $tile1 $p->getWorld()->getTileAt($x,$y,$z);
           
    $tile1->setName($name);
           
    /** @var Chest */
           
    $tile2 $p->getWorld()->getTileAt($x-1,$y,$z);
           
    $tile2->setName($name);
           
    $p->getWorld()->addTile($tile1);
           
    $p->getWorld()->addTile($tile2);
           
    $chest1 = new ChestInventory(new Position($x-1,$y,$z,$p->getWorld()));
           
    $chest2 = new ChestInventory(new Position($x,$y,$z,$p->getWorld()));
           
    $chest = new DoubleChestInventory($chest1,$chest2);
           
    $ev = new ChestPairEvent($p->getWorld()->getBlockAt($x-1,$y,$z),$p->getWorld()->getBlockAt($x,$y,$z));
           
    $ev->call();
           
    $tile1->pairWith($tile2);
           
    $tile2->pairWith($tile1);
           
    $i 0;
           
    /** @var null|Chest */
           
    $tile $p->getWorld()->getTileAt($x,$y,$z);
           
    $cf $this->chestItemFunctions;
           
    $cfa $this->chestItemFunctionArgs;
           
    $cf = [$name => []];
           
    $cff = [];
           foreach(
    $items as $item){
               
    $tile->getInventory()->addItem($item);
               
    array_push($cf[$name],$functions[$i]);
               
    $cfa[$i] = $functionArgs[$i];
               
    $i++;
           }
          
    // $cf = [$name => $cff];
           
    $this->chestItemFunctionArgs=$cfa;
           
    $this->chestItemFunctions=$cf;
           foreach(
    $this->chestItemFunctions as $cff$this->getLogger()->info(key($cf));
           if(
    $pl != null) {
               
    /*
               $im = $pl->getNetworkSession()->getInvManager();
               $im->onCurrentWindowRemove();
               $im->onCurrentWindowChange($chest);
               $im->syncAll();
               */
               
    $pl->setCurrentWindow($chest);
           }
    Even tried through $tile->getInventory() and getRealInventory(), nothing worked.
    No errors in log.
     
    Primus likes this.
  2. BloodyJohnRus

    BloodyJohnRus Silverfish

    Messages:
    19
    GitHub:
    GDSHNIK
    Nevermind, solved it by adding delayed task.
     
    Primus 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.