setMaxHealth(10); parent::initEntity($nbt); } public function getName() : string{ return "Squid"; } public function attack(EntityDamageEvent $source) : void{ 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 = $this->location->subtractVector($e->location)->normalize(); } $this->broadcastAnimation(new SquidInkCloudAnimation($this)); } } private function generateRandomDirection() : Vector3{ return new Vector3(mt_rand(-1000, 1000) / 1000, mt_rand(-500, 500) / 1000, mt_rand(-1000, 1000) / 1000); } protected function entityBaseTick(int $tickDiff = 1) : bool{ if($this->closed){ return false; } if(++$this->switchDirectionTicker === 100){ $this->switchDirectionTicker = 0; if(mt_rand(0, 100) < 50){ $this->swimDirection = null; } } $hasUpdate = parent::entityBaseTick($tickDiff); if($this->isAlive()){ if($this->location->y > 62 and $this->swimDirection !== null){ $this->swimDirection = $this->swimDirection->withComponents(null, -0.5, null); } $inWater = $this->isUnderwater(); $this->setHasGravity(!$inWater); if(!$inWater){ $this->swimDirection = null; }elseif($this->swimDirection !== null){ if($this->motion->lengthSquared() <= $this->swimDirection->lengthSquared()){ $this->motion = $this->swimDirection->multiply($this->swimSpeed); } }else{ $this->swimDirection = $this->generateRandomDirection(); $this->swimSpeed = mt_rand(50, 100) / 2000; } $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); $this->location->yaw = (-atan2($this->motion->x, $this->motion->z) * 180 / M_PI); $this->location->pitch = (-atan2($f, $this->motion->y) * 180 / M_PI); } return $hasUpdate; } public function getDrops() : array{ return [ VanillaItems::INK_SAC()->setCount(mt_rand(1, 3)) ]; } }