fixed more tasks

This commit is contained in:
GameHerobrine 2024-01-09 10:18:22 +03:00
parent bcf7ef7c79
commit 2636aa985d
15 changed files with 64 additions and 20 deletions

View file

@ -84,6 +84,8 @@ class Entity extends Position
public $stepHeight = 0.5;
public $enableAutojump = false;
public $yOffset = 0.0;
public $noClip = false;
function __construct(Level $level, $eid, $class, $type = 0, $data = array())
{
$this->random = new Random();
@ -552,7 +554,7 @@ class Entity extends Position
$this->boundingBox->offset($dx, $dy, $dz);
$fallingFlag = $this->onGround || $savedDY != $dy && $savedDY < 0;
if($this->stepHeight > 0 && $fallingFlag && /*($this->ySize < 0.05) && TODO ySuze*/ ($savedDX != $dx || $savedDZ != $dz)){
if($this->stepHeight > 0 && $fallingFlag && ($savedDX != $dx || $savedDZ != $dz)){
$cx = $dx;
$cy = $dy;
$cz = $dz;
@ -600,7 +602,7 @@ class Entity extends Position
//TODO step
$this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2;
$this->y = $this->boundingBox->minY; //TODO + $this->yOffset - //TODO $this->ySize;
$this->y = $this->boundingBox->minY + $this->yOffset;// - //TODO - used when player is sneaking $this->ySize;
$this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2;
//$this.isCollidedHorizontally = savedDX != dx || savedDZ != dz;
//$this.isCollidedVertically = savedDY != dy;

View file

@ -36,8 +36,11 @@ abstract class Living extends Entity implements Pathfindable{
return $this->aiMoveSpeed;
}
public function getVerticalFaceSpeed(){
return 40; //unused in 0.8 but may be useful in 0.9/0.10
}
public function setAIMoveSpeed($speed){
console("set spedd to $speed");
$this->aiMoveSpeed = $speed;
$this->moveForward = $speed;
}
@ -182,7 +185,6 @@ abstract class Living extends Entity implements Pathfindable{
}
//TODO onLadder
console($this->speedY);
$this->move($this->speedX, $this->speedY, $this->speedZ);
//TODO onLadder + isCollidedHorizonatlly => speedY = 0.2

View file

@ -26,6 +26,9 @@ class MobController
public $moveToX, $moveToY, $moveToZ;
public $speed;
public $updateMove = false;
public $lookX, $lookY, $lookZ;
public $deltaLookYaw, $deltaLookPitch;
public $isLooking = false;
@ -132,7 +135,17 @@ class MobController
$this->entity->pitch = 0;
if($this->isLooking){
$this->isLooking = false;
//TODO
$diffX = $this->lookX - $this->entity->x;
$diffY = $this->lookY - ($this->entity->y + $this->entity->getEyeHeight());
$diffZ = $this->lookZ - $this->entity->z;
$distance = sqrt($diffX*$diffX + $diffZ*$diffZ);
$v9 = (atan2($diffZ, $diffX)*180 / M_PI) - 90;
$v10 = -(atan2($diffY, $distance)*180 / M_PI);
$this->entity->pitch = self::limitAngle($this->entity->pitch, $v10, $this->deltaLookPitch);
$this->entity->headYaw = self::limitAngle($this->entity->headYaw, $v9, $this->deltaLookYaw);
}else{
$this->entity->headYaw = self::limitAngle($this->entity->headYaw, $this->entity->renderYawOffset, 10);
}
@ -160,8 +173,13 @@ class MobController
//$this->entity->headYaw = Utils::wrapAngleTo360($this->entity->headYaw + $w180min);
}
public function moveTo($x, $y, $z, $camera = true){
//TODO fix return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z), $camera);
public function setLookPosition($posX, $posY, $posZ, $lookYaw, $lookPitch){
$this->lookX = $posX;
$this->lookY = $posY;
$this->lookZ = $posZ;
$this->deltaLookYaw = $lookYaw;
$this->deltaLookPitch = $lookPitch;
$this->isLooking = true;
}
public function faceEntity($x, $y, $z){

View file

@ -2,7 +2,11 @@
class TaskLookAtPlayer extends TaskBase{
public $target = false;
private $state, $yaw, $pitch;
public $distance;
public function __construct($distance){
$this->distance = $distance;
}
public function canBeExecuted(EntityAI $ai){
return !$ai->entity->inPanic && lcg_value() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->isStarted("TaskPanic") && !$ai->entity->hasPath();
}
@ -37,14 +41,13 @@ class TaskLookAtPlayer extends TaskBase{
}
public function onStart(EntityAI $ai){
$this->target = $this->findTarget($ai->entity, 6); //TODO max distance for different mobs
$this->target = $this->findTarget($ai->entity, $this->distance);
if(!($this->target instanceof Entity) || !$this->target->isPlayer()){
$this->reset();
$this->onEnd($ai);
return;
}
$this->yaw = $ai->entity->yaw;
$this->pitch = $ai->entity->pitch;
$this->selfCounter = mt_rand(20, 60);
}
@ -54,6 +57,7 @@ class TaskLookAtPlayer extends TaskBase{
$this->onEnd($ai);
return;
}
$ai->mobController->setLookPosition($this->target->x, $this->target->y + $this->target->getEyeHeight(), $this->target->z, 10, $ai->entity->getVerticalFaceSpeed());
$ai->mobController->lookOn($this->target);
$this->selfCounter--;
}

View file

@ -3,6 +3,12 @@
class TaskPanic extends TaskBase
{
protected $randX = 2, $randZ = 2;
public $moveSpeed;
public function __construct($moveSpeed){
$this->moveSpeed = $moveSpeed;
}
public function onStart(EntityAI $ai)
{
$this->selfCounter = 60;
@ -16,8 +22,8 @@ class TaskPanic extends TaskBase
}
public function regenerateRandXZ(){
$this->randX = (mt_rand(0, 1) ? -1 : 1) * 2;
$this->randZ = (mt_rand(0, 1) ? -1 : 1) * 2;
$this->randX = (mt_rand(0, 1) ? -1 : 1);
$this->randZ = (mt_rand(0, 1) ? -1 : 1);
}
public function reset(){
@ -28,7 +34,7 @@ class TaskPanic extends TaskBase
{
--$this->selfCounter;
if($this->selfCounter % 20 === 0) $this->regenerateRandXZ();
//TODO fix $ai->mobController->moveNonInstant($this->randX, 0, $this->randZ);
$ai->mobController->setMovingOffset($this->randX, 0, $this->randZ, $this->moveSpeed);
}
public function canBeExecuted(EntityAI $ai)

View file

@ -37,11 +37,10 @@ class TaskRandomWalk extends TaskBase
public function canBeExecuted(EntityAI $ai)
{
return true;
//if(($ai->entity instanceof Creeper && $ai->entity->isIgnited()) || $ai->entity->hasPath() || $ai->isStarted("TaskTempt") ||$ai->isStarted("TaskAttackPlayer")) {
// return false;
//} // i really need mutexBits
//return !$ai->entity->inPanic && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskEatTileGoal") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
if(($ai->entity instanceof Creeper && $ai->entity->isIgnited()) || $ai->entity->hasPath() || $ai->isStarted("TaskTempt") ||$ai->isStarted("TaskAttackPlayer")) {
return false;
} // i really need mutexBits
return !$ai->entity->inPanic && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskEatTileGoal") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
}

View file

@ -12,6 +12,8 @@ class Chicken extends Animal{
$this->setSpeed(0.25);
$this->ai->addTask(new TaskRandomWalk(0.25));
$this->ai->addTask(new TaskLookAtPlayer(6));
$this->ai->addTask(new TaskPanic(0.375));
}
public function isFood($id){
return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS;

View file

@ -8,6 +8,8 @@ class Cow extends Animal{
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
$this->setName("Cow");
$this->ai->addTask(new TaskRandomWalk(0.2));
$this->ai->addTask(new TaskLookAtPlayer(6));
$this->ai->addTask(new TaskPanic(0.375));
}
public function isFood($id){

View file

@ -11,6 +11,8 @@ class Pig extends Animal implements Rideable{
$this->setSpeed(0.25);
$this->ai->addTask(new TaskRandomWalk(0.25));
$this->ai->addTask(new TaskLookAtPlayer(6));
$this->ai->addTask(new TaskPanic(0.375));
}
/**

View file

@ -14,6 +14,8 @@ class Sheep extends Animal{
$this->setSpeed(0.25);
$this->ai->addTask(new TaskRandomWalk(0.25)); //in 1.5.2 it is 0.23, but according to ida it should be 1.0 which is 0.25 if converted to 1.5.2?
$this->ai->addTask(new TaskLookAtPlayer(6));
$this->ai->addTask(new TaskPanic(0.375));
$this->ai->addTask(new TaskEatTileGoal());
}

View file

@ -8,6 +8,7 @@ class FallingSand extends Entity{
$this->setHealth(PHP_INT_MAX, "generic");
$this->height = 0.98;
$this->width = 0.98;
$this->yOffset = $this->height / 2;
$this->hasGravity = true;
$this->gravity = 0.04;
}

View file

@ -10,6 +10,7 @@ class ItemEntity extends Entity{
{
parent::__construct($level, $eid, $class, $type, $data);
$this->setSize(0.25, 0.25);
$this->yOffset = $this->height / 2;
if(isset($data["item"]) and ($data["item"] instanceof Item)){
$this->meta = $this->data["item"]->getMetadata();
$this->stack = $this->data["item"]->count;

View file

@ -65,6 +65,7 @@ class Minecart extends Vehicle{
$this->setHealth(1, "generic"); //orig: 3
$this->width = 0.98;
$this->height = 0.7;
$this->yOffset = $this->height / 2;
$this->update();
}

View file

@ -10,6 +10,8 @@ class PrimedTNT extends Entity{
}
$this->hasGravity = true;
$this->gravity = 0.04;
$this->setSize(0.98, 0.98);
$this->yOffset = $this->height / 2;
$this->setHealth(10000000, "generic");
$this->server->schedule(5, [$this, "updateFuse"], [], true);
}

View file

@ -13,7 +13,7 @@ class SpawnEggItem extends Item{
"x" => $block->x + 0.5,
"y" => $block->y,
"z" => $block->z + 0.5,
"IsBaby" => $ageable ? Utils::chance(5) ? 1 : 0 : 0
"IsBaby" => $ageable ? mt_rand(0, 5) == 0 ? 1 : 0 : 0
);
$e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
ServerAPI::request()->api->entity->spawnToAll($e);