setMaxHealth(10); parent::initEntity(); } public function getName() : string{ return "Squid"; } public function attack(EntityDamageEvent $source){ parent::attack($source); if($source->isCancelled()){ return; } if($source instanceof EntityDamageByEntityEvent){ $this->swimSpeed = mt_rand(150, 350) / 2000; $e = $source->getDamager(); if($e !== null){ $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); } $pk = new EntityEventPacket(); $pk->entityRuntimeId = $this->getId(); $pk->event = EntityEventPacket::SQUID_INK_CLOUD; $this->server->broadcastPacket($this->hasSpawned, $pk); } } private function generateRandomDirection() : Vector3{ return new Vector3(mt_rand(-1000, 1000) / 1000, mt_rand(-500, 500) / 1000, mt_rand(-1000, 1000) / 1000); } public function entityBaseTick(int $tickDiff = 1) : bool{ if($this->closed !== false){ return false; } if(++$this->switchDirectionTicker === 100 or $this->isCollided){ $this->switchDirectionTicker = 0; if(mt_rand(0, 100) < 50){ $this->swimDirection = null; } } $hasUpdate = parent::entityBaseTick($tickDiff); if($this->isAlive()){ if($this->y > 62 and $this->swimDirection !== null){ $this->swimDirection->y = -0.5; } $inWater = $this->isInsideOfWater(); if(!$inWater){ $this->swimDirection = null; }elseif($this->swimDirection !== null){ if($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2 <= $this->swimDirection->lengthSquared()){ $this->motionX = $this->swimDirection->x * $this->swimSpeed; $this->motionY = $this->swimDirection->y * $this->swimSpeed; $this->motionZ = $this->swimDirection->z * $this->swimSpeed; } }else{ $this->swimDirection = $this->generateRandomDirection(); $this->swimSpeed = mt_rand(50, 100) / 2000; } $f = sqrt(($this->motionX ** 2) + ($this->motionZ ** 2)); $this->yaw = (-atan2($this->motionX, $this->motionZ) * 180 / M_PI); $this->pitch = (-atan2($f, $this->motionY) * 180 / M_PI); } return $hasUpdate; } protected function applyGravity(){ if(!$this->isInsideOfWater()){ parent::applyGravity(); } } public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->entityRuntimeId = $this->getId(); $pk->type = Squid::NETWORK_ID; $pk->position = $this->asVector3(); $pk->motion = $this->getMotion(); $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->metadata = $this->dataProperties; $player->dataPacket($pk); parent::spawnTo($player); } public function getDrops() : array{ return [ ItemFactory::get(ItemItem::DYE, 0, mt_rand(1, 3)) ]; } }