swimming tweaks, fall damage tweaks

This commit is contained in:
GameHerobrine 2023-02-23 20:07:02 +03:00
parent 6b68b88572
commit db8b221c02
5 changed files with 34 additions and 4 deletions

View file

@ -568,6 +568,10 @@ class Entity extends Position
$y1 = ceil($aABB->maxY);
$z0 = floor($aABB->minZ);
$z1 = ceil($aABB->maxZ);
$ywMin = floor($aABB->minY + 0.4);
$ywMax = ceil($aABB->maxY - 0.4);
$x0 = $x0 < 0 ? 0 : $x0;
$y0 = $y0 < 0 ? 0 : $y0;
$z0 = $z0 < 0 ? 0 : $z0;
@ -579,8 +583,9 @@ class Entity extends Position
for($z = $z0; $z < $z1; ++$z){
$pos = new Vector3($x, $y, $z);
$b = $this->level->getBlock($pos);
if($b->y == ($y1 - 1) && ($b->getID() === WATER || $b->getID() === STILL_WATER)){
$water = true;
if(($b->getID() === WATER || $b->getID() === STILL_WATER)){
$water = $b->y == ($y1 - 1);
$this->fallDistance = 0;
}
if($b != false && $b->isSolid){
$this->speedY = $b->boundingBox->calculateYOffset($this->boundingBox, $this->speedY);
@ -729,7 +734,6 @@ class Entity extends Position
$this->needsUpdate = $hasUpdate;
$this->lastUpdate = $now;
}
public function fall(){}
public function updateFallState($fallTick){

View file

@ -39,6 +39,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
$this->ai->updateTasks();
}
$this->ai->mobController->rotateTick();
$this->ai->mobController->movementTick();
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);

View file

@ -9,11 +9,21 @@ class MobController
public $finalYaw, $finalPitch, $finalHeadYaw;
protected $jumping;
protected $jumpTimeout;
public function __construct($e){
$this->entity = $e;
}
public function isJumping(){
return $this->jumping;
}
public function setJumping($b){
$this->jumping = $b;
}
public function moveNonInstant($x, $y, $z){
if($x == 0 && $y == 0 && $z == 0){
return false;
@ -47,6 +57,15 @@ class MobController
return true;
}
public function movementTick(){
if($this->isJumping() && $this->jumpTimeout <= 0){
$this->jumpTimeout = 10;
$this->entity->speedY = 0.42;
}
if($this->jumpTimeout > 0) --$this->jumpTimeout;
}
public function rotateTick(){ //TODO handle more rotation
$w180 = Utils::wrapAngleTo180($this->finalHeadYaw - $this->entity->headYaw);
$w180min = min(abs($w180), 20)*Utils::getSign($w180);

View file

@ -16,10 +16,12 @@ class TaskSwimming extends TaskBase
{
if(!$ai->entity->inWater){
$this->reset();
$ai->mobController->setJumping(false);
return;
}
if(Utils::randomFloat() < 0.8){ #1.5.2 method
$ai->entity->speedY = 0.42;
$ai->mobController->setJumping(true);
}

View file

@ -18,4 +18,8 @@ class LiquidBlock extends TransparentBlock{
public function getDrops(Item $item, Player $player){
return array();
}
public function getLiquidHeight(){ //TODO lava,water meta
return (($this->meta >= 8 ? 0 : $this->meta)+1) / 9;
}
}