mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
ai changes
This commit is contained in:
parent
4835c15747
commit
5a3aeecd93
9 changed files with 196 additions and 98 deletions
37
src/entity/ai/MobController.php
Normal file
37
src/entity/ai/MobController.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
class MobController
|
||||
{
|
||||
/**
|
||||
* @var Entity
|
||||
*/
|
||||
public $entity;
|
||||
|
||||
public function __construct($e){
|
||||
$this->entity = $e;
|
||||
}
|
||||
|
||||
public function moveNonInstant($x, $y, $z){
|
||||
if($x === $this->entity->x && $y === $this->entity->y && $z === $this->entity->z){
|
||||
return false; //failed
|
||||
}
|
||||
$this->entity->moveEntityWithOffset(($x > 0 ? 1 : ($x < 0 ? -1 : 0)), ($y > 0 ? 1 : ($y < 0 ? -1 : 0)), ($z > 0 ? 1 : ($z < 0 ? -1 : 0)));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function lookAt($x, $y = 0, $z = 0){
|
||||
if($x instanceof Entity){
|
||||
return $this->lookAt($x->x, $x->y, $x->z);
|
||||
}
|
||||
$this->entity->yaw = -atan2($x, $z) * 180 / M_PI;
|
||||
$this->entity->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt(pow($x, 2) + pow($z, 2))));
|
||||
$this->entity->server->query("UPDATE entities SET pitch = ".$this->entity->pitch.", yaw = ".$this->entity->yaw." WHERE EID = ".$this->entity->eid.";");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function __destruct(){
|
||||
unset($this->entity);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue