Updated TileEntity API [fixes #306]

This commit is contained in:
Shoghi Cervantes 2013-05-29 23:13:01 +02:00
parent 25de7a68d5
commit 450b5d9560
5 changed files with 10 additions and 53 deletions

View File

@ -35,21 +35,11 @@ class TileEntityAPI{
}
public function get(Position $pos){
$tiles = $this->server->query("SELECT * FROM tileentities WHERE level = '".$pos->level->getName()."' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};");
$ret = array();
if($tiles !== false and $tiles !== true){
while(($t = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){
if(($tile = $this->getByID($t["ID"])) !== false){
if($tile->normal === true){
$ret[] = $tile;
}
}
}
$tile = $this->server->query("SELECT * FROM tileentities WHERE level = '".$pos->level->getName()."' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};", true);
if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){
return $tile;
}
if(count($ret) === 0){
return false;
}
return $ret;
return false;
}
public function getByID($id){

View File

@ -1240,8 +1240,7 @@ class Player{
break;
}
$t = $this->server->api->tileentity->get(new Position($data["x"], $data["y"], $data["z"], $this->level));
if(($t[0] instanceof TileEntity) and $t[0]->class === TILE_SIGN){
$t = $t[0];
if(($t instanceof TileEntity) and $t->class === TILE_SIGN){
if($t->data["creator"] !== $this->username){
$t->spawn($this);
}else{

View File

@ -46,19 +46,7 @@ class BurningFurnaceBlock extends SolidBlock{
public function onBreak(Item $item, Player $player){
$server = ServerAPI::request();
$t = $server->api->tileentity->get($this);
if($t !== false){
if(is_array($t)){
foreach($t as $ts){
if($ts->class === TILE_FURNACE){
$server->api->tileentity->remove($ts->id);
}
}
}elseif($t->class === TILE_FURNACE){
$server->api->tileentity->remove($t->id);
}
}
$this->level->setBlock($this, new AirBlock());
$this->level->setBlock($this, new AirBlock(), true, true);
return true;
}
@ -68,11 +56,7 @@ class BurningFurnaceBlock extends SolidBlock{
$t = $server->api->tileentity->get($this);
$furnace = false;
if($t !== false){
if(is_array($t)){
$furnace = array_shift($t);
}else{
$furnace = $t;
}
$furnace = $t;
}else{
$furnace = $server->api->tileentity->add($this->level, TILE_FURNACE, $this->x, $this->y, $this->z, array(
"Items" => array(),

View File

@ -59,19 +59,7 @@ class ChestBlock extends TransparentBlock{
public function onBreak(Item $item, Player $player){
$server = ServerAPI::request();
$t = $server->api->tileentity->get($this);
if($t !== false){
if(is_array($t)){
foreach($t as $ts){
if($ts->class === TILE_CHEST){
$server->api->tileentity->remove($ts->id);
}
}
}elseif($t->class === TILE_CHEST){
$server->api->tileentity->remove($t->id);
}
}
$this->level->setBlock($this, new AirBlock());
$this->level->setBlock($this, new AirBlock(), true, true);
return true;
}
@ -85,11 +73,7 @@ class ChestBlock extends TransparentBlock{
$t = $server->api->tileentity->get($this);
$chest = false;
if($t !== false){
if(is_array($t)){
$chest = array_shift($t);
}else{
$chest = $t;
}
$chest = $t;
}else{
$chest = $server->api->tileentity->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array(
"Items" => array(),

View File

@ -247,7 +247,7 @@ class Level{
}
if($tiles === true){
if(($t = $this->server->api->tileentity->get($pos)) !== false){
$t[0]->close();
$t->close();
}
}
}