mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +00:00
New method EntityAPI::getRadius()
This commit is contained in:
parent
a890cdc023
commit
75bb2a6399
@ -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){
|
public function getAll($level = null){
|
||||||
if($level instanceof Level){
|
if($level instanceof Level){
|
||||||
$entities = array();
|
$entities = array();
|
||||||
|
@ -212,13 +212,7 @@ class Entity extends Position{
|
|||||||
$hasUpdate = false;
|
$hasUpdate = false;
|
||||||
$time = microtime(true);
|
$time = microtime(true);
|
||||||
if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === 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;");
|
foreach($this->server->api->entity->getRadius($this, 1.5, ENTITY_ITEM) as $item){
|
||||||
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(($time - $item->spawntime) >= 0.6){
|
||||||
if(($this->player->gamemode & 0x01) === 0x00){
|
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(
|
if($this->player->hasSpace($item->type, $item->meta, $item->stack) === true and $this->server->api->dhandle("player.pickup", array(
|
||||||
@ -236,7 +230,6 @@ class Entity extends Position{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}elseif($this->class === ENTITY_ITEM){
|
}elseif($this->class === ENTITY_ITEM){
|
||||||
if(($time - $this->spawntime) >= 300){
|
if(($time - $this->spawntime) >= 300){
|
||||||
$this->close(); //Despawn timer
|
$this->close(); //Despawn timer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user