mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
Refactored EntityAPI and TileEntityAPI
This commit is contained in:
parent
588379a430
commit
5bba03eb09
5 changed files with 18 additions and 38 deletions
|
|
@ -112,21 +112,9 @@ class EntityAPI{
|
|||
return $this->entities[$eid];
|
||||
}
|
||||
|
||||
public function spawnTo($eid, $player){
|
||||
$e = $this->get($eid);
|
||||
if($e === false){
|
||||
return false;
|
||||
}
|
||||
$e->spawn($player);
|
||||
}
|
||||
|
||||
public function spawnToAll(Level $level, $eid){
|
||||
$e = $this->get($eid);
|
||||
if($e === false){
|
||||
return false;
|
||||
}
|
||||
foreach($this->server->api->player->getAll($level) as $player){
|
||||
if($player->eid !== false and $player->eid !== $eid){
|
||||
public function spawnToAll(Entity $e){
|
||||
foreach($this->server->api->player->getAll($e->level) as $player){
|
||||
if($player->eid !== false and $player->eid !== $e->eid){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
|
|
@ -150,7 +138,7 @@ class EntityAPI{
|
|||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
|
||||
$this->spawnToAll($pos->level, $e->eid);
|
||||
$this->spawnToAll($e);
|
||||
$this->server->api->handle("entity.motion", $e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class TileEntityAPI{
|
|||
public function add(Level $level, $class, $x, $y, $z, $data = array()){
|
||||
$id = $this->tCnt++;
|
||||
$this->tileEntities[$id] = new TileEntity($level, $id, $class, $x, $y, $z, $data);
|
||||
$this->spawnToAll($level, $id);
|
||||
$this->spawnToAll($this->tileEntities[$id]);
|
||||
return $this->tileEntities[$id];
|
||||
}
|
||||
|
||||
|
|
@ -92,20 +92,8 @@ class TileEntityAPI{
|
|||
));
|
||||
}
|
||||
|
||||
public function spawnTo($id, $player){
|
||||
$t = $this->getByID($id);
|
||||
if($t === false){
|
||||
return false;
|
||||
}
|
||||
$t->spawn($player);
|
||||
}
|
||||
|
||||
public function spawnToAll(Level $level, $id){
|
||||
$t = $this->getByID($id);
|
||||
if($t === false){
|
||||
return false;
|
||||
}
|
||||
foreach($this->server->api->player->getAll($level) as $player){
|
||||
public function spawnToAll(TileEntity $t){
|
||||
foreach($this->server->api->player->getAll($t->level) as $player){
|
||||
if($player->eid !== false){
|
||||
$t->spawn($player);
|
||||
}
|
||||
|
|
@ -126,6 +114,7 @@ class TileEntityAPI{
|
|||
$t->closed = true;
|
||||
$t->close();
|
||||
$this->server->query("DELETE FROM tileentities WHERE ID = ".$id.";");
|
||||
$this->server->api->dhandle("tile.remove", $t);
|
||||
$t = null;
|
||||
unset($t);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue