diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 59874882..510170d5 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -46,6 +46,20 @@ class EntityAPI{ } + public function getRadius(Position $center, $radius = 15, $class = false){ + $entities = array(); + $l = $this->server->query("SELECT EID FROM entities WHERE level = '".$center->level->getName()."' ".($class !== false ? "AND class = $class ":"")."AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;"); + if($l !== false and $l !== true){ + while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ + $e = $this->get($e["EID"]); + if($e instanceof Entity){ + $entities[$e->eid] = $e; + } + } + } + return $entities; + } + public function getAll($level = null){ if($level instanceof Level){ $entities = array(); diff --git a/src/world/Entity.php b/src/world/Entity.php index 3ab362c5..e07cafd8 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -212,28 +212,21 @@ class Entity extends Position{ $hasUpdate = false; $time = microtime(true); if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === true){ - $items = $this->server->query("SELECT EID FROM entities WHERE level = '".$this->level->getName()."' AND class = ".ENTITY_ITEM." AND abs(x - {$this->x}) <= 1.5 AND abs(y - {$this->y}) <= 1.5 AND abs(z - {$this->z}) <= 1.5;"); - if($items instanceof SQLite3Result){ - while(($item = $items->fetchArray(SQLITE3_NUM)) !== false){ - $item = $this->server->api->entity->get($item[0]); - if(!($item instanceof Entity)){ - continue; - } - if(($time - $item->spawntime) >= 0.6){ - if(($this->player->gamemode & 0x01) === 0x00){ - if($this->player->hasSpace($item->type, $item->meta, $item->stack) === true and $this->server->api->dhandle("player.pickup", array( - "eid" => $this->player->eid, - "player" => $this->player, - "entity" => $item, - "block" => $item->type, - "meta" => $item->meta, - "target" => $item->eid - )) !== false){ - $item->close(); - } - }else{ + foreach($this->server->api->entity->getRadius($this, 1.5, ENTITY_ITEM) as $item){ + if(($time - $item->spawntime) >= 0.6){ + if(($this->player->gamemode & 0x01) === 0x00){ + if($this->player->hasSpace($item->type, $item->meta, $item->stack) === true and $this->server->api->dhandle("player.pickup", array( + "eid" => $this->player->eid, + "player" => $this->player, + "entity" => $item, + "block" => $item->type, + "meta" => $item->meta, + "target" => $item->eid + )) !== false){ $item->close(); } + }else{ + $item->close(); } } }