mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
entity ai classes, pigs should look around
This commit is contained in:
parent
6f603fcbe9
commit
8d454e5ec9
12 changed files with 206 additions and 38 deletions
47
src/entity/ai/tasks/TaskLookAround.php
Normal file
47
src/entity/ai/tasks/TaskLookAround.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
class TaskLookAround extends TaskBase
|
||||
{
|
||||
private $finYaw = 0;
|
||||
public function shouldBeExecuted(EntityAI $ai)
|
||||
{
|
||||
return !$ai->entity->isMoving() && $ai->entity->lookTime <= 0 && mt_rand(0,30) == 1 && $ai->entity->idleTime <= 0;
|
||||
}
|
||||
|
||||
public function wasExecuted(EntityAI $ai){
|
||||
|
||||
return $ai->entity->lookTime > 0;
|
||||
}
|
||||
|
||||
public function onStart(EntityAI $ai){
|
||||
$ai->entity->lookTime = 120;
|
||||
$this->finYaw = $ai->entity->yaw;
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
//90 - 75 = -45deg rot
|
||||
//60 - 30 = 90deg rot
|
||||
//30 - 15 = -45deg rot
|
||||
if($ai->entity->lookTime === 1){
|
||||
$ai->entity->idleTime = mt_rand(40, 200);
|
||||
}
|
||||
if(Utils::in_range($ai->entity->lookTime, 105, 120) || Utils::in_range($ai->entity->lookTime, 15, 30)){
|
||||
$ai->entity->yaw -= 3;
|
||||
}
|
||||
if(Utils::in_range($ai->entity->lookTime, 50, 80)){
|
||||
$ai->entity->yaw += 3;
|
||||
}
|
||||
|
||||
$pk = new RotateHeadPacket();
|
||||
$pk->eid = $ai->entity->eid;
|
||||
$pk->yaw = $ai->entity->yaw;
|
||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
|
||||
}
|
||||
public function testLook($pos){
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue