mobs should swim now

This commit is contained in:
GameHerobrine 2023-01-17 20:29:19 +03:00
parent c2e069ef08
commit 6f54da56ba
3 changed files with 39 additions and 5 deletions

View file

@ -16,8 +16,7 @@ abstract class Creature extends Living{
$this->ai->addTask(new TaskLookAround());
$this->ai->addTask(new TaskRandomWalk());
$this->ai->addTask(new TaskLookAtPlayer());
$this->ai->addTask(new TaskSwimming());
}
public function createSaveData(){

View file

@ -72,7 +72,7 @@ class Entity extends Position
public $inAction = false;
public $hasKnockback;
public $onGround;
public $onGround, $inWater;
function __construct(Level $level, $eid, $class, $type = 0, $data = array())
{
@ -558,7 +558,7 @@ class Entity extends Position
if(Utils::in_range($this->speedY, -0.007, 0.007)){
$this->speedY = 0;
}
$this->inWater = false;
if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT)){
$aABB = $this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ);
$x0 = floor($aABB->minX);
@ -594,6 +594,7 @@ class Entity extends Position
$this->air -= 1;
$waterDone = true;
$this->updateMetadata();
$this->inWater = true;
$hasUpdate = true;
}
break;
@ -646,7 +647,7 @@ class Entity extends Position
}
if($this->speedX != 0){
$this->x += $this->speedX;
$this->speedX -= $this->speedX * $drag;

View file

@ -0,0 +1,34 @@
<?php
class TaskSwimming extends TaskBase
{
public function onStart(EntityAI $ai)
{
$this->selfCounter = 1;
}
public function onEnd(EntityAI $ai)
{
}
public function onUpdate(EntityAI $ai)
{
if(!$ai->entity->inWater){
$this->reset();
}
if(Utils::randomFloat() < 0.8){ #1.5.2 method
$ai->entity->speedY = 0.42;
}
}
public function canBeExecuted(EntityAI $ai)
{
return $ai->entity->inWater;
}
}