Hi! My name is ZenixPlayzMC. So I have this error when i create a entity on a world. The world and its chunks is fully loaded though. This is the error: Code: [11:52:33] [Server thread/CRITICAL]: InvalidStateException "Cannot create entities in unloaded chunks" (EXCEPTION) in "src/pocketmine/entity/Entity" at line 561 This is the code on creating the entity: PHP: $entity = Entity::createEntity("Zombie", $player->getLevel(), $nbt); $entity->setMaxHealth(500); $entity->setHealth(500); $entity->setScale(1); $entity->getArmorInventory()->setHelmet(Item::get(310,0,1)); $entity->getArmorInventory()->setChestplate(Item::get(311,0,1)); $entity->getArmorInventory()->setLeggings(Item::get(312,0,1)); $entity->getArmorInventory()->setBoots(Item::get(313,0,1)); $entity->setNameTag(c::LIGHT_PURPLE . c::BOLD . "Test Boss" . "\n" . c::AQUA . "HP " . c::GRAY . $entity->getHealth() . c::GREEN . "/" . c::GRAY . $entity->getMaxHealth()); $entity->spawnToAll();
Are you sure the chunk at whatever position you put in $nbt is loaded? It does not seem to be Can you show your $nbt?
Sorry for late reply. This is my $nbt: PHP: $nbt = new CompoundTag("", [ "Pos" => new ListTag("Pos", [ new DoubleTag("", $block->x), new DoubleTag("", $block->y + 2), new DoubleTag("", $block->z) ]), "Motion" => new ListTag("Motion", [ new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0) ]), "Rotation" => new ListTag("Rotation", [ new FloatTag("", mt_rand() / mt_getrandmax() * 360), new FloatTag("", 0) ]), ]);
Just to make sure that the chunk is loaded you can add this before Entity::createEntity PHP: $player->getLevel()->loadChunk($block->x >> 4,$block->z >> 4);
It probably isnt spawning at where you expect it to be, judging by the chunks not being loaded previously How did you define $block? Is it near the player?
you should create NBT from the function createBaseNBT which should be called on child classes PHP: $nbt = Zombie::createBaseNBT($block->add(0, 2));
literally just paste the code, and see if it has changed or not, it seems like you're interacting with a block in a chunk that has not loaded yet
where should i paste it? So i should replace this code: PHP: $nbt = new CompoundTag("", [ "Pos" => new ListTag("Pos", [ new DoubleTag("", $block->x), new DoubleTag("", $block->y + 2), new DoubleTag("", $block->z) ]), "Motion" => new ListTag("Motion", [ new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0) ]), "Rotation" => new ListTag("Rotation", [ new FloatTag("", mt_rand() / mt_getrandmax() * 360), new FloatTag("", 0) ]), ]); with: PHP: $nbt = Zombie::createBaseNBT($block->add(0, 2));