mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 04:29:43 +00:00
added entity collision, new entity sorting system
This commit is contained in:
parent
db8b221c02
commit
79831c457d
2 changed files with 81 additions and 0 deletions
|
|
@ -34,12 +34,38 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
|
|||
unset($this->ai->entity);
|
||||
}
|
||||
|
||||
public function collideHandler(){
|
||||
$this->level->applyCallbackToNearbyEntities($this, [$this, "applyCollision"], 2); //TODO radiuses
|
||||
}
|
||||
|
||||
public function applyCollision(Entity $collided){
|
||||
if($collided->boundingBox->intersectsWith($this->boundingBox) && !($this->isPlayer() && $collided->isPlayer()) && $this->eid != $collided->eid){
|
||||
$diffX = $collided->x - $this->x;
|
||||
$diffZ = $collided->z - $this->z;
|
||||
$maxDiff = max(abs($diffX), abs($diffZ));
|
||||
if($maxDiff > 0.01){
|
||||
$sqrtMax = sqrt($maxDiff);
|
||||
$diffX /= $sqrtMax;
|
||||
$diffZ /= $sqrtMax;
|
||||
|
||||
$col = (($v = 1 / $sqrtMax) > 1 ? 1 : $v);
|
||||
$diffX *= $col;
|
||||
$diffZ *= $col;
|
||||
$diffX *= 0.05;
|
||||
$diffZ *= 0.05;
|
||||
$this->addVelocity(-$diffX, 0, -$diffZ);
|
||||
$collided->addVelocity($diffX, 0, $diffZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function update(){
|
||||
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
|
||||
$this->ai->updateTasks();
|
||||
}
|
||||
$this->ai->mobController->rotateTick();
|
||||
$this->ai->mobController->movementTick();
|
||||
$this->collideHandler();
|
||||
if($this->onGround){
|
||||
//if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
|
||||
// $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue