mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
Fixed getting Entities by area
This commit is contained in:
parent
9aed430fda
commit
b9ec63f016
@ -1203,7 +1203,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$hasUpdate = $this->entityBaseTick();
|
$hasUpdate = $this->entityBaseTick();
|
||||||
foreach($this->getNearbyEntities($this->boundingBox->expand(3, 3, 3)) as $entity){
|
foreach($this->getLevel()->getCollidingEntities($this->boundingBox->expand(1.5, 1, 1.5), $this) as $entity){
|
||||||
if($entity instanceof DroppedItem){
|
if($entity instanceof DroppedItem){
|
||||||
if($entity->dead !== true and $entity->getPickupDelay() <= 0){
|
if($entity->dead !== true and $entity->getPickupDelay() <= 0){
|
||||||
$item = $entity->getItem();
|
$item = $entity->getItem();
|
||||||
@ -1227,6 +1227,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->inventory->addItem(clone $item);
|
||||||
|
|
||||||
$pk = new TakeItemEntityPacket;
|
$pk = new TakeItemEntityPacket;
|
||||||
$pk->eid = 0;
|
$pk->eid = 0;
|
||||||
$pk->target = $entity->getID();
|
$pk->target = $entity->getID();
|
||||||
@ -1236,7 +1238,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$pk->eid = $this->getID();
|
$pk->eid = $this->getID();
|
||||||
$pk->target = $entity->getID();
|
$pk->target = $entity->getID();
|
||||||
$this->server->broadcastPacket($entity->getViewers(), $pk);
|
$this->server->broadcastPacket($entity->getViewers(), $pk);
|
||||||
$this->inventory->addItem(clone $item);
|
|
||||||
$entity->kill();
|
$entity->kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -591,37 +591,6 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
$this->fallDistance = 0;
|
$this->fallDistance = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the entities near the current one inside the AxisAlignedBB
|
|
||||||
*
|
|
||||||
* @param AxisAlignedBB $bb
|
|
||||||
*
|
|
||||||
* @return Entity[]
|
|
||||||
*/
|
|
||||||
public function getNearbyEntities(AxisAlignedBB $bb){
|
|
||||||
|
|
||||||
$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->getLevel()->isChunkLoaded($x, $z)){
|
|
||||||
foreach($this->getLevel()->getChunkEntities($x, $z) as $ent){
|
|
||||||
if($ent !== $this and $ent->boundingBox->intersectsWith($this->boundingBox)){
|
|
||||||
$nearby[] = $ent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $nearby;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function move($dx, $dy, $dz){
|
public function move($dx, $dy, $dz){
|
||||||
//$collision = [];
|
//$collision = [];
|
||||||
//$this->checkBlockCollision($collision);
|
//$this->checkBlockCollision($collision);
|
||||||
|
@ -929,6 +929,37 @@ class Level{
|
|||||||
return $this->entities;
|
return $this->entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the entities near the current one inside the AxisAlignedBB
|
||||||
|
*
|
||||||
|
* @param AxisAlignedBB $bb
|
||||||
|
* @param Entity $entity
|
||||||
|
*
|
||||||
|
* @return Entity[]
|
||||||
|
*/
|
||||||
|
public function getCollidingEntities(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)){
|
||||||
|
foreach($this->getChunkEntities($x, $z) as $ent){
|
||||||
|
if($ent !== $entity and $ent->boundingBox->intersectsWith($bb)){
|
||||||
|
$nearby[] = $ent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nearby;
|
||||||
|
}
|
||||||
|
|
||||||
public function addEntity(Entity $entity){
|
public function addEntity(Entity $entity){
|
||||||
//TODO: chunkIndex
|
//TODO: chunkIndex
|
||||||
$this->entities[$entity->getID()] = $entity;
|
$this->entities[$entity->getID()] = $entity;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user