Inheritance: extends Creature, implements pocketmine\entity\Ageable
Ejemplo n.º 1
0
 public function spawnToAll()
 {
     parent::spawnToAll();
     if ($this->getLevel()->getServer()->lightningFire) {
         $fire = ItemItem::get(ItemItem::FIRE)->getBlock();
         $oldBlock = $this->getLevel()->getBlock($this);
         if ($oldBlock instanceof Liquid) {
         } elseif ($oldBlock->isSolid()) {
             $v3 = new Vector3($this->x, $this->y + 1, $this->z);
         } else {
             $v3 = new Vector3($this->x, $this->y, $this->z);
         }
         if (isset($v3)) {
             $this->getLevel()->setBlock($v3, $fire);
         }
         foreach ($this->level->getNearbyEntities($this->boundingBox->grow(4, 3, 4), $this) as $entity) {
             if ($entity instanceof Player) {
                 $damage = mt_rand(8, 20);
                 $ev = new EntityDamageByEntityEvent($this, $entity, EntityDamageByEntityEvent::CAUSE_LIGHTNING, $damage);
                 if ($entity->attack($ev->getFinalDamage(), $ev) === true) {
                     $ev->useArmors();
                 }
                 $entity->setOnFire(mt_rand(3, 8));
             }
             if ($entity instanceof Creeper) {
                 $entity->setPowered(true, $this);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function spawnTo(Player $player)
 {
     $pk = $this->addEntityDataPacket($player);
     $pk->type = Mooshroom::NETWORK_ID;
     $player->dataPacket($pk);
     parent::spawnTo($player);
 }
Ejemplo n.º 3
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = Wolf::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->speedX = $this->motionX;
     $pk->speedY = $this->motionY;
     $pk->speedZ = $this->motionZ;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = $this->dataProperties;
     $player->dataPacket($pk);
     parent::spawnTo($player);
 }
Ejemplo n.º 4
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = Pig::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->speedX = $this->motionX;
     $pk->speedY = $this->motionY;
     $pk->speedZ = $this->motionZ;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = $this->dataProperties;
     $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
     parent::spawnTo($player);
 }
Ejemplo n.º 5
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = self::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->speedX = $this->motionX;
     $pk->speedY = 1.5;
     $pk->speedZ = $this->motionZ;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = [Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $this->getDataProperty(2)], Entity::DATA_SHOW_NAMETAG => [Entity::DATA_TYPE_BYTE, 1], Entity::DATA_NO_AI => [Entity::DATA_TYPE_BYTE, 1]];
     $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
     parent::spawnTo($player);
 }
Ejemplo n.º 6
0
 public function knockBack(Entity $attacker, $damage, $x, $z, $base = 0.4)
 {
     parent::knockBack($attacker, $damage, $x, $z, $base);
     $this->knockback = time() + 1;
     // Stunned for 1 second...
 }
Ejemplo n.º 7
0
 public function onUpdate($currentTick)
 {
     $hasUpdate = false;
     $this->timings->startTiming();
     // Handle flying objects...
     $tickDiff = max(1, $currentTick - $this->lastUpdate);
     $bb = clone $this->getBoundingBox();
     $onGround = count($this->level->getCollisionBlocks($bb->offset(0, -$this->gravity, 0))) > 0;
     if (!$onGround) {
         // falling or jumping...
         $this->motionY -= $this->gravity;
         $this->x += $this->motionX * $tickDiff;
         $this->y += $this->motionY * $tickDiff;
         $this->z += $this->motionZ * $tickDiff;
         //echo ("Falling...\n");
     } else {
         $this->motionX = 0;
         // No longer jumping/falling
         $this->motionY = 0;
         $this->motionZ = 0;
         if ($this->y != floor($this->y)) {
             $this->y = floor($this->y);
         }
         // Try to attack a player
         $target = null;
         if ($this->petOwner->player) {
             $target = $this->petOwner->player;
             if ($target) {
                 if ($target->getLevel() != $this->level) {
                     // Pet is in a different level...
                     $target = null;
                 } else {
                     $dist = $this->distance($target);
                 }
             }
         }
         // if no target despawn
         if ($target === null) {
             $this->close();
             return;
         }
         if ($target !== null && $dist != 0) {
             $dir = $target->getLevel()->getSafeSpawn($target)->subtract($this);
             $dir = $dir->divide($dist);
             $this->yaw = rad2deg(atan2(-$dir->getX(), $dir->getZ()));
             $this->pitch = rad2deg(atan(-$dir->getY()));
             // if dist to owner < move dist or pet is being told to stay just look at owner
             if ($dist <= self::$dist || $this->isSitting) {
                 //$this->yaw = rad2deg(atan2(-$dir->getX(),$dir->getZ()));
                 //$this->pitch = rad2deg(atan(-$dir->getY()));
                 $this->updateMovement();
                 $this->level->addEntityMovement($this->chunk->getX(), $this->chunk->getZ(), $this->id, $this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->yaw);
             }
             // otherwise do a full movement
             if ($dist > self::$dist && !$this->isSitting) {
                 $x = $dir->getX() * self::$speed;
                 $y = 0;
                 $z = $dir->getZ() * self::$speed;
                 $isJump = count($this->level->getCollisionBlocks($bb->offset($x, 1.2, $z))) <= 0;
                 if (count($this->level->getCollisionBlocks($bb->offset(0, 0.1, $z))) > 0) {
                     if ($isJump) {
                         $y = self::$jump;
                         $this->motionZ = $z;
                     }
                     $z = 0;
                 }
                 if (count($this->level->getCollisionBlocks($bb->offset($x, 0.1, 0))) > 0) {
                     if ($isJump) {
                         $y = self::$jump;
                         $this->motionX = $x;
                     }
                     $x = 0;
                 }
                 //if ($y) echo "Jumping\n";
                 $ev = new \pocketmine\event\entity\EntityMotionEvent($this, new \pocketmine\math\Vector3($x, $y, $z));
                 $this->server->getPluginManager()->callEvent($ev);
                 if ($ev->isCancelled()) {
                     return false;
                 }
                 $this->x += $x;
                 $this->y += $y;
                 $this->z += $z;
             }
             if ($dist > 40) {
                 $target->sendMessage($this->petName_unformatted . " could not keep up - use /pet spawn again to bring them back");
                 $this->close();
             }
         }
     }
     $bb = clone $this->getBoundingBox();
     $onGround = count($this->level->getCollisionBlocks($bb->offset(0, -$this->gravity, 0))) > 0;
     $this->onGround = $onGround;
     $this->timings->stopTiming();
     $hasUpdate = parent::onUpdate($currentTick) || $hasUpdate;
     return $hasUpdate;
 }