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

Mobs spawning

Discussion in 'Development' started by FIRERO, Dec 24, 2016.

  1. FIRERO

    FIRERO Spider

    Messages:
    6
    Hi, guys! I have a problem with the mobs spawning. My code you can see
    PHP:
            public function createVillager($x$y$zLevel $level){
            
    $x += 0.5;
            
    $z += 0.5;

            
    $nbt = new CompoundTag;
            
    $nbt->Pos = new ListTag("Pos", [
                new 
    DoubleTag(""$x),
                new 
    DoubleTag(""$y),
                new 
    DoubleTag(""$z)
            ]);

            
    $nbt->Rotation = new ListTag("Rotation", [
                new 
    FloatTag(""0),
                new 
    FloatTag(""0)
            ]);

            
    $nbt->Health = new ShortTag("Health"20);
            
    $nbt->CustomName = new StringTag("CustomName""§3Эдвард §7- §eКвестер");
            
    $nbt->CustomNameVisible = new ByteTag("CustomNameVisible"1);

            
    $level->loadChunk($x >> 4$z >> 4);

            
    $villager Entity::createEntity("Villager"$level->getChunk($x >> 4$y >> 4), $nbt);
            
    $villager->spawnToAll();
            }
    So, there is a
    PHP:
    [23:05:39] [Server thread/CRITICAL]: ▒еоб▒або▒анное и▒кл▒▒ение п▒и в▒полнении команд▒ 'vc' в vcArgument 2 passed to pocketmine\entity\Entity::createEntity() must implement interface pocketmine\level\format\FullChunknull givencalled in /root/test/plugins/aQuest/src/AlexBrin/aQuest.php on line 153

    [23:05:39] [Server thread/CRITICAL]: TypeError"Argument 2 passed to pocketmine\entity\Entity::createEntity() must implement interface pocketmine\level\format\FullChunk, null given, called in /root/test/plugins/Mob/src/FIRERO/main_file.php on line 153" (EXCEPTIONin "/src/pocketmine/entity/Entity" at line 554
    in the console
    PHP:
    $villager Entity::createEntity("Villager"$level->getChunk($x >> 4$y >> 4), $nbt);
    PHP:
    public static function createEntity($typeFullChunk $chunkCompoundTag $nbt, ...$args){
     
  2. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  3. FIRERO

    FIRERO Spider

    Messages:
    6
    PHP:
    <?php

        
    namespace FIRERO;
        use 
    pocketmine\plugin\PluginBase;
        use 
    pocketmine\command\Command;
        use 
    pocketmine\command\CommandSender;
        use 
    pocketmine\command\CommandExecutor;

        use 
    pocketmine\entity\Entity;
        use 
    pocketmine\level\Level;
        use 
    pocketmine\level\Position;
        use 
    pocketmine\math\Vector3;
        use 
    pocketmine\nbt\NBT;
        use 
    pocketmine\nbt\tag\ByteTag;
        use 
    pocketmine\nbt\tag\CompoundTag;
        use 
    pocketmine\nbt\tag\DoubleTag;
        use 
    pocketmine\nbt\tag\FloatTag;
        use 
    pocketmine\nbt\tag\IntTag;
        use 
    pocketmine\nbt\tag\ListTag;
        use 
    pocketmine\nbt\tag\ShortTag;
        use 
    pocketmine\nbt\tag\StringTag;
        use 
    pocketmine\entity\Villager;


        use 
    pocketmine\event\Listener;

        use 
    pocketmine\Player;
        use 
    pocketmine\Server;

        class 
    main_file extends PluginBase implements Listener {



            public function 
    onCommand(CommandSender $senderCommand $command$label, array $args) {
                if(
    $sender instanceof Player) {
                    if(
    $command == "vc"){
                        
    $this->createVillager($sender->getX(), $sender->getY(), $sender->getZ(), $this->getServer()->getLevelByName("lobby"));
                    }
                } else 
    $sender->sendMessage('§cOnly for players!');
            }
           
           
            public function 
    createVillager($x$y$zLevel $level){
            
    $x += 0.5;
            
    $z += 0.5;

            
    $nbt = new CompoundTag;
            
    $nbt->Pos = new ListTag("Pos", [
                new 
    DoubleTag(""$x),
                new 
    DoubleTag(""$y),
                new 
    DoubleTag(""$z)
            ]);

            
    $nbt->Rotation = new ListTag("Rotation", [
                new 
    FloatTag(""0),
                new 
    FloatTag(""0)
            ]);

            
    $nbt->Health = new ShortTag("Health"20);
            
    $nbt->CustomName = new StringTag("CustomName""§3Эдвард §7- §eКвестер");
            
    $nbt->CustomNameVisible = new ByteTag("CustomNameVisible"1);

            
    $level->loadChunk($x >> 4$z >> 4);

            
    $villager Entity::createEntity("Villager"$level->getChunk($x >> 4$y >> 4), $nbt);
            
    $villager->spawnToAll();
            }
        }

    ?>
     
    Last edited: Dec 24, 2016
  4. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    i think you forgot to put use
    pocketmine\level\format\FullChunk;
     
  5. JackboyPlay

    JackboyPlay Spider

    Messages:
    11
    GitHub:
    JackboyPlay
    Why ist there a $y??
    PHP:
            $villager Entity::createEntity("Villager"$level->getChunk($x >> 4$y >> 4), $nbt);  
     
  6. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Its checking the x/y position
     
  7. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Because it isn't a parameter in the Level::getChunks() function.
     
  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.