mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
Refactored EntityAPI and TileEntityAPI
This commit is contained in:
parent
588379a430
commit
5bba03eb09
@ -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);
|
||||
}
|
||||
|
@ -171,7 +171,10 @@ class Player{
|
||||
$tiles = $this->server->query("SELECT ID FROM tileentities WHERE spawnable = 1 AND level = '".$this->level->getName()."' AND x >= ".($x - 1)." AND x < ".($x + 17)." AND z >= ".($z - 1)." AND z < ".($z + 17)." AND y >= ".($y - 1)." AND y < ".($y + 17).";");
|
||||
if($tiles !== false and $tiles !== true){
|
||||
while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$this->server->api->tileentity->spawnTo($tile["ID"], $this);
|
||||
$tile = $this->server->api->tileentitiy->getByID($tile["ID"]);
|
||||
if($tile instanceof TileEntity){
|
||||
$tile->spawn($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -636,7 +639,7 @@ class Player{
|
||||
$this->level->freeAllChunks($this);
|
||||
$this->level = $pos->level;
|
||||
$this->chunksLoaded = array();
|
||||
$this->server->api->entity->spawnToAll($this->level, $this->eid);
|
||||
$this->server->api->entity->spawnToAll($this->entity);
|
||||
$this->server->api->entity->spawnAll($this);
|
||||
$terrain = true;
|
||||
}
|
||||
@ -987,7 +990,7 @@ class Player{
|
||||
}
|
||||
$this->spawned = true;
|
||||
$this->server->api->entity->spawnAll($this);
|
||||
$this->server->api->entity->spawnToAll($this->level, $this->eid);
|
||||
$this->server->api->entity->spawnToAll($this->entity);
|
||||
$this->server->schedule(5, array($this->entity, "update"), array(), true);
|
||||
$this->sendArmor();
|
||||
$this->eventHandler(new Container($this->server->motd), "server.chat");
|
||||
@ -1089,7 +1092,7 @@ class Player{
|
||||
"z" => $this->entity->z,
|
||||
);
|
||||
$e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_ARROW, $d);
|
||||
$this->server->api->entity->spawnToAll($this->level, $e->eid);
|
||||
$this->server->api->entity->spawnToAll($e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1396,7 +1399,7 @@ class Player{
|
||||
"meta" => $data[1],
|
||||
"stack" => $data[2],
|
||||
));
|
||||
$this->server->api->entity->spawnTo($e->eid, $this);
|
||||
$e->spawn($this);
|
||||
}
|
||||
$this->inventory[$s] = array(AIR, 0, 0);
|
||||
}*/
|
||||
|
@ -55,7 +55,7 @@ class GenericBlock extends Block{
|
||||
$server = ServerAPI::request();
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
|
||||
$server->api->entity->spawnToAll($this->level, $e->eid);
|
||||
$server->api->entity->spawnToAll($e);
|
||||
$server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1);
|
||||
}
|
||||
return false;
|
||||
|
@ -79,7 +79,7 @@ class PaintingItem extends Item{
|
||||
"Motive" => $motive[0],
|
||||
);
|
||||
$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data);
|
||||
$server->api->entity->spawnToAll($level, $e->eid);
|
||||
$server->api->entity->spawnToAll($e);
|
||||
if(($player->gamemode & 0x01) === 0x00){
|
||||
$player->removeItem($this->getID(), $this->getMetadata(), 1);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user