From 7753b1d8bec46b149140807ee351de29d6286c50 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 19 May 2015 21:29:30 +0200 Subject: [PATCH] Fixed items (and other entities) vibrating, bad offsets in tile calculation --- src/pocketmine/Player.php | 8 +++---- src/pocketmine/entity/Entity.php | 10 ++++----- src/pocketmine/level/Explosion.php | 6 +++--- src/pocketmine/level/Level.php | 34 +++++++++++++++--------------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 472d5ce60..7d9fdb69a 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -667,6 +667,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade ++$count; + $this->usedChunks[$index] = false; + $this->level->registerChunkLoader($this, $X, $Z); + if(!$this->level->populateChunk($X, $Z)){ if($this->spawned and $this->teleportPosition === null){ continue; @@ -676,9 +679,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } unset($this->loadQueue[$index]); - $this->usedChunks[$index] = false; - - $this->level->registerChunkLoader($this, $X, $Z); $this->level->requestChunk($X, $Z, $this, LevelProvider::ORDER_ZXY); } @@ -1398,7 +1398,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->entityBaseTick($tickDiff); - if(!$this->isSpectator()){ + if(!$this->isSpectator() and $this->speed !== null){ if($this->onGround){ if($this->inAirTicks !== 0){ $this->startAirTicks = 5; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 0615a0e30..aa3f728df 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -656,9 +656,9 @@ abstract class Entity extends Location implements Metadatable{ } protected function checkObstruction($x, $y, $z){ - $i = (int) $x; - $j = (int) $y; - $k = (int) $z; + $i = Math::floorFloat($x); + $j = Math::floorFloat($y); + $k = Math::floorFloat($z); $diffX = $x - $i; $diffY = $y - $j; @@ -830,7 +830,7 @@ abstract class Entity extends Location implements Metadatable{ $diffMotion = ($this->motionX - $this->lastMotionX) ** 2 + ($this->motionY - $this->lastMotionY) ** 2 + ($this->motionZ - $this->lastMotionZ) ** 2; - if($diffPosition > 0.04 or $diffRotation > 2.25 or ($diffMotion > 0 and $this->getMotion()->lengthSquared() <= 0.0001)){ //0.2 ** 2, 1.5 ** 2 + if($diffPosition > 0.04 or $diffRotation > 2.25 and ($diffMotion > 0.0001 and $this->getMotion()->lengthSquared() <= 0.00001)){ //0.2 ** 2, 1.5 ** 2 $this->lastX = $this->x; $this->lastY = $this->y; $this->lastZ = $this->z; @@ -845,7 +845,7 @@ abstract class Entity extends Location implements Metadatable{ } } - if($diffMotion > 0.0025 or ($diffMotion > 0 and $this->getMotion()->lengthSquared() <= 0.0001)){ //0.05 ** 2 + if($diffMotion > 0.0025 or ($diffMotion > 0.0001 and $this->getMotion()->lengthSquared() <= 0.0001)){ //0.05 ** 2 $this->lastMotionX = $this->motionX; $this->lastMotionY = $this->motionY; $this->lastMotionZ = $this->motionZ; diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index abe0be5d9..212badc6d 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -145,11 +145,11 @@ class Explosion{ $explosionSize = $this->size * 2; $minX = Math::floorFloat($this->source->x - $explosionSize - 1); - $maxX = Math::floorFloat($this->source->x + $explosionSize + 1); + $maxX = Math::ceilFloat($this->source->x + $explosionSize + 1); $minY = Math::floorFloat($this->source->y - $explosionSize - 1); - $maxY = Math::floorFloat($this->source->y + $explosionSize + 1); + $maxY = Math::ceilFloat($this->source->y + $explosionSize + 1); $minZ = Math::floorFloat($this->source->z - $explosionSize - 1); - $maxZ = Math::floorFloat($this->source->z + $explosionSize + 1); + $maxZ = Math::ceilFloat($this->source->z + $explosionSize + 1); $explosionBB = new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 60c6cb091..f38e072da 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -982,13 +982,13 @@ class Level implements ChunkManager, Metadatable{ * @return Block[] */ public function getCollisionBlocks(AxisAlignedBB $bb){ - $minX = (int) $bb->minX; - $minY = (int) $bb->minY; - $minZ = (int) $bb->minZ; - $maxX = (int) ($bb->maxX + 1); - $maxY = (int) ($bb->maxY + 1); - $maxZ = (int) ($bb->maxZ + 1); - + $minX = Math::floorFloat($bb->minX); + $minY = Math::floorFloat($bb->minY); + $minZ = Math::floorFloat($bb->minZ); + $maxX = Math::ceilFloat($bb->maxX); + $maxY = Math::ceilFloat($bb->maxY); + $maxZ = Math::ceilFloat($bb->maxZ); + $collides = []; $v = $this->temporalVector; @@ -1030,12 +1030,12 @@ class Level implements ChunkManager, Metadatable{ * @return AxisAlignedBB[] */ public function getCollisionCubes(Entity $entity, AxisAlignedBB $bb, $entities = true){ - $minX = (int) $bb->minX; - $minY = (int) $bb->minY; - $minZ = (int) $bb->minZ; - $maxX = (int) ($bb->maxX + 1); - $maxY = (int) ($bb->maxY + 1); - $maxZ = (int) ($bb->maxZ + 1); + $minX = Math::floorFloat($bb->minX); + $minY = Math::floorFloat($bb->minY); + $minZ = Math::floorFloat($bb->minZ); + $maxX = Math::ceilFloat($bb->maxX); + $maxY = Math::ceilFloat($bb->maxY); + $maxZ = Math::ceilFloat($bb->maxZ); $collides = []; $v = $this->temporalVector; @@ -1692,10 +1692,10 @@ class Level implements ChunkManager, Metadatable{ public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null){ $nearby = []; - $minX = (int) (($bb->minX - 2) / 16); - $maxX = (int) (($bb->maxX + 2) / 16 + 1); - $minZ = (int) (($bb->minZ - 2) / 16); - $maxZ = (int) (($bb->maxZ + 2) / 16 + 1); + $minX = Math::floorFloat(($bb->minX - 2) / 16); + $maxX = Math::ceilFloat(($bb->maxX + 2) / 16 + 1); + $minZ = Math::floorFloat(($bb->minZ - 2) / 16); + $maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16 + 1); for($x = $minX; $x <= $maxX; ++$x){ for($z = $minZ; $z <= $maxZ; ++$z){