40 public static function getNetworkTypeId() :
string{
return EntityIds::SQUID; }
42 public ?
Vector3 $swimDirection =
null;
43 public float $swimSpeed = 0.1;
45 private int $switchDirectionTicker = 0;
49 public function initEntity(
CompoundTag $nbt) :
void{
50 $this->setMaxHealth(10);
51 parent::initEntity($nbt);
54 public function getName() :
string{
59 parent::attack($source);
65 $this->swimSpeed = mt_rand(150, 350) / 2000;
66 $e = $source->getDamager();
68 $this->swimDirection = $this->location->subtractVector($e->location)->normalize();
75 private function generateRandomDirection() :
Vector3{
76 return new Vector3(mt_rand(-1000, 1000) / 1000, mt_rand(-500, 500) / 1000, mt_rand(-1000, 1000) / 1000);
79 protected function entityBaseTick(
int $tickDiff = 1) :
bool{
84 if(++$this->switchDirectionTicker === 100){
85 $this->switchDirectionTicker = 0;
86 if(mt_rand(0, 100) < 50){
87 $this->swimDirection =
null;
91 $hasUpdate = parent::entityBaseTick($tickDiff);
95 if($this->location->y > 62 && $this->swimDirection !==
null){
96 $this->swimDirection = $this->swimDirection->withComponents(
null, -0.5,
null);
99 $inWater = $this->isUnderwater();
100 $this->setHasGravity(!$inWater);
102 $this->swimDirection =
null;
103 }elseif($this->swimDirection !==
null){
104 if($this->motion->lengthSquared() <= $this->swimDirection->lengthSquared()){
105 $this->motion = $this->swimDirection->multiply($this->swimSpeed);
108 $this->swimDirection = $this->generateRandomDirection();
109 $this->swimSpeed = mt_rand(50, 100) / 2000;
112 $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2));
114 -atan2($this->motion->x, $this->motion->z) * 180 / M_PI,
115 -atan2($f, $this->motion->y) * 180 / M_PI