From 0ca6becc6a4d4daab2718a2bf2274c17ff6388cd Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 31 Jan 2024 05:58:05 +0300 Subject: [PATCH] lava movement --- src/entity/Entity.php | 66 +++++++--------------------- src/entity/Living.php | 16 +++++-- src/entity/ai/tasks/TaskSwimming.php | 4 +- src/entity/object/FallingSand.php | 12 ----- src/world/Level.php | 21 ++++++++- 5 files changed, 51 insertions(+), 68 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 99fec561..03d536b1 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -97,7 +97,7 @@ class Entity extends Position */ public $fireResistance = 1; public $inWeb; - + public $inLava; function __construct(Level $level, $eid, $class, $type = 0, $data = array()) { $this->random = new Random(); @@ -338,6 +338,11 @@ class Entity extends Position } } + public function handleLavaMovement(){ //TODO maybe try merging with water? + $this->inLava = $this->level->isLavaInBB($this->boundingBox->expand(-0.1, -0.4, -0.1)); + return $this->inLava; + } + 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; @@ -419,6 +424,13 @@ class Entity extends Position } } + if(!$this->isPlayer()) { + if($this->handleLavaMovement()){ + //TODO this.setOnFireFromLava(); + $this->fallDistance *= 0.5; + } + } + $startX = floor($this->boundingBox->minX); $startY = floor($this->boundingBox->minY); $startZ = floor($this->boundingBox->minZ); @@ -590,11 +602,11 @@ class Entity extends Position $aABB = $this->boundingBox->addCoord($dx, $dy, $dz); $x0 = floor($aABB->minX); - $x1 = floor($aABB->maxX) + 1; + $x1 = floor($aABB->maxX + 1); $y0 = floor($aABB->minY); - $y1 = floor($aABB->maxY) + 1; + $y1 = floor($aABB->maxY + 1); $z0 = floor($aABB->minZ); - $z1 = floor($aABB->maxZ) + 1; + $z1 = floor($aABB->maxZ + 1); for($x = $x0; $x < $x1; ++$x){ for($y = $y0; $y < $y1; ++$y){ @@ -750,52 +762,6 @@ class Entity extends Position $this->updateLast(); $this->updatePosition(); //TODO shouldnt be called in Entity $this->updateEntityMovement(); - /*$update = false; - if($this->speedX > -self::MIN_POSSIBLE_SPEED && $this->speedX < self::MIN_POSSIBLE_SPEED){ - $this->speedX = 0; - } - if($this->speedZ > -self::MIN_POSSIBLE_SPEED && $this->speedZ < self::MIN_POSSIBLE_SPEED){ - $this->speedZ = 0; - } - if($this->speedY > -self::MIN_POSSIBLE_SPEED && $this->speedY < self::MIN_POSSIBLE_SPEED){ - $this->speedY = 0; - } - - $horizontalMultiplyFactor = 0.91; - if($this->onGround){ - $horizontalMultiplyFactor = 0.54; - $b = $this->level->level->getBlockID(floor($this->x), floor($this->boundingBox->minY) - 1, floor($this->z)); - if($b > 0){ - $horizontalMultiplyFactor = StaticBlock::getSlipperiness($b) * 0.91; - } - } - - if($this->inWater){ - $this->speedX *= 0.8; - $this->speedY *= 0.8; - $this->speedZ *= 0.8; - }else{ - $this->speedX *= $horizontalMultiplyFactor; - $this->speedY *= 0.98; - $this->speedZ *= $horizontalMultiplyFactor; - } - - $savedSpeedY = $this->speedY; - $savedSpeedX = $this->speedX; - $savedSpeedZ = $this->speedZ; - $ultraMegaOldBB = clone $this->boundingBox; - $stepSuccess = false; - $beforeStepSpeedY = 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); - } - } - }*/ - if($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){ $this->server->api->handle("entity.move", $this); diff --git a/src/entity/Living.php b/src/entity/Living.php index 0f836bc7..4bbcb5cd 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -185,9 +185,19 @@ abstract class Living extends Entity implements Pathfindable{ if($this->isCollidedHorizontally && $this->isFree($this->speedX, $this->speedY + 0.6 - $this->y + $prevPosY, $this->speedZ)){ $this->speedY = 0.3; } - } - //TODO lava - else{ + }else if($this->inLava){ + $prevPosY = $this->y; + $this->moveFlying($strafe, $forward, 0.02); + $this->move($this->speedX, $this->speedY, $this->speedZ); + $this->speedX *= 0.5; + $this->speedY *= 0.5; + $this->speedZ *= 0.5; + $this->speedY -= 0.02; + + if($this->isCollidedHorizontally && $this->isFree($this->speedX, $this->speedY + 0.6 - $this->y + $prevPosY, $this->speedZ)){ + $this->speedY = 0.3; + } + }else{ $friction = 0.91; if($this->onGround){ diff --git a/src/entity/ai/tasks/TaskSwimming.php b/src/entity/ai/tasks/TaskSwimming.php index 59b5700a..f074a9a9 100644 --- a/src/entity/ai/tasks/TaskSwimming.php +++ b/src/entity/ai/tasks/TaskSwimming.php @@ -14,7 +14,7 @@ class TaskSwimming extends TaskBase public function onUpdate(EntityAI $ai) { - if(!$ai->entity->inWater){ + if(!$ai->entity->inWater || !$ai->entity->inLava){ $this->reset(); return; } @@ -26,7 +26,7 @@ class TaskSwimming extends TaskBase public function canBeExecuted(EntityAI $ai) { - return $ai->entity->inWater; + return $ai->entity->inWater || $ai->entity->inLava; } } diff --git a/src/entity/object/FallingSand.php b/src/entity/object/FallingSand.php index 2a43338f..c29a8f94 100644 --- a/src/entity/object/FallingSand.php +++ b/src/entity/object/FallingSand.php @@ -36,18 +36,6 @@ class FallingSand extends Entity{ $y = floor($this->y); $z = floor($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; diff --git a/src/world/Level.php b/src/world/Level.php index 0c1a8eb7..3e39ccd9 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -77,7 +77,26 @@ class Level{ } //TODO mayPlace - + public function isLavaInBB($aabb){ + $minX = floor($aabb->minX); + $maxX = floor($aabb->maxX + 1); + $minY = floor($aabb->minY); + $maxY = floor($aabb->maxY + 1); + $minZ = floor($aabb->minZ); + $maxZ = floor($aabb->maxZ + 1); + + for($x = $minX; $x < $maxX; ++$x){ + for($y = $minY; $y < $maxY; ++$y){ + for($z = $minZ; $z < $maxZ; ++$z){ + $blockId = $this->level->getBlockID($x, $y, $z); + + if($blockId == LAVA || $blockId == STILL_LAVA) return true; + } + } + } + + return false; + } public function handleMaterialAcceleration(AxisAlignedBB $aabb, $materialType, Entity $entity){ $minX = floor($aabb->minX);