diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 5abdf9fb4..2f49c86c9 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -445,8 +445,17 @@ class BlockAPI{ return $this->cancelAction($block, $player, false); } if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){ - $t = $this->server->api->tile->addSign($player->level, $block->x, $block->y, $block->z); - $t->data["creator"] = $player->username; + new SignTile($player->level, new NBTTag_Compound(false, array( + "id" => new NBTTag_String("id", Tile::Sign), + "x" => new NBTTag_Int("x", $block->x), + "y" => new NBTTag_Int("y", $block->y), + "z" => new NBTTag_Int("z", $block->z), + "Text1" => new NBTTag_String("Text1", ""), + "Text2" => new NBTTag_String("Text2", ""), + "Text3" => new NBTTag_String("Text3", ""), + "Text4" => new NBTTag_String("Text4", ""), + "creator" => new NBTTag_String("creator", $player->username) + ))); } if(($player->gamemode & 0x01) === 0x00){ diff --git a/src/MainServer.php b/src/MainServer.php index 9be40b243..95dba4906 100644 --- a/src/MainServer.php +++ b/src/MainServer.php @@ -132,7 +132,6 @@ class MainServer{ $this->query("PRAGMA secure_delete = OFF;"); $this->query("CREATE TABLE players (CID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT UNIQUE COLLATE NOCASE);"); $this->query("CREATE TABLE entities (EID INTEGER PRIMARY KEY, level TEXT, type NUMERIC, class NUMERIC, hasUpdate NUMERIC, name TEXT, x NUMERIC, y NUMERIC, z NUMERIC, yaw NUMERIC, pitch NUMERIC, health NUMERIC);"); - $this->query("CREATE TABLE tiles (ID INTEGER PRIMARY KEY, level TEXT, class TEXT, x NUMERIC, y NUMERIC, z NUMERIC, spawnable NUMERIC);"); $this->query("CREATE TABLE actions (ID INTEGER PRIMARY KEY, interval NUMERIC, last NUMERIC, code TEXT, repeat NUMERIC);"); $this->query("CREATE TABLE handlers (ID INTEGER PRIMARY KEY, name TEXT, priority NUMERIC);"); $this->query("CREATE TABLE blockUpdates (level TEXT, x INTEGER, y INTEGER, z INTEGER, type INTEGER, delay NUMERIC);"); diff --git a/src/Player.php b/src/Player.php index 015bb82d6..43329c2ce 100644 --- a/src/Player.php +++ b/src/Player.php @@ -196,16 +196,12 @@ class Player{ } if(is_array($this->lastChunk)){ - $tiles = $this->server->query("SELECT ID FROM tiles WHERE spawnable = 1 AND level = '".$this->level->getName()."' AND x >= ".($this->lastChunk[0] - 1)." AND x < ".($this->lastChunk[0] + 17)." AND z >= ".($this->lastChunk[1] - 1)." AND z < ".($this->lastChunk[1] + 17).";"); - $this->lastChunk = false; - if($tiles !== false and $tiles !== true){ - while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){ - $tile = $this->server->api->tile->getByID($tile["ID"]); - if($tile instanceof Tile){ - $tile->spawn($this); - } + foreach($this->level->getChunkTiles($this->lastChunk[0], $this->lastChunk[1]) as $tile){ + if($tile instanceof SpawnableTile){ + $tile->spawn($this); } - } + } + $this->lastChunk = false; } $c = key($this->chunksOrder); @@ -220,8 +216,6 @@ class Player{ $X = $id[0]; $Z = $id[2]; $Y = $id[1]; - $x = $X << 4; - $z = $Z << 4; $this->level->useChunk($X, $Z, $this); $Yndex = 1 << $Y; for($iY = 0; $iY < 8; ++$iY){ @@ -244,7 +238,7 @@ class Player{ $this->chunkCount[$count] = true; } - $this->lastChunk = array($x, $z); + $this->lastChunk = array($X, $Z); $this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk")); } @@ -2244,9 +2238,9 @@ class Player{ } $this->craftingItems = array(); $this->toCraft = array(); - $t = $this->server->api->tile->get(new Position($packet->x, $packet->y, $packet->z, $this->level)); - if(($t instanceof Tile) and $t->class === Tile::SIGN){ - if($t->data["creator"] !== $this->username){ + $t = $this->level->getTile(new Vector3($packet->x, $packet->y, $packet->z)); + if($t instanceof SignTile){ + if($t->namedtag->creator !== $this->username){ $t->spawn($this); }else{ $nbt = new NBT(); diff --git a/src/material/block/solid/BurningFurnace.php b/src/material/block/solid/BurningFurnace.php index 995b2d2e4..e358523d8 100644 --- a/src/material/block/solid/BurningFurnace.php +++ b/src/material/block/solid/BurningFurnace.php @@ -45,19 +45,18 @@ class BurningFurnaceBlock extends SolidBlock{ public function onActivate(Item $item, Player $player){ - $server = ServerAPI::request(); - $t = $server->api->tile->get($this); + $t = $this->level->getTile($this); $furnace = false; - if($t !== false){ + if($t instanceof FurnaceTile){ $furnace = $t; }else{ - $furnace = $server->api->tile->add($this->level, Tile::FURNACE, $this->x, $this->y, $this->z, array( - "Items" => array(), - "id" => Tile::FURNACE, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z - )); + $furnace = new FurnaceTile($this->level, new NBTTag_Compound(false, array( + "Items" => new NBTTag_List("Items", array()), + "id" => new NBTTag_String("id", Tile::FURNACE), + "x" => new NBTTag_Int("x", $this->x), + "y" => new NBTTag_Int("y", $this->y), + "z" =>new NBTTag_Int("z", $this->z) + ))); } if(($player->gamemode & 0x01) === 0x01){ @@ -93,9 +92,9 @@ class BurningFurnaceBlock extends SolidBlock{ if($item->isPickaxe() >= 1){ $drops[] = array(FURNACE, 0, 1); } - $t = ServerAPI::request()->api->tile->get($this); - if($t !== false and $t->class === Tile::FURNACE){ - for($s = 0; $s < FURNACE_SLOTS; ++$s){ + $t = $this->level->getTile($this); + if($t instanceof FurnaceTile){ + for($s = 0; $s < FurnaceTile::SLOTS; ++$s){ $slot = $t->getSlot($s); if($slot->getID() > AIR and $slot->count > 0){ $drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count); diff --git a/src/material/block/solid/Chest.php b/src/material/block/solid/Chest.php index 6ad1dfb6b..ca48fcacd 100644 --- a/src/material/block/solid/Chest.php +++ b/src/material/block/solid/Chest.php @@ -26,7 +26,6 @@ class ChestBlock extends TransparentBlock{ $this->hardness = 15; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $server = ServerAPI::request(); $faces = array( 0 => 4, 1 => 2, @@ -45,7 +44,7 @@ class ChestBlock extends TransparentBlock{ } $c = $this->getSide($side); if(($c instanceof ChestBlock) and $c->getMetadata() === $this->meta){ - if((($tile = $server->api->tile->get($c)) instanceof Tile) and !$tile->isPaired()){ + if((($tile = $this->level->getTile($c)) instanceof ChestTile) and !$tile->isPaired()){ $chest = $tile; break; } @@ -53,15 +52,15 @@ class ChestBlock extends TransparentBlock{ } $this->level->setBlock($block, $this, true, false, true); - $tile = $server->api->tile->add($this->level, Tile::CHEST, $this->x, $this->y, $this->z, array( - "Items" => array(), - "id" => Tile::CHEST, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z - )); + $tile = new ChestTile($this->level, new NBTTag_Compound(false, array( + "Items" => new NBTTag_List("Items", array()), + "id" => new NBTTag_String("id", Tile::CHEST), + "x" => new NBTTag_Int("x", $this->x), + "y" => new NBTTag_Int("y", $this->y), + "z" =>new NBTTag_Int("z", $this->z) + ))); - if($chest instanceof Tile){ + if($chest instanceof ChestTile){ $chest->pairWith($tile); $tile->pairWith($chest); } @@ -69,8 +68,8 @@ class ChestBlock extends TransparentBlock{ } public function onBreak(Item $item, Player $player){ - $t = ServerAPI::request()->api->tile->get($this); - if($t !== false){ + $t = $this->level->getTile($this); + if($t instanceof ChestTile){ $t->unpair(); } $this->level->setBlock($this, new AirBlock(), true, true, true); @@ -83,19 +82,18 @@ class ChestBlock extends TransparentBlock{ return true; } - $server = ServerAPI::request(); - $t = $server->api->tile->get($this); + $t = $this->level->getTile($this); $chest = false; - if($t !== false){ + if($t instanceof ChestTile){ $chest = $t; }else{ - $chest = $server->api->tile->add($this->level, Tile::CHEST, $this->x, $this->y, $this->z, array( - "Items" => array(), - "id" => Tile::CHEST, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z - )); + $chest = new ChestTile($this->level, new NBTTag_Compound(false, array( + "Items" => new NBTTag_List("Items", array()), + "id" => new NBTTag_String("id", Tile::CHEST), + "x" => new NBTTag_Int("x", $this->x), + "y" => new NBTTag_Int("y", $this->y), + "z" =>new NBTTag_Int("z", $this->z) + ))); } @@ -112,9 +110,9 @@ class ChestBlock extends TransparentBlock{ $drops = array( array($this->id, 0, 1), ); - $t = ServerAPI::request()->api->tile->get($this); - if($t !== false and $t->class === Tile::CHEST){ - for($s = 0; $s < CHEST_SLOTS; ++$s){ + $t = $this->level->getTile($this); + if($t instanceof ChestTile){ + for($s = 0; $s < ChestTile::SLOTS; ++$s){ $slot = $t->getSlot($s); if($slot->getID() > AIR and $slot->count > 0){ $drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count); diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 5db62028b..fb3f792f6 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -98,14 +98,6 @@ class PMFLevel extends PMF{ private function createBlank(){ $this->saveData(); @mkdir(dirname($this->file)."/chunks/", 0755); - if(!file_exists(dirname($this->file)."/entities.yml")){ - $entities = new Config(dirname($this->file)."/entities.yml", Config::YAML); - $entities->save(); - } - if(!file_exists(dirname($this->file)."/tiles.yml")){ - $tiles = new Config(dirname($this->file)."/tiles.yml", Config::YAML); - $tiles->save(); - } } protected function parseLevel(){ diff --git a/src/tile/ChestTile.php b/src/tile/ChestTile.php index d69dbc6ad..cfd4265d1 100644 --- a/src/tile/ChestTile.php +++ b/src/tile/ChestTile.php @@ -38,7 +38,7 @@ class ChestTile extends SpawnableTile{ public function getPair(){ if($this->isPaired()){ - return $this->server->api->tile->get(new Position((int) $this->namedtag->pairx, $this->y, (int) $this->namedtag->pairz, $this->level)); + return $this->level->getTile(new Vector3((int) $this->namedtag->pairx, $this->y, (int) $this->namedtag->pairz)); } return false; } @@ -54,8 +54,8 @@ class ChestTile extends SpawnableTile{ $tile->namedtag->pairx = $this->x; $tile->namedtag->pairz = $this->z; - $this->server->api->tile->spawnToAll($this); - $this->server->api->tile->spawnToAll($tile); + $this->spawnToAll(); + $tile->spawnToAll(); $this->server->handle("tile.update", $this); $this->server->handle("tile.update", $tile); } @@ -68,10 +68,10 @@ class ChestTile extends SpawnableTile{ $tile = $this->getPair(); unset($this->namedtag->pairx, $this->namedtag->pairz, $tile->namedtag->pairx, $tile->namedtag->pairz); - $this->server->api->tile->spawnToAll($this); + $this->spawnToAll(); $this->server->handle("tile.update", $this); - if($tile instanceof Tile){ - $this->server->api->tile->spawnToAll($tile); + if($tile instanceof ChestTile){ + $tile->spawnToAll(); $this->server->handle("tile.update", $tile); } } diff --git a/src/tile/SignTile.php b/src/tile/SignTile.php index b842c047e..185601ff6 100644 --- a/src/tile/SignTile.php +++ b/src/tile/SignTile.php @@ -33,7 +33,7 @@ class SignTile extends SpawnableTile{ $this->namedtag->Text2 = $line2; $this->namedtag->Text3 = $line3; $this->namedtag->Text4 = $line4; - $this->server->api->tile->spawnToAll($this); + $this->spawnToAll(); $this->server->handle("tile.update", $this); return true; } diff --git a/src/tile/SpawnableTile.php b/src/tile/SpawnableTile.php index 813651f31..2514d377f 100644 --- a/src/tile/SpawnableTile.php +++ b/src/tile/SpawnableTile.php @@ -22,7 +22,7 @@ abstract class SpawnableTile extends Tile{ public abstract function spawn(Player $player); - public function spawnToAll(Tile $t){ + public function spawnToAll(){ foreach($this->level->getPlayers() as $player){ if($player->eid !== false or $player->spawned !== true){ $this->spawn($player); diff --git a/src/world/Level.php b/src/world/Level.php index 3ef0c7dc4..2681ec676 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -297,7 +297,7 @@ class Level{ $this->server->api->entity->updateRadius($pos, 3); } if($tiles === true){ - if(($t = $this->server->api->tile->get($pos)) !== false){ + if(($t = $this->getTile($pos)) !== false){ $t->close(); } } @@ -305,6 +305,21 @@ class Level{ return $ret; } + public function getTile(Vector3 $pos){ + if($pos instanceof Position and $pos->level->getName() !== $this->getName()){ + return false; + } + $tiles = $this->getChunkTiles($pos->x >> 4, $pos->z >> 4); + if(count($tiles) > 0){ + foreach($tiles as $tile){ + if($tile->x === (int) $pos->x and $tile->y === (int) $pos->y and $tile->z === (int) $pos->z){ + return $tile; + } + } + } + return false; + } + public function getMiniChunk($X, $Z, $Y){ if(!isset($this->level)){ return false; diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index 35787683a..eef1f0c52 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -39,10 +39,8 @@ class WorldGenerator{ "generatorSettings" => $this->generator->getSettings(), "extra" => "" )); - $entities = new Config($this->path."entities.yml", Config::YAML); - $tiles = new Config($this->path."tiles.yml", Config::YAML); $blockUpdates = new Config($this->path."bupdates.yml", Config::YAML); - $this->level = new Level($level, $entities, $tiles, $blockUpdates, $name); + $this->level = new Level($level, $name); } public function generate(){