mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
ported 1.5.2 way of mob movement but broke everything else
This commit is contained in:
parent
8684e3092a
commit
5161d087ba
5 changed files with 169 additions and 93 deletions
|
|
@ -12,9 +12,9 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
$this->setAge(-24000);
|
||||
}
|
||||
|
||||
$this->ai->addTask(new TaskTempt());
|
||||
$this->ai->addTask(new TaskPanic());
|
||||
$this->ai->addTask(new TaskMate());
|
||||
//$this->ai->addTask(new TaskTempt());
|
||||
//$this->ai->addTask(new TaskPanic());
|
||||
//$this->ai->addTask(new TaskMate());
|
||||
}
|
||||
|
||||
public function harm($dmg, $cause = "generic", $force = false){
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ abstract class Creature extends Living{
|
|||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 1, "generic");
|
||||
$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());
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
//$this->ai->addTask(new TaskLookAround());
|
||||
//$this->ai->addTask(new TaskRandomWalk());
|
||||
//$this->ai->addTask(new TaskLookAtPlayer());
|
||||
//$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
|
||||
public function createSaveData(){
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ class Entity extends Position
|
|||
const TYPE = - 1;
|
||||
const CLASS_TYPE = - 1;
|
||||
const MIN_POSSIBLE_SPEED = 1/8000; //anything below will send 0 to player
|
||||
|
||||
public $counter = 0;
|
||||
public $fallDistance = 0;
|
||||
public static $updateOnTick, $allowedAI;
|
||||
|
|
@ -486,9 +487,91 @@ class Entity extends Position
|
|||
return $hasUpdate;
|
||||
}
|
||||
|
||||
public function moveFlying($strafe, $forward, $speed){ //TODO rename?
|
||||
$v4 = $strafe*$strafe + $forward*$forward;
|
||||
|
||||
if($v4 >= 1.0e-4){ //TODO dont use ugly scienfitic notation
|
||||
$v4 = sqrt($v4);
|
||||
if($v4 < 1) $v4 = 1;
|
||||
|
||||
$v4 = $speed / $v4;
|
||||
$strafe *= $v4;
|
||||
$forward *= $v4;
|
||||
|
||||
$v5 = sin($this->yaw * M_PI/180);
|
||||
$v6 = cos($this->yaw * M_PI/180);
|
||||
|
||||
$this->speedX += $strafe*$v6 - $forward*$v5;
|
||||
$this->speedZ += $forward*$v6 + $strafe*$v5;
|
||||
|
||||
//float var5 = MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F);
|
||||
//float var6 = MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F);
|
||||
//this.motionX += (double)(strafe * var6 - forward * var5);
|
||||
//this.motionZ += (double)(forward * var6 + strafe * var5);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateEntityMovement(){}
|
||||
|
||||
|
||||
public function move($dx, $dy, $dz){
|
||||
//TODO ySize?
|
||||
$movX = $this->x;
|
||||
$movY = $this->y;
|
||||
$movZ = $this->z;
|
||||
|
||||
//TODO isInWeb
|
||||
$savedDX = $dx;
|
||||
$savedDY = $dy;
|
||||
$savedDZ = $dz;
|
||||
|
||||
$oldBB = clone $this->boundingBox;
|
||||
|
||||
$aABB = $this->boundingBox->addCoord($dx, $dy, $dz);
|
||||
$x0 = floor($aABB->minX);
|
||||
$x1 = ceil($aABB->maxX);
|
||||
$y0 = floor($aABB->minY);
|
||||
$y1 = ceil($aABB->maxY);
|
||||
$z0 = floor($aABB->minZ);
|
||||
$z1 = ceil($aABB->maxZ);
|
||||
|
||||
for($x = $x0; $x <= $x1; ++$x){
|
||||
for($y = $y0; $y <= $y1; ++$y){
|
||||
for($z = $z0; $z <= $z1; ++$z){
|
||||
$b = $this->level->level->getBlockID($x, $y, $z);
|
||||
if($b != 0){ //TODO might be better to use other method
|
||||
$blockBounds = Block::$class[$b]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this);
|
||||
foreach($blockBounds as $blockBound){
|
||||
$dy = $blockBound->calculateYOffset($this->boundingBox, $dy);
|
||||
$dx = $blockBound->calculateXOffset($this->boundingBox, $dx);
|
||||
$dz = $blockBound->calculateZOffset($this->boundingBox, $dz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->boundingBox->offset($dx, $dy, $dz);
|
||||
$fallingFlag = $this->onGround || $savedDY != $dy && $savedDY < 0;
|
||||
|
||||
//TODO step
|
||||
$this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2;
|
||||
$this->y = $this->boundingBox->minY; //TODO + $this->yOffset - //TODO $this->ySize;
|
||||
$this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2;
|
||||
//$this.isCollidedHorizontally = savedDX != dx || savedDZ != dz;
|
||||
//$this.isCollidedVertically = savedDY != dy;
|
||||
$this->onGround = $savedDY != $dy && $savedDY < 0.0;
|
||||
//$this.isCollided = this.isCollidedHorizontally || this.isCollidedVertically;
|
||||
|
||||
if($savedDX != $dx) $this->speedX = 0;
|
||||
if($savedDY != $dy) $this->speedY = 0;
|
||||
if($savedDZ != $dz) $this->speedZ = 0;
|
||||
|
||||
//TODO more stuff
|
||||
|
||||
//TODO block collisions?
|
||||
//TODO deal fire damage here
|
||||
|
||||
}
|
||||
|
||||
public function isInVoid(){
|
||||
return $this->y < -1.6;
|
||||
}
|
||||
|
|
@ -513,7 +596,7 @@ class Entity extends Position
|
|||
if(!$this->isPlayer()){
|
||||
$this->updateLast();
|
||||
$this->updateEntityMovement();
|
||||
$update = false;
|
||||
/*$update = false;
|
||||
if($this->speedX > -self::MIN_POSSIBLE_SPEED && $this->speedX < self::MIN_POSSIBLE_SPEED){
|
||||
$this->speedX = 0;
|
||||
}
|
||||
|
|
@ -554,37 +637,8 @@ class Entity extends Position
|
|||
if($this->hasGravity){
|
||||
$this->speedY -= $this->inWater ? 0.02 : ($this->gravity);
|
||||
}
|
||||
$savedSpeedY = $this->speedY;
|
||||
$aABB = $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ);
|
||||
$x0 = floor($aABB->minX);
|
||||
$x1 = ceil($aABB->maxX);
|
||||
$y0 = floor($aABB->minY);
|
||||
$y1 = ceil($aABB->maxY);
|
||||
$z0 = floor($aABB->minZ);
|
||||
$z1 = ceil($aABB->maxZ);
|
||||
|
||||
for($x = $x0; $x <= $x1; ++$x){
|
||||
for($y = $y0; $y <= $y1; ++$y){
|
||||
for($z = $z0; $z <= $z1; ++$z){
|
||||
|
||||
$b = $this->level->level->getBlockID($x, $y, $z);
|
||||
if(($b == WATER || $b == STILL_WATER)){
|
||||
$water |= $y == ($y1 - 1);
|
||||
$this->fallDistance = 0;
|
||||
}
|
||||
if($b != 0){
|
||||
$blockBounds = Block::$class[$b]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this);
|
||||
foreach($blockBounds as $blockBound){
|
||||
$this->speedY = $blockBound->calculateYOffset($this->boundingBox, $this->speedY);
|
||||
$this->speedX = $blockBound->calculateXOffset($this->boundingBox, $this->speedX);
|
||||
$this->speedZ = $blockBound->calculateZOffset($this->boundingBox, $this->speedZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->boundingBox->offset($this->speedX, $this->speedY, $this->speedZ);
|
||||
$this->inWater = $water;
|
||||
$this->move($this->speedX, $this->speedY, $this->speedZ);
|
||||
$this->inWater = $water; TODO
|
||||
$fallingFlag = $this->onGround || $savedSpeedY != $this->speedY && $savedSpeedY < 0.0;
|
||||
$beforeStepSpeedY = $this->speedY;
|
||||
|
||||
|
|
@ -636,39 +690,7 @@ class Entity extends Position
|
|||
$this->ai->mobController->setJumping(false);
|
||||
}
|
||||
}
|
||||
|
||||
$support = $savedSpeedY != $this->speedY && $savedSpeedY < 0;
|
||||
if($this->speedX != 0){
|
||||
$this->x += $this->speedX;
|
||||
$update = true;
|
||||
}
|
||||
if($this->speedZ != 0){
|
||||
$this->z += $this->speedZ;
|
||||
$update = true;
|
||||
}
|
||||
if($this->speedY != 0){
|
||||
$ny = $this->y + $this->speedY;
|
||||
if($stepSuccess) $this->speedY = $beforeStepSpeedY;
|
||||
if($this->class === ENTITY_FALLING){
|
||||
if($support){
|
||||
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->data["Tile"], 0);
|
||||
$this->close();
|
||||
return;
|
||||
}
|
||||
$id = $this->level->level->getBlockID($this->x, $this->y, $this->z);
|
||||
if($id > 0 && !StaticBlock::getIsSolid($id) && !StaticBlock::getIsLiquid($id)){
|
||||
$this->server->api->entity->drop($this, BlockAPI::getItem($this->data["Tile"], 0, 1));
|
||||
$this->close();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
$this->y = $ny;
|
||||
|
||||
$update = true;
|
||||
}
|
||||
|
||||
$this->onGround = $support;
|
||||
}*/
|
||||
|
||||
|
||||
if($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){
|
||||
|
|
@ -1085,18 +1107,6 @@ class Entity extends Position
|
|||
$this->pitch = $angle["pitch"];
|
||||
}
|
||||
|
||||
public function move(Vector3 $pos, $yaw = 0, $pitch = 0)
|
||||
{
|
||||
$this->x += $pos->x;
|
||||
$this->y += $pos->y;
|
||||
$this->z += $pos->z;
|
||||
$this->yaw += $yaw;
|
||||
$this->yaw %= 360;
|
||||
$this->pitch += $pitch;
|
||||
$this->pitch %= 90;
|
||||
$this->updateAABB();
|
||||
}
|
||||
|
||||
public function updateAABB()
|
||||
{
|
||||
$this->boundingBox->setBounds(
|
||||
|
|
|
|||
|
|
@ -3,10 +3,14 @@
|
|||
abstract class Living extends Entity implements Pathfindable{
|
||||
|
||||
public static $despawnMobs, $despawnTimer, $entityPushing = false;
|
||||
|
||||
public $moveStrafing, $moveForward;
|
||||
public $target, $ai;
|
||||
public $pathFinder, $path = null, $currentIndex = 0, $currentNode, $pathFollower;
|
||||
public $ticksExisted = 0;
|
||||
|
||||
public $landMovementFactor = 0.1; //TODO may not be constant
|
||||
public $jumpMovementFactor = 0.02; //TODO may not be constant
|
||||
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
$this->target = false;
|
||||
$this->ai = new EntityAI($this);
|
||||
|
|
@ -99,15 +103,77 @@ abstract class Living extends Entity implements Pathfindable{
|
|||
$this->ai->mobController->rotateTick();
|
||||
$this->ai->mobController->movementTick();
|
||||
|
||||
|
||||
if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0;
|
||||
if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0;
|
||||
if(abs($this->speedY) < self::MIN_POSSIBLE_SPEED) $this->speedY = 0;
|
||||
|
||||
$this->moveStrafing *= 0.98;
|
||||
$this->moveForward *= 0.98;
|
||||
$savedLandFactor = $this->landMovementFactor;
|
||||
$this->landMovementFactor *= $this->getSpeedModifer();
|
||||
$this->moveEntityWithHeading($this->moveStrafing, $this->moveForward);
|
||||
$this->landMovementFactor = $savedLandFactor;
|
||||
|
||||
if(self::$entityPushing){
|
||||
$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();
|
||||
}
|
||||
|
||||
public function moveEntityWithHeading($strafe, $forward){
|
||||
//TODO lava, water
|
||||
//If not in lava in water ->
|
||||
{
|
||||
$friction = 0.91;
|
||||
|
||||
if($this->onGround){
|
||||
$friction = 0.546;
|
||||
$blockAt = $this->level->level->getBlockID(floor($this->x), floor($this->boundingBox->minY) - 1, floor($this->z));
|
||||
|
||||
if($blockAt > 0) $friction = StaticBlock::getSlipperiness($blockAt) * 0.91;
|
||||
}
|
||||
|
||||
$var8 = 0.16277136 / ($friction*$friction*$friction);
|
||||
|
||||
if($this->onGround){
|
||||
//TODO if AIEnabled
|
||||
{
|
||||
//TODO $var5 = getAIMoveSpeed
|
||||
}
|
||||
//else
|
||||
{
|
||||
$var5 = $this->landMovementFactor;
|
||||
}
|
||||
$var5 *= $var8;
|
||||
}else{
|
||||
$var5 = $this->jumpMovementFactor;
|
||||
}
|
||||
|
||||
$this->moveFlying($strafe, $forward, $var5);
|
||||
//1.5.2 recalculates friction, might be not neccessary
|
||||
$friction = 0.91;
|
||||
|
||||
if($this->onGround){
|
||||
$friction = 0.546;
|
||||
$blockAt = $this->level->level->getBlockID(floor($this->x), floor($this->boundingBox->minY) - 1, floor($this->z));
|
||||
|
||||
if($blockAt > 0) $friction = StaticBlock::getSlipperiness($blockAt) * 0.91;
|
||||
}
|
||||
|
||||
//TODO onLadder
|
||||
console($this->speedY);
|
||||
$this->move($this->speedX, $this->speedY, $this->speedZ);
|
||||
//TODO onLadder + isCollidedHorizonatlly => speedY = 0.2
|
||||
|
||||
$this->speedY -= 0.08; //gravity
|
||||
|
||||
$this->speedY *= 0.98;
|
||||
$this->speedX *= $friction;
|
||||
$this->speedZ *= $friction;
|
||||
}
|
||||
|
||||
//TODO limbYaw - is it even needed?
|
||||
|
||||
}
|
||||
|
||||
public function sendMoveUpdate(){
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ class MobController
|
|||
);
|
||||
}
|
||||
|
||||
while(self::$ADVANCED){
|
||||
if($this->isDangerous($a) || $this->isDangerous($b) || $this->isDangerous($c) || $this->isDangerous($d)){
|
||||
while(self::$ADVANCED){
|
||||
if($this->isDangerous($a) || $this->isDangerous($b) || $this->isDangerous($c) || $this->isDangerous($d)){
|
||||
return false;
|
||||
}
|
||||
$id1 = $this->entity->level->level->getBlockID($xf, $this->entity->y + $oy - 1, $zf);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue