diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 5c68dff3..4602d727 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -319,7 +319,19 @@ class Entity extends Position $this->server->api->entity->drop($this, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF), true); } } - + + public function handleWaterMovement(){ + if($this->level->handleMaterialAcceleration($this->boundingBox->expand(0, -0.4, 0)->contract(0.001, 0.001, 0.001), 0, $this)){ + $this->fallDistance = 0; + $this->inWater = true; + $this->fire = 0; + }else{ + $this->inWater = false; + } + + return $this->inWater; + } + public function environmentUpdate($time) { $hasUpdate = $this->class === ENTITY_MOB; // force true for mobs @@ -372,7 +384,10 @@ class Entity extends Position $this->outOfWorld(); $hasUpdate = true; } - + if(!$this->isPlayer()){ + $this->handleWaterMovement(); + } + if($this->fire > 0){ if(($this->fire % 20) === 0){ $this->harm(1, "burning"); @@ -411,6 +426,8 @@ class Entity extends Position } } + + //air damage if($this->isPlayer() || $this instanceof Living){ $d = $this->y + $this->getEyeHeight(); diff --git a/src/entity/Living.php b/src/entity/Living.php index 3124197d..382c3357 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -13,7 +13,7 @@ abstract class Living extends Entity implements Pathfindable{ public $aiMoveSpeed; public $renderYawOffset = 0.0; //used by head rotation, TODO better name - + public $jumping, $jumpTicks; public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ $this->target = false; $this->ai = new EntityAI($this); @@ -115,7 +115,7 @@ abstract class Living extends Entity implements Pathfindable{ public function updateEntityMovement(){ if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) { - //$this->ai->updateTasks(); + $this->ai->updateTasks(); } //if($this->onGround){ // if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){ @@ -123,9 +123,27 @@ abstract class Living extends Entity implements Pathfindable{ // } // $this->pathFollower->followPath(); //} + + + //not exactly here + if($this->jumping){ + if(!$this->inWater){ //TODO also lava + if($this->onGround && $this->jumpTicks <= 0){ + //TODO jump $this->jump(); + $this->jumpTicks = 10; + } + }else{ + $this->speedY += 0.04; + } + }else{ + $this->jumpTicks = 0; + } + + $this->ai->mobController->movementTick(); $this->ai->mobController->rotateTick(); - + $this->ai->mobController->jumpTick(); + 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; @@ -147,10 +165,28 @@ abstract class Living extends Entity implements Pathfindable{ } + public function counterUpdate(){ + parent::counterUpdate(); + if($this->jumpTicks > 0) --$this->jumpTicks; + } + public function moveEntityWithHeading($strafe, $forward){ - //TODO lava, water - //If not in lava in water -> - { + if($this->inWater){ //also check is player, and can it fly or not + $this->moveFlying($strafe, $forward, 0.04); //TODO speed: this.isAIEnabled() ? 0.04F : 0.02F + $this->move($this->speedX, $this->speedY, $this->speedZ); + $this->speedX *= 0.8; + $this->speedY *= 0.8; + $this->speedZ *= 0.8; + $this->speedY -= 0.02; + + //TODO: static speedY + //if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6 - this.posY + var9, this.motionZ)) + //{ + // this.motionY = 0.3; + //} + } + //TODO lava + else{ $friction = 0.91; if($this->onGround){ diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index 342fb168..1c30d638 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -21,7 +21,6 @@ class MobController public $someTicker = 0; protected $jumping; - protected $jumpTimeout; public $moveToX, $moveToY, $moveToZ; public $speed; @@ -84,6 +83,11 @@ class MobController return $old + $v4; } + public function jumpTick(){ + $this->entity->jumping = $this->jumping; + $this->jumping = false; + } + public function movementTick(){ $this->entity->moveForward = 0; if($this->updateMove){ diff --git a/src/entity/ai/tasks/TaskSwimming.php b/src/entity/ai/tasks/TaskSwimming.php index 159c7ff3..59b5700a 100644 --- a/src/entity/ai/tasks/TaskSwimming.php +++ b/src/entity/ai/tasks/TaskSwimming.php @@ -16,15 +16,12 @@ class TaskSwimming extends TaskBase { if(!$ai->entity->inWater){ $this->reset(); - $ai->mobController->setJumping(false); return; } if(lcg_value() < 0.8){ #1.5.2 method $ai->mobController->setJumping(true); } - - } public function canBeExecuted(EntityAI $ai) diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index d1049460..5e0c2c4b 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -15,6 +15,7 @@ class Chicken extends Animal{ $this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskPanic(0.375)); $this->ai->addTask(new TaskLookAround()); + $this->ai->addTask(new TaskSwimming()); } public function isFood($id){ return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS; diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index ed592207..02bd7f69 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -11,8 +11,7 @@ class Cow extends Animal{ $this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskPanic(0.375)); $this->ai->addTask(new TaskLookAround()); - - //$this->ai->addTask(new TaskSwimming()); + $this->ai->addTask(new TaskSwimming()); } public function isFood($id){ diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index a69bdfd3..0c152f82 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -14,6 +14,7 @@ class Pig extends Animal implements Rideable{ $this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskPanic(0.375)); $this->ai->addTask(new TaskLookAround()); + $this->ai->addTask(new TaskSwimming()); } /** * @return boolean diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index 2b002cf4..79e66056 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -18,6 +18,7 @@ class Sheep extends Animal{ $this->ai->addTask(new TaskPanic(0.375)); $this->ai->addTask(new TaskEatTileGoal()); $this->ai->addTask(new TaskLookAround()); + $this->ai->addTask(new TaskSwimming()); } public function createSaveData(){ diff --git a/src/entity/monster/Creeper.php b/src/entity/monster/Creeper.php index 93011ba9..750d80e8 100644 --- a/src/entity/monster/Creeper.php +++ b/src/entity/monster/Creeper.php @@ -14,6 +14,7 @@ class Creeper extends Monster{ $this->ai->addTask(new TaskRandomWalk(0.25)); $this->ai->addTask(new TaskLookAround()); + $this->ai->addTask(new TaskSwimming()); } public function getAttackDamage(){ diff --git a/src/entity/monster/PigZombie.php b/src/entity/monster/PigZombie.php index 1e8878c9..6be561e8 100644 --- a/src/entity/monster/PigZombie.php +++ b/src/entity/monster/PigZombie.php @@ -10,6 +10,7 @@ class PigZombie extends Monster{ $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskSwimming()); } public function getAttackDamage(){ return 5; diff --git a/src/entity/monster/Skeleton.php b/src/entity/monster/Skeleton.php index 46471322..749f0d06 100644 --- a/src/entity/monster/Skeleton.php +++ b/src/entity/monster/Skeleton.php @@ -11,6 +11,7 @@ class Skeleton extends Monster{ $this->ai->addTask(new TaskRandomWalk(0.25)); $this->ai->addTask(new TaskLookAround()); + $this->ai->addTask(new TaskSwimming()); } public function getAttackDamage(){ @@ -18,7 +19,7 @@ class Skeleton extends Monster{ } public function updateBurning(){ - if($this->fire > 0 or !$this->level->isDay()){ + if($this->fire > 0 or !$this->level->isDay() || $this->inWater){ //TODO fix burning in water return false; } diff --git a/src/entity/monster/Spider.php b/src/entity/monster/Spider.php index 69dab308..d9adf87e 100644 --- a/src/entity/monster/Spider.php +++ b/src/entity/monster/Spider.php @@ -9,6 +9,7 @@ class Spider extends Monster{ $this->setSpeed(0.3); $this->ai->addTask(new TaskRandomWalk(0.25)); //TODO this mob doesnt use newAI -> speed is not correct $this->ai->addTask(new TaskLookAround()); //TODO this mob doesnt use newAI + $this->ai->addTask(new TaskSwimming()); } public function getDrops(){ diff --git a/src/entity/monster/Zombie.php b/src/entity/monster/Zombie.php index 0364f6f5..e864ada3 100644 --- a/src/entity/monster/Zombie.php +++ b/src/entity/monster/Zombie.php @@ -10,6 +10,7 @@ class Zombie extends Monster{ $this->ai->addTask(new TaskRandomWalk(0.25)); $this->ai->addTask(new TaskLookAround()); + $this->ai->addTask(new TaskSwimming()); } public function getArmorValue(){ @@ -17,7 +18,7 @@ class Zombie extends Monster{ } public function updateBurning(){ - if($this->fire > 0 or !$this->level->isDay()){ + if($this->fire > 0 or !$this->level->isDay() || $this->inWater){ //TODO fix burning in water return false; } diff --git a/src/entity/object/FallingSand.php b/src/entity/object/FallingSand.php index 42ad573c..6a9a8607 100644 --- a/src/entity/object/FallingSand.php +++ b/src/entity/object/FallingSand.php @@ -3,6 +3,9 @@ class FallingSand extends Entity{ const TYPE = FALLING_SAND; const CLASS_TYPE = ENTITY_FALLING; + + public $fallTime = 0; + public function __construct($level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); $this->setHealth(PHP_INT_MAX, "generic"); @@ -12,4 +15,52 @@ class FallingSand extends Entity{ $this->hasGravity = true; $this->gravity = 0.04; } + + public function update($now){ + if($this->closed) return; + + if( $this->data["Tile"] == AIR) $this->close(); + else { + $this->lastX = $this->x; + $this->lastY = $this->y; + $this->lastZ = $this->z; + ++$this->fallTime; + $this->speedY -= 0.04; + $this->move($this->speedX, $this->speedY, $this->speedZ); + + $this->speedX *= 0.98; + $this->speedY *= 0.98; + $this->speedZ *= 0.98; + + $x = floor($this->x); + $y = floor($this->y); + $z = floot($this->z); + + if($this->fallTime == 1){ + /* i dont think this is needed here? + * if (this.worldObj.getBlockId(var1, var2, var3) != this.blockID) + { + this.setDead(); + return; + } + + this.worldObj.setBlockToAir(var1, var2, var3); + */ + } + + if($this->onGround){ + $this->speedX *= 0.7; + $this->speedZ *= 0.7; + $this->speedY *= -0.5; + + //1.5.2 has piston check, skipping + $this->close(); + //if (!this.isBreakingAnvil && this.worldObj.canPlaceEntityOnSide(this.blockID, var1, var2, var3, true, 1, (Entity)null, (ItemStack)null) && !BlockSand.canFallBelow(this.worldObj, var1, var2 - 1, var3) && this.worldObj.setBlock(var1, var2, var3, this.blockID, this.metadata, 3)) + // + //} + //a check if block has tilentity, might be added after tile entities rewrite + + } + } + } } \ No newline at end of file diff --git a/src/material/Block.php b/src/material/Block.php index f15cf946..e4b4965e 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -155,6 +155,7 @@ abstract class Block extends Position{ public $z = 0; public $slipperiness; + public static function addVelocityToEntity(Level $level, $x, $y, $z, Entity $entity, Vector3 $velocityVector){} public static function onRandomTick(Level $level, $x, $y, $z){} public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){} public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ diff --git a/src/world/Level.php b/src/world/Level.php index 4cfc4f1c..cf4e1a10 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -76,6 +76,47 @@ class Level{ return true; } + //TODO public function canPlaceEntityOnSide() + + public function handleMaterialAcceleration(AxisAlignedBB $aabb, $materialType, Entity $entity){ + $minX = floor($aabb->minX); + $maxX = ceil($aabb->maxX); + $minY = floor($aabb->minY); + $maxY = ceil($aabb->maxY); + $minZ = floor($aabb->minZ); + $maxZ = ceil($aabb->maxZ); + + //1.5.2 checks that all chunks exist, not needed here i think + + $appliedVelocity = false; + $velocityVec = new Vector3(0, 0, 0); + + for($x = $minX; $x < $maxX; ++$x){ + for($y = $minY; $y < $maxY; ++$y){ + for($z = $minZ; $z < $maxZ; ++$z){ + [$block, $meta] = $this->level->getBlock($x, $y, $z); + if(($materialType == 0 && ($block == WATER || $block == STILL_WATER)) || ($materialType == 1 && ($block == LAVA || $block == STILL_LAVA))){ //TODO better material system + $v16 = ($y + 1) - LiquidBlock::getPercentAir($meta); + if($maxY >= $v16){ + $appliedVelocity = true; + Block::$class[$block]::addVelocityToEntity($this, $x, $y, $z, $entity, $velocityVec); + } + } + } + } + } + + if($velocityVec->length() > 0){ //also checks is player flying + $velocityVec = $velocityVec->normalize(); //TODO do not use vec methods + $v18 = 0.014; + $entity->speedX += $velocityVec->x * $v18; + $entity->speedY += $velocityVec->y * $v18; + $entity->speedZ += $velocityVec->z * $v18; + } + + return $appliedVelocity; + } + /** * @param Entity $e * @param AxisAlignedBB $aABB