mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +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){
|
||||
if($level instanceof Level){
|
||||
$entities = array();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user