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

Spawn Chest crash ?

Discussion in 'Development' started by ItzAribie, Nov 4, 2017.

  1. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
    Hello, when i click on the entity a chest spawn and when the chest is spawned i get a chunk bug and i crash what problem can caused her please ?

    PHP:
        public function openJob(Player $p)
        {

           
    $x $p->getFloorX();
           
    $y $p->getFloorY()-4;
           
    $z $p->getFloorZ();

           
    $chestBlock Block::get(Block::CHEST);
           
    $p->getLevel()->setBlock(new Vector3($x$y$z), $chestBlocktruetrue);
           
    $p->getLevel()->loadChunk($x >> 4$z >> 4);

            
    $tile Tile::createTile('Chest'$p->getLevel(), new CompoundTag('', [
                new 
    StringTag('id'Tile::CHEST),       
                new 
    IntTag('x'$x),
                new 
    IntTag('y'$y),
                new 
    IntTag('z'$z)
            ]));



            if(
    $tile instanceof Chest){
     

                
    $inv $tile->getInventory();
                
    $inv->clearAll();

                
    $inv->setContents($this->contents['items']);

                
    $p->addWindow($inv);
           }
        }
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Remove loadChunk()
     
    LewBr likes this.
  3. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
    No, it's not going to change anything.
     
  4. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Be patient. If others want to help you, they would do so without you pinging them. You're just spamming the thread by bumping it.
     
    Muqsit, jasonwynn10 and HimbeersaftLP like this.
  6. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    I think he is right, try removing that.
     
  7. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I tested your code without loadChunk() and it is working perfectly so....
     
  8. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Maybe it's problem of your client... Slow device or something...
     
  9. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
    No doesnt work if you have tested please give me a screen.
     
  10. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    upload_2017-11-7_20-5-34.png
    Here you go! :D
     
  11. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Can you show us your imports?
    instanceof doesn't throw any exceptions if the class doesn't exist, I'm assuming that's where the problem exists.
     
  13. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
    PHP:
    use pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\inventory\ChestInventory;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Player;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\inventory\PlayerInventory;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\tile\Tile;
    use 
    pocketmine\tile\Chest;
    use 
    pocketmine\nbt\tag\CompoundTag;
    use 
    pocketmine\nbt\tag\ListTag;
    use 
    pocketmine\nbt\tag\StringTag;
    use 
    pocketmine\nbt\tag\IntTag;
    use 
    pocketmine\nbt\NBT;
     
  14. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
    Login timeout I received...
     
  15. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You need need to clean the code up a bit.

    Level::setBlock() indirectly calls Level::loadChunk(), so you're calling Level::loadChunk() twice.

    Tile::createTile('Chest'...) will always return an instance of pocketmine\tile\Chest unless a plugin has overridden it, which is highly unlikely.
    So, if($tile instanceof Chest) is unneeded.

    Oh and you said you get a chunk bug when you call that function, you forgot to post the chunk bug you were facing.
     
  16. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
    Look the var_dump https://ibb.co/c92c2b
     
  17. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    umm can you directly post it here, I kinda do not want to visit that link
    cc.JPG
     
  18. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    idk where your problem with that site lies, but here:
    [​IMG]
     
  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.