diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 6eb1c99d7..cee4d3d8d 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1204,7 +1204,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return true; } $hasUpdate = $this->entityBaseTick(); - foreach($this->getLevel()->getCollidingEntities($this->boundingBox->expand(1.5, 1, 1.5), $this) as $entity){ + foreach($this->getLevel()->getNearbyEntities($this->boundingBox->expand(1.5, 1, 1.5), $this) as $entity){ if($entity instanceof DroppedItem){ if($entity->dead !== true and $entity->getPickupDelay() <= 0){ $item = $entity->getItem(); diff --git a/src/pocketmine/entity/DroppedItem.php b/src/pocketmine/entity/DroppedItem.php index 3a7bc07e4..101346f26 100644 --- a/src/pocketmine/entity/DroppedItem.php +++ b/src/pocketmine/entity/DroppedItem.php @@ -46,7 +46,6 @@ class DroppedItem extends Entity{ protected $drag = 0.02; protected function initEntity(){ - //TODO: upgrade old numeric entity ids $this->namedtag->id = new String("id", "Item"); $this->setMaxHealth(5); $this->setHealth(@$this->namedtag["Health"]); @@ -150,6 +149,10 @@ class DroppedItem extends Entity{ return $this->item; } + public function canCollideWith(Entity $entity){ + return false; + } + /** * @return int */ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index efb8368ec..6c8d4799c 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -277,6 +277,10 @@ abstract class Entity extends Position implements Metadatable{ $this->health = (int) min($this->health, $this->maxHealth); } + public function canCollideWith(Entity $entity){ + return true; + } + protected function checkObstruction($x, $y, $z){ $i = (int) $x; $j = (int) $y; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index e121ae9b1..6e6afcabf 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -566,9 +566,9 @@ class Level{ } //TODO: fix this - /*foreach($entity->getNearbyEntities($bb->expand(0.25, 0.25, 0.25)) as $ent){ + foreach($this->getCollidingEntities($bb->expand(0.25, 0.25, 0.25), $entity) as $ent){ $collides[] = $ent->boundingBox; - }*/ + } return $collides; } @@ -842,7 +842,7 @@ class Level{ //$face = -1; } - if($hand->isSolid === true and $this->getCollidingEntities($hand->getBoundingBox())){ + if($hand->isSolid === true and count($this->getCollidingEntities($hand->getBoundingBox())) > 0){ return false; //Entity in block } @@ -948,6 +948,37 @@ class Level{ $minZ = ($bb->minZ - 2) >> 4; $maxZ = ($bb->maxZ + 2) >> 4; + for($x = $minX; $x <= $maxX; ++$x){ + for($z = $minZ; $z <= $maxZ; ++$z){ + if($this->isChunkLoaded($x, $z)){ + foreach($this->getChunkEntities($x, $z) as $ent){ + if($ent !== $entity and ($entity === null or ($ent->canCollideWith($entity) and $entity->canCollideWith($ent))) and $ent->boundingBox->intersectsWith($bb)){ + $nearby[] = $ent; + } + } + } + } + } + + return $nearby; + } + + /** + * Returns the entities near the current one inside the AxisAlignedBB + * + * @param AxisAlignedBB $bb + * @param Entity $entity + * + * @return Entity[] + */ + public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null){ + $nearby = []; + + $minX = ($bb->minX - 2) >> 4; + $maxX = ($bb->maxX + 2) >> 4; + $minZ = ($bb->minZ - 2) >> 4; + $maxZ = ($bb->maxZ + 2) >> 4; + for($x = $minX; $x <= $maxX; ++$x){ for($z = $minZ; $z <= $maxZ; ++$z){ if($this->isChunkLoaded($x, $z)){