This commit is contained in:
GameHerobrine 2023-01-06 00:59:30 +03:00
parent 60c8603c8b
commit d0ec32dc02
5 changed files with 22 additions and 16 deletions

View file

@ -5,7 +5,9 @@ class Entity extends Position
const TYPE = - 1; const TYPE = - 1;
const CLASS_TYPE = - 1; const CLASS_TYPE = - 1;
public $counter = 0;
public static $updateOnTick, $allowedAI; public static $updateOnTick, $allowedAI;
public $isCollidable; public $isCollidable;
public $canBeAttacked; public $canBeAttacked;
@ -487,7 +489,6 @@ class Entity extends Position
return; return;
} }
$tdiff = $now - $this->lastUpdate; $tdiff = $now - $this->lastUpdate;
if($this->tickCounter === 0){ if($this->tickCounter === 0){
$this->tickCounter = 1; $this->tickCounter = 1;
$hasUpdate = $this->environmentUpdate(); $hasUpdate = $this->environmentUpdate();
@ -499,7 +500,7 @@ class Entity extends Position
if($this->closed === true){ if($this->closed === true){
return false; return false;
} }
++$this->counter;
if($this->isStatic === false){ if($this->isStatic === false){
$startX = floor($this->x - 0.5 - $this->width - 1); $startX = floor($this->x - 0.5 - $this->width - 1);
// prefix for flying when player on fence // prefix for flying when player on fence
@ -510,6 +511,7 @@ class Entity extends Position
$endZ = ceil($this->z - 0.5 + $this->width + 1); $endZ = ceil($this->z - 0.5 + $this->width + 1);
$support = false; $support = false;
$isFlying = true; $isFlying = true;
if($this->isPlayer()){ if($this->isPlayer()){
for($z = $startZ; $z <= $endZ; ++ $z){ for($z = $startZ; $z <= $endZ; ++ $z){
for($x = $startX; $x <= $endX; ++ $x){ for($x = $startX; $x <= $endX; ++ $x){
@ -569,9 +571,9 @@ class Entity extends Position
$y1 = $y1 > 128 ? 128 : $y1; $y1 = $y1 > 128 ? 128 : $y1;
$z1 = $z1 > 256 ? 256 : $z1; $z1 = $z1 > 256 ? 256 : $z1;
$waterDone = false; $waterDone = false;
for($x = $x0; $x < $x1; ++ $x){ for($x = $x0 - 1; $x < $x1 + 1; ++ $x){
for($y = $y0; $y < $y1; ++ $y){ for($y = $y0; $y < $y1; ++ $y){
for($z = $z0; $z < $z1; ++ $z){ for($z = $z0 - 1; $z < $z1 + 1; ++ $z){
$pos = new Vector3($x, $y, $z); $pos = new Vector3($x, $y, $z);
$b = $this->level->getBlock($pos); $b = $this->level->getBlock($pos);
switch($b->getID()) { switch($b->getID()) {
@ -623,7 +625,7 @@ class Entity extends Position
} }
break; break;
} }
if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid && $this->isMoving()){ if($this->isMoving() && $b != false && $b->isSolid && $b->boundingBox->intersectsWith($aABB)){
$this->speedX = $b->boundingBox->calculateXOffset($this->boundingBox, $this->speedX); $this->speedX = $b->boundingBox->calculateXOffset($this->boundingBox, $this->speedX);
$this->speedZ = $b->boundingBox->calculateZOffset($this->boundingBox, $this->speedZ); $this->speedZ = $b->boundingBox->calculateZOffset($this->boundingBox, $this->speedZ);
$lastY = $this->speedY; $lastY = $this->speedY;
@ -721,9 +723,9 @@ class Entity extends Position
// $this->speedZ = 0; // $this->speedZ = 0;
$this->server->api->handle("entity.move", $this); $this->server->api->handle("entity.move", $this);
$update = true; $update = true;
}elseif($this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch){ }elseif ($this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch) {
$update = true; $update = true;
} }
if($update === true){ if($update === true){
$hasUpdate = true; $hasUpdate = true;

View file

@ -42,4 +42,11 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
parent::update(); parent::update();
} }
public function sendMoveUpdate(){
if($this->counter % 3 != 0){
return;
}
parent::sendMoveUpdate();
}
} }

View file

@ -18,8 +18,6 @@ class EntityAI
public $lastTask; public $lastTask;
public $counter = 0;
public function __construct($entity){ public function __construct($entity){
$this->entity = $entity; $this->entity = $entity;
$this->tasks = []; $this->tasks = [];
@ -49,9 +47,6 @@ class EntityAI
} }
public function updateTasks(){ public function updateTasks(){
if($this->counter % 3 != 0){
return;
}
foreach($this->tasks as $t){ foreach($this->tasks as $t){
if(!$t->isStarted && $t->canBeExecuted($this)){ if(!$t->isStarted && $t->canBeExecuted($this)){
$t->isStarted = true; $t->isStarted = true;

View file

@ -34,7 +34,7 @@ class MobController
$dz = $d->z; $dz = $d->z;
$tan = $dz == 0 ? ($dx < 0 ? 180 : 0) : (90 - rad2deg($dx / $dz)); $tan = $dz == 0 ? ($dx < 0 ? 180 : 0) : (90 - rad2deg($dx / $dz));
$thetaOffset = $dz < 0 ? 90 : 270; $thetaOffset = $dz <= 0 ? 90 : 270;
$this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan); $this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan);
} }

View file

@ -34,6 +34,7 @@ class TaskLookAtPlayer extends TaskBase{
$this->target = $this->findTarget($ai->entity, 6); //TODO max distance for different mobs $this->target = $this->findTarget($ai->entity, 6); //TODO max distance for different mobs
if(!($this->target instanceof Entity) || !$this->target->isPlayer()){ if(!($this->target instanceof Entity) || !$this->target->isPlayer()){
$this->reset(); $this->reset();
$this->onEnd($ai);
return; return;
} }
$this->yaw = $ai->entity->yaw; $this->yaw = $ai->entity->yaw;
@ -44,12 +45,13 @@ class TaskLookAtPlayer extends TaskBase{
public function onUpdate(EntityAI $ai){ public function onUpdate(EntityAI $ai){
if(!($this->target instanceof Entity) || Utils::distance($ai->entity, $this->target) > 6 || $this->target->level->getName() != $ai->entity->level->getName()){ //TODO max distance for different mobs if(!($this->target instanceof Entity) || Utils::distance($ai->entity, $this->target) > 6 || $this->target->level->getName() != $ai->entity->level->getName()){ //TODO max distance for different mobs
$this->reset(); $this->reset();
$this->onEnd($ai);
return; return;
} }
$ai->mobController->lookOn($this->target); $ai->mobController->lookOn($this->target);
$this->selfCounter--; $this->selfCounter--;
} }
public function onEnd(EntityAI $ai){ public function onEnd(EntityAI $ai){
unset($this->target); unset($this->target);
$ai->entity->pitch = 0; $ai->entity->pitch = 0;