mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-24 13:39:44 +00:00
Merge pull request #32 from gameherobrine2/newmovement
209 (step height and autojump rewrite)
This commit is contained in:
commit
6d430c3440
7 changed files with 116 additions and 48 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());
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,9 @@ class Entity extends Position
|
||||||
public $onGround, $inWater;
|
public $onGround, $inWater;
|
||||||
public $carryoverDamage;
|
public $carryoverDamage;
|
||||||
public $gravity;
|
public $gravity;
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
@ -150,6 +153,7 @@ class Entity extends Position
|
||||||
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y;
|
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y;
|
||||||
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z;
|
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z;
|
||||||
$this->setHealth(1, "generic");
|
$this->setHealth(1, "generic");
|
||||||
|
$this->stepHeight = false;
|
||||||
// $this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
// $this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
||||||
$this->width = 1;
|
$this->width = 1;
|
||||||
$this->height = 1;
|
$this->height = 1;
|
||||||
|
|
@ -500,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;
|
||||||
}
|
}
|
||||||
|
|
@ -535,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;
|
||||||
|
|
@ -566,6 +569,11 @@ class Entity extends Position
|
||||||
}
|
}
|
||||||
|
|
||||||
$savedSpeedY = $this->speedY;
|
$savedSpeedY = $this->speedY;
|
||||||
|
$savedSpeedX = $this->speedX;
|
||||||
|
$savedSpeedZ = $this->speedZ;
|
||||||
|
$ultraMegaOldBB = clone $this->boundingBox;
|
||||||
|
$stepSuccess = false;
|
||||||
|
$beforeStepSpeedY = 0;
|
||||||
if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT) || $this->class === ENTITY_FALLING){
|
if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT) || $this->class === ENTITY_FALLING){
|
||||||
$water = false;
|
$water = false;
|
||||||
if($this->hasGravity){
|
if($this->hasGravity){
|
||||||
|
|
@ -601,9 +609,65 @@ class Entity extends Position
|
||||||
}
|
}
|
||||||
$this->boundingBox->offset($this->speedX, $this->speedY, $this->speedZ);
|
$this->boundingBox->offset($this->speedX, $this->speedY, $this->speedZ);
|
||||||
$this->inWater = $water;
|
$this->inWater = $water;
|
||||||
}
|
$fallingFlag = $this->onGround || $savedSpeedY != $this->speedY && $savedSpeedY < 0.0;
|
||||||
$support = $savedSpeedY != $this->speedY && $savedSpeedY < 0;
|
$beforeStepSpeedY = $this->speedY;
|
||||||
|
|
||||||
|
if($this->stepHeight > 0 && $fallingFlag && ($this->speedX != $savedSpeedX || $this->speedZ != $savedSpeedZ)){
|
||||||
|
$cx = $this->speedX;
|
||||||
|
$cy = $this->speedY;
|
||||||
|
$cz = $this->speedZ;
|
||||||
|
|
||||||
|
$this->speedX = $savedSpeedX;
|
||||||
|
$this->speedY = $this->stepHeight;
|
||||||
|
$this->speedZ = $savedSpeedZ;
|
||||||
|
|
||||||
|
$aabb = clone $this->boundingBox;
|
||||||
|
$this->boundingBox->setBB($ultraMegaOldBB);
|
||||||
|
$aaBBs = $this->level->getCubes($this, $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ));
|
||||||
|
|
||||||
|
foreach($aaBBs as $bb){ //TODO optimize
|
||||||
|
$this->speedY = $bb->calculateYOffset($this->boundingBox, $this->speedY);
|
||||||
|
}
|
||||||
|
$this->boundingBox->offset(0, $this->speedY, 0);
|
||||||
|
|
||||||
|
foreach($aaBBs as $bb){
|
||||||
|
$this->speedX = $bb->calculateXOffset($this->boundingBox, $this->speedX);
|
||||||
|
}
|
||||||
|
$this->boundingBox->offset($this->speedX, 0, 0);
|
||||||
|
|
||||||
|
foreach($aaBBs as $bb){
|
||||||
|
$this->speedZ = $bb->calculateZOffset($this->boundingBox, $this->speedZ);
|
||||||
|
}
|
||||||
|
$this->boundingBox->offset(0, 0, $this->speedZ);
|
||||||
|
|
||||||
|
//$this->speedY = -$this->stepHeight;
|
||||||
|
//foreach($aaBBs as $bb){ //TODO optimize
|
||||||
|
// $this->speedY = $bb->calculateYOffset($this->boundingBox, $this->speedY);
|
||||||
|
//}
|
||||||
|
//$this->boundingBox->offset(0, $this->speedY, 0);
|
||||||
|
|
||||||
|
if ($cx*$cx + $cz*$cz >= $this->speedX*$this->speedX + $this->speedZ*$this->speedZ)
|
||||||
|
{
|
||||||
|
$this->speedX = $cx;
|
||||||
|
$this->speedY = $cy;
|
||||||
|
$this->speedZ = $cz;
|
||||||
|
$this->boundingBox->setBB($aabb);
|
||||||
|
}else{
|
||||||
|
$stepSuccess = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
@ -614,6 +678,7 @@ class Entity extends Position
|
||||||
}
|
}
|
||||||
if($this->speedY != 0){
|
if($this->speedY != 0){
|
||||||
$ny = $this->y + $this->speedY;
|
$ny = $this->y + $this->speedY;
|
||||||
|
if($stepSuccess) $this->speedY = $beforeStepSpeedY;
|
||||||
if($this->class === ENTITY_FALLING){
|
if($this->class === ENTITY_FALLING){
|
||||||
if($support){
|
if($support){
|
||||||
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->data["Tile"], 0);
|
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->data["Tile"], 0);
|
||||||
|
|
@ -632,6 +697,7 @@ class Entity extends Position
|
||||||
|
|
||||||
$update = true;
|
$update = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->onGround = $support;
|
$this->onGround = $support;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -780,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{
|
||||||
|
|
@ -1328,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,11 +72,17 @@ 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();
|
||||||
}*/
|
}*/
|
||||||
|
|
@ -86,9 +92,6 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
|
||||||
//}
|
//}
|
||||||
//$this->pathFollower->followPath();
|
//$this->pathFollower->followPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
parent::update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendMoveUpdate(){
|
public function sendMoveUpdate(){
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
class MobController
|
class MobController
|
||||||
{
|
{
|
||||||
public static $ADVANCED = false;
|
public static $ADVANCED = false;
|
||||||
|
public static $AUTOJUMP = false;
|
||||||
public static $landed = false;
|
public static $landed = false;
|
||||||
public static $DANGEROUS_BLOCKS = [
|
public static $DANGEROUS_BLOCKS = [
|
||||||
LAVA => true,
|
LAVA => true,
|
||||||
|
|
@ -42,12 +43,13 @@ 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;
|
||||||
|
if(self::$AUTOJUMP){
|
||||||
$oy = $this->entity->onGround && (
|
$oy = $this->entity->onGround && (
|
||||||
StaticBlock::getIsSolid(($a = $this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y), ceil($zf)))) &&
|
StaticBlock::getIsSolid(($a = $this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y), ceil($zf)))) &&
|
||||||
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y) + 1, ceil($zf)))
|
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y) + 1, ceil($zf)))
|
||||||
|
|
@ -61,6 +63,7 @@ class MobController
|
||||||
StaticBlock::getIsSolid(($d = $this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y), ceil($zf)))) &&
|
StaticBlock::getIsSolid(($d = $this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y), ceil($zf)))) &&
|
||||||
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y) + 1, ceil($zf)))
|
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y) + 1, ceil($zf)))
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
while(self::$ADVANCED){
|
while(self::$ADVANCED){
|
||||||
if($this->isDangerous($a) || $this->isDangerous($b) || $this->isDangerous($c) || $this->isDangerous($d)){
|
if($this->isDangerous($a) || $this->isDangerous($b) || $this->isDangerous($c) || $this->isDangerous($d)){
|
||||||
|
|
@ -97,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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,5 +21,6 @@ class ItemEntity extends Entity{
|
||||||
$this->setHealth(5, "generic");
|
$this->setHealth(5, "generic");
|
||||||
$this->gravity = 0.04;
|
$this->gravity = 0.04;
|
||||||
$this->delayBeforePickup = 20;
|
$this->delayBeforePickup = 20;
|
||||||
|
$this->stepHeight = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
//TODO make it extend SlabBlock
|
||||||
class WoodSlabBlock extends TransparentBlock{
|
class WoodSlabBlock extends TransparentBlock{
|
||||||
public function __construct($meta = 0){
|
public function __construct($meta = 0){
|
||||||
parent::__construct(WOOD_SLAB, $meta, "Wooden Slab");
|
parent::__construct(WOOD_SLAB, $meta, "Wooden Slab");
|
||||||
|
|
@ -17,7 +17,10 @@ class WoodSlabBlock extends TransparentBlock{
|
||||||
}
|
}
|
||||||
$this->hardness = 15;
|
$this->hardness = 15;
|
||||||
}
|
}
|
||||||
|
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
|
||||||
|
if(($level->level->getBlockDamage($x, $y, $z) & 0x08) == 0x08) return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)];
|
||||||
|
return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 0.5, $z + 1)];
|
||||||
|
}
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
$this->meta &= 0x07;
|
$this->meta &= 0x07;
|
||||||
if($face === 0){
|
if($face === 0){
|
||||||
|
|
|
||||||
|
|
@ -75,15 +75,16 @@ class Level{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param Entity $e
|
||||||
* @param AxisAlignedBB $aABB
|
* @param AxisAlignedBB $aABB
|
||||||
* @return AxisAlignedBB[]
|
* @return AxisAlignedBB[]
|
||||||
*/
|
*/
|
||||||
public function getCubes(AxisAlignedBB $aABB) {
|
public function getCubes(Entity $e, AxisAlignedBB $aABB) {
|
||||||
$aABBs = [];
|
$aABBs = [];
|
||||||
$x0 = floor($aABB->minX);
|
$x0 = floor($aABB->minX);
|
||||||
$x1 = ceil($aABB->maxX);
|
$x1 = ceil($aABB->maxX);
|
||||||
$y0 = floor($aABB->minY);
|
$y0 = floor($aABB->minY);
|
||||||
$y1 = round($aABB->maxY);
|
$y1 = ceil($aABB->maxY);
|
||||||
$z0 = floor($aABB->minZ);
|
$z0 = floor($aABB->minZ);
|
||||||
$z1 = ceil($aABB->maxZ);
|
$z1 = ceil($aABB->maxZ);
|
||||||
$x0 = $x0 < 0 ? 0 : $x0;
|
$x0 = $x0 < 0 ? 0 : $x0;
|
||||||
|
|
@ -93,12 +94,15 @@ class Level{
|
||||||
$y1 = $y1 > 128 ? 128 : $y1;
|
$y1 = $y1 > 128 ? 128 : $y1;
|
||||||
$z1 = $z1 > 256 ? 256 : $z1;
|
$z1 = $z1 > 256 ? 256 : $z1;
|
||||||
|
|
||||||
for($x = $x0; $x < $x1; ++$x) {
|
for($x = $x0; $x <= $x1; ++$x) {
|
||||||
for($y = $y0; $y < $y1; ++$y) {
|
for($y = $y0; $y <= $y1; ++$y) {
|
||||||
for($z = $z0; $z < $z1; ++$z) {
|
for($z = $z0; $z <= $z1; ++$z) {
|
||||||
$b = $this->getBlockWithoutVector($x, $y, $z);
|
$bid = $this->level->getBlockID($x, $y, $z);
|
||||||
if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid) {
|
if($bid > 0){
|
||||||
$aABBs[] = $b->boundingBox;
|
$blockBounds = Block::$class[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z);
|
||||||
|
foreach($blockBounds as $blockBound){
|
||||||
|
$aABBs[] = $blockBound;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue