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