mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 20:19:44 +00:00
fixed bug with flying detection, added panic task
This commit is contained in:
parent
7c47c852e2
commit
d7561ed1ba
10 changed files with 70 additions and 17 deletions
41
src/entity/ai/tasks/TaskPanic.php
Normal file
41
src/entity/ai/tasks/TaskPanic.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
class TaskPanic extends TaskBase
|
||||
{
|
||||
protected $randX = 2, $randZ = 2;
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = mt_rand(60, 120);
|
||||
$this->regenerateRandXZ();
|
||||
}
|
||||
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$ai->entity->inPanic = false;
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
public function regenerateRandXZ(){
|
||||
$this->randX = (mt_rand(0, 1) ? -1 : 1) * 2;
|
||||
$this->randZ = (mt_rand(0, 1) ? -1 : 1) * 2;
|
||||
}
|
||||
|
||||
public function reset(){
|
||||
$this->randX = $this->randZ = 2;
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
--$this->selfCounter;
|
||||
if($this->selfCounter % 20 === 0) $this->regenerateRandXZ();
|
||||
$ai->mobController->moveNonInstant($this->randX, 0, $this->randZ);
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
return $ai->entity instanceof Animal && $ai->entity->inPanic && $ai->entity->knockbackTime <= 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue