mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
new autojump
This commit is contained in:
parent
f7745aa69c
commit
f7fed3cd74
4 changed files with 33 additions and 33 deletions
|
|
@ -12,7 +12,8 @@ abstract class Creature extends Living{
|
|||
$this->inPanic = false; //force for now
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 1, "generic");
|
||||
// $this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
|
||||
$this->enableAutojump = true;
|
||||
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskRandomWalk());
|
||||
$this->ai->addTask(new TaskLookAtPlayer());
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class Entity extends Position
|
|||
public $gravity;
|
||||
|
||||
public $stepHeight = 0.5;
|
||||
|
||||
public $enableAutojump = false;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array())
|
||||
{
|
||||
$this->random = new Random();
|
||||
|
|
@ -504,16 +504,14 @@ class Entity extends Position
|
|||
return $hasUpdate;
|
||||
}
|
||||
|
||||
|
||||
public function updateEntityMovement(){}
|
||||
|
||||
|
||||
public function isInVoid(){
|
||||
return $this->y < -1.6;
|
||||
}
|
||||
|
||||
|
||||
public function update(){
|
||||
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
}
|
||||
|
|
@ -539,6 +537,7 @@ class Entity extends Position
|
|||
if($this->isStatic === false){
|
||||
if(!$this->isPlayer()){
|
||||
$this->updateLast();
|
||||
$this->updateEntityMovement();
|
||||
$update = false;
|
||||
if($this->speedX > -self::MIN_POSSIBLE_SPEED && $this->speedX < self::MIN_POSSIBLE_SPEED){
|
||||
$this->speedX = 0;
|
||||
|
|
@ -612,6 +611,7 @@ class Entity extends Position
|
|||
$this->inWater = $water;
|
||||
$fallingFlag = $this->onGround || $savedSpeedY != $this->speedY && $savedSpeedY < 0.0;
|
||||
$beforeStepSpeedY = $this->speedY;
|
||||
|
||||
if($this->stepHeight > 0 && $fallingFlag && ($this->speedX != $savedSpeedX || $this->speedZ != $savedSpeedZ)){
|
||||
$cx = $this->speedX;
|
||||
$cy = $this->speedY;
|
||||
|
|
@ -658,8 +658,16 @@ class Entity extends Position
|
|||
}
|
||||
|
||||
}
|
||||
$support = $savedSpeedY != $this->speedY && $savedSpeedY < 0;
|
||||
|
||||
if($this->enableAutojump && $this instanceof Creature){
|
||||
if(!$stepSuccess && $fallingFlag && ($this->speedX != $savedSpeedX || $this->speedZ != $savedSpeedZ)){
|
||||
$this->ai->mobController->setJumping(true);
|
||||
}else{
|
||||
$this->ai->mobController->setJumping(false);
|
||||
}
|
||||
}
|
||||
|
||||
$support = $savedSpeedY != $this->speedY && $savedSpeedY < 0;
|
||||
if($this->speedX != 0){
|
||||
$this->x += $this->speedX;
|
||||
$update = true;
|
||||
|
|
@ -689,6 +697,7 @@ class Entity extends Position
|
|||
|
||||
$update = true;
|
||||
}
|
||||
|
||||
$this->onGround = $support;
|
||||
|
||||
|
||||
|
|
@ -837,15 +846,6 @@ class Entity extends Position
|
|||
$pk->pitch = $this->pitch;
|
||||
$pk->bodyYaw = $this->yaw;
|
||||
$this->server->api->player->broadcastPacket($players, $pk);
|
||||
} else{
|
||||
/*$pk = new MoveEntityPacket_PosRot();
|
||||
$pk->eid = $this->eid;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$this->server->api->player->broadcastPacket($players, $pk);*/
|
||||
}
|
||||
}
|
||||
} else{
|
||||
|
|
@ -1385,14 +1385,6 @@ class Entity extends Position
|
|||
$this->player->teleport(new Vector3($this->x, $this->y, $this->z));
|
||||
return;
|
||||
}
|
||||
/*$pk = new MoveEntityPacket_PosRot();
|
||||
$pk->eid = $this->eid;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);*/
|
||||
}
|
||||
|
||||
public function moveEntityWithOffset($oX, $oY, $oZ)
|
||||
|
|
|
|||
|
|
@ -72,23 +72,26 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
|
|||
return;
|
||||
}
|
||||
if($this->closed) return;
|
||||
|
||||
parent::update();
|
||||
}
|
||||
|
||||
public function updateEntityMovement(){
|
||||
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
|
||||
$this->ai->updateTasks();
|
||||
}
|
||||
$this->ai->mobController->rotateTick();
|
||||
$this->ai->mobController->movementTick();
|
||||
|
||||
/*if(self::$entityPushing){
|
||||
$this->collideHandler();
|
||||
}*/
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
parent::update();
|
||||
}
|
||||
|
||||
public function sendMoveUpdate(){
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ class MobController
|
|||
return false;
|
||||
}
|
||||
|
||||
$ox = ($x > 0 ? 1 : ($x < 0 ? -1 : 0));
|
||||
$oy = ($y > 0 ? 1 : ($y < 0 ? -1 : 0));
|
||||
$oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0));
|
||||
$ox = $x <=> 1;
|
||||
$oy = $y <=> 1;
|
||||
$oz = $z <=> 1;
|
||||
$xf = $this->entity->x + ($this->entity->getSpeedModifer() * $ox * $this->entity->getSpeed());
|
||||
$zf = $this->entity->z + ($this->entity->getSpeedModifer() * $oz * $this->entity->getSpeed());
|
||||
$a = $b = $c = $d = 0;
|
||||
|
|
@ -100,10 +100,14 @@ class MobController
|
|||
return true;
|
||||
}
|
||||
|
||||
public function canJump(){
|
||||
return $this->isJumping() && $this->jumpTimeout <= 0 && $this->entity->onGround;
|
||||
}
|
||||
|
||||
public function movementTick(){
|
||||
if($this->isJumping() && $this->jumpTimeout <= 0 && $this->entity->onGround){
|
||||
if($this->canJump()){
|
||||
$this->jumpTimeout = 10;
|
||||
$this->entity->speedY = 0.40;
|
||||
$this->entity->speedY = 0.50;
|
||||
}
|
||||
if($this->jumpTimeout > 0) --$this->jumpTimeout;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue