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), $chestBlock, true, true); $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); } }
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.
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.
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;
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.