ported 1.5.2 way of mob movement but broke everything else

This commit is contained in:
GameHerobrine 2024-01-09 06:44:19 +03:00
parent 8684e3092a
commit 5161d087ba
5 changed files with 169 additions and 93 deletions

View file

@ -3,10 +3,14 @@
abstract class Living extends Entity implements Pathfindable{
public static $despawnMobs, $despawnTimer, $entityPushing = false;
public $moveStrafing, $moveForward;
public $target, $ai;
public $pathFinder, $path = null, $currentIndex = 0, $currentNode, $pathFollower;
public $ticksExisted = 0;
public $landMovementFactor = 0.1; //TODO may not be constant
public $jumpMovementFactor = 0.02; //TODO may not be constant
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
$this->target = false;
$this->ai = new EntityAI($this);
@ -99,15 +103,77 @@ abstract class Living extends Entity implements Pathfindable{
$this->ai->mobController->rotateTick();
$this->ai->mobController->movementTick();
if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0;
if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0;
if(abs($this->speedY) < self::MIN_POSSIBLE_SPEED) $this->speedY = 0;
$this->moveStrafing *= 0.98;
$this->moveForward *= 0.98;
$savedLandFactor = $this->landMovementFactor;
$this->landMovementFactor *= $this->getSpeedModifer();
$this->moveEntityWithHeading($this->moveStrafing, $this->moveForward);
$this->landMovementFactor = $savedLandFactor;
if(self::$entityPushing){
$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);
//}
//$this->pathFollower->followPath();
}
public function moveEntityWithHeading($strafe, $forward){
//TODO lava, water
//If not in lava in water ->
{
$friction = 0.91;
if($this->onGround){
$friction = 0.546;
$blockAt = $this->level->level->getBlockID(floor($this->x), floor($this->boundingBox->minY) - 1, floor($this->z));
if($blockAt > 0) $friction = StaticBlock::getSlipperiness($blockAt) * 0.91;
}
$var8 = 0.16277136 / ($friction*$friction*$friction);
if($this->onGround){
//TODO if AIEnabled
{
//TODO $var5 = getAIMoveSpeed
}
//else
{
$var5 = $this->landMovementFactor;
}
$var5 *= $var8;
}else{
$var5 = $this->jumpMovementFactor;
}
$this->moveFlying($strafe, $forward, $var5);
//1.5.2 recalculates friction, might be not neccessary
$friction = 0.91;
if($this->onGround){
$friction = 0.546;
$blockAt = $this->level->level->getBlockID(floor($this->x), floor($this->boundingBox->minY) - 1, floor($this->z));
if($blockAt > 0) $friction = StaticBlock::getSlipperiness($blockAt) * 0.91;
}
//TODO onLadder
console($this->speedY);
$this->move($this->speedX, $this->speedY, $this->speedZ);
//TODO onLadder + isCollidedHorizonatlly => speedY = 0.2
$this->speedY -= 0.08; //gravity
$this->speedY *= 0.98;
$this->speedX *= $friction;
$this->speedZ *= $friction;
}
//TODO limbYaw - is it even needed?
}
public function sendMoveUpdate(){