mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 00:59:51 +00:00
Updated global Tile code
This commit is contained in:
parent
44b9d33b65
commit
c9dfdc288d
@ -445,8 +445,17 @@ class BlockAPI{
|
|||||||
return $this->cancelAction($block, $player, false);
|
return $this->cancelAction($block, $player, false);
|
||||||
}
|
}
|
||||||
if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){
|
if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){
|
||||||
$t = $this->server->api->tile->addSign($player->level, $block->x, $block->y, $block->z);
|
new SignTile($player->level, new NBTTag_Compound(false, array(
|
||||||
$t->data["creator"] = $player->username;
|
"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){
|
if(($player->gamemode & 0x01) === 0x00){
|
||||||
|
@ -132,7 +132,6 @@ class MainServer{
|
|||||||
$this->query("PRAGMA secure_delete = OFF;");
|
$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 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 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 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 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);");
|
$this->query("CREATE TABLE blockUpdates (level TEXT, x INTEGER, y INTEGER, z INTEGER, type INTEGER, delay NUMERIC);");
|
||||||
|
@ -196,16 +196,12 @@ class Player{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(is_array($this->lastChunk)){
|
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).";");
|
foreach($this->level->getChunkTiles($this->lastChunk[0], $this->lastChunk[1]) as $tile){
|
||||||
$this->lastChunk = false;
|
if($tile instanceof SpawnableTile){
|
||||||
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);
|
$tile->spawn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
$this->lastChunk = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$c = key($this->chunksOrder);
|
$c = key($this->chunksOrder);
|
||||||
@ -220,8 +216,6 @@ class Player{
|
|||||||
$X = $id[0];
|
$X = $id[0];
|
||||||
$Z = $id[2];
|
$Z = $id[2];
|
||||||
$Y = $id[1];
|
$Y = $id[1];
|
||||||
$x = $X << 4;
|
|
||||||
$z = $Z << 4;
|
|
||||||
$this->level->useChunk($X, $Z, $this);
|
$this->level->useChunk($X, $Z, $this);
|
||||||
$Yndex = 1 << $Y;
|
$Yndex = 1 << $Y;
|
||||||
for($iY = 0; $iY < 8; ++$iY){
|
for($iY = 0; $iY < 8; ++$iY){
|
||||||
@ -244,7 +238,7 @@ class Player{
|
|||||||
$this->chunkCount[$count] = true;
|
$this->chunkCount[$count] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->lastChunk = array($x, $z);
|
$this->lastChunk = array($X, $Z);
|
||||||
|
|
||||||
$this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk"));
|
$this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk"));
|
||||||
}
|
}
|
||||||
@ -2244,9 +2238,9 @@ class Player{
|
|||||||
}
|
}
|
||||||
$this->craftingItems = array();
|
$this->craftingItems = array();
|
||||||
$this->toCraft = array();
|
$this->toCraft = array();
|
||||||
$t = $this->server->api->tile->get(new Position($packet->x, $packet->y, $packet->z, $this->level));
|
$t = $this->level->getTile(new Vector3($packet->x, $packet->y, $packet->z));
|
||||||
if(($t instanceof Tile) and $t->class === Tile::SIGN){
|
if($t instanceof SignTile){
|
||||||
if($t->data["creator"] !== $this->username){
|
if($t->namedtag->creator !== $this->username){
|
||||||
$t->spawn($this);
|
$t->spawn($this);
|
||||||
}else{
|
}else{
|
||||||
$nbt = new NBT();
|
$nbt = new NBT();
|
||||||
|
@ -45,19 +45,18 @@ class BurningFurnaceBlock extends SolidBlock{
|
|||||||
|
|
||||||
public function onActivate(Item $item, Player $player){
|
public function onActivate(Item $item, Player $player){
|
||||||
|
|
||||||
$server = ServerAPI::request();
|
$t = $this->level->getTile($this);
|
||||||
$t = $server->api->tile->get($this);
|
|
||||||
$furnace = false;
|
$furnace = false;
|
||||||
if($t !== false){
|
if($t instanceof FurnaceTile){
|
||||||
$furnace = $t;
|
$furnace = $t;
|
||||||
}else{
|
}else{
|
||||||
$furnace = $server->api->tile->add($this->level, Tile::FURNACE, $this->x, $this->y, $this->z, array(
|
$furnace = new FurnaceTile($this->level, new NBTTag_Compound(false, array(
|
||||||
"Items" => array(),
|
"Items" => new NBTTag_List("Items", array()),
|
||||||
"id" => Tile::FURNACE,
|
"id" => new NBTTag_String("id", Tile::FURNACE),
|
||||||
"x" => $this->x,
|
"x" => new NBTTag_Int("x", $this->x),
|
||||||
"y" => $this->y,
|
"y" => new NBTTag_Int("y", $this->y),
|
||||||
"z" => $this->z
|
"z" =>new NBTTag_Int("z", $this->z)
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($player->gamemode & 0x01) === 0x01){
|
if(($player->gamemode & 0x01) === 0x01){
|
||||||
@ -93,9 +92,9 @@ class BurningFurnaceBlock extends SolidBlock{
|
|||||||
if($item->isPickaxe() >= 1){
|
if($item->isPickaxe() >= 1){
|
||||||
$drops[] = array(FURNACE, 0, 1);
|
$drops[] = array(FURNACE, 0, 1);
|
||||||
}
|
}
|
||||||
$t = ServerAPI::request()->api->tile->get($this);
|
$t = $this->level->getTile($this);
|
||||||
if($t !== false and $t->class === Tile::FURNACE){
|
if($t instanceof FurnaceTile){
|
||||||
for($s = 0; $s < FURNACE_SLOTS; ++$s){
|
for($s = 0; $s < FurnaceTile::SLOTS; ++$s){
|
||||||
$slot = $t->getSlot($s);
|
$slot = $t->getSlot($s);
|
||||||
if($slot->getID() > AIR and $slot->count > 0){
|
if($slot->getID() > AIR and $slot->count > 0){
|
||||||
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count);
|
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count);
|
||||||
|
@ -26,7 +26,6 @@ class ChestBlock extends TransparentBlock{
|
|||||||
$this->hardness = 15;
|
$this->hardness = 15;
|
||||||
}
|
}
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
$server = ServerAPI::request();
|
|
||||||
$faces = array(
|
$faces = array(
|
||||||
0 => 4,
|
0 => 4,
|
||||||
1 => 2,
|
1 => 2,
|
||||||
@ -45,7 +44,7 @@ class ChestBlock extends TransparentBlock{
|
|||||||
}
|
}
|
||||||
$c = $this->getSide($side);
|
$c = $this->getSide($side);
|
||||||
if(($c instanceof ChestBlock) and $c->getMetadata() === $this->meta){
|
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;
|
$chest = $tile;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -53,15 +52,15 @@ class ChestBlock extends TransparentBlock{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
$tile = $server->api->tile->add($this->level, Tile::CHEST, $this->x, $this->y, $this->z, array(
|
$tile = new ChestTile($this->level, new NBTTag_Compound(false, array(
|
||||||
"Items" => array(),
|
"Items" => new NBTTag_List("Items", array()),
|
||||||
"id" => Tile::CHEST,
|
"id" => new NBTTag_String("id", Tile::CHEST),
|
||||||
"x" => $this->x,
|
"x" => new NBTTag_Int("x", $this->x),
|
||||||
"y" => $this->y,
|
"y" => new NBTTag_Int("y", $this->y),
|
||||||
"z" => $this->z
|
"z" =>new NBTTag_Int("z", $this->z)
|
||||||
));
|
)));
|
||||||
|
|
||||||
if($chest instanceof Tile){
|
if($chest instanceof ChestTile){
|
||||||
$chest->pairWith($tile);
|
$chest->pairWith($tile);
|
||||||
$tile->pairWith($chest);
|
$tile->pairWith($chest);
|
||||||
}
|
}
|
||||||
@ -69,8 +68,8 @@ class ChestBlock extends TransparentBlock{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item, Player $player){
|
public function onBreak(Item $item, Player $player){
|
||||||
$t = ServerAPI::request()->api->tile->get($this);
|
$t = $this->level->getTile($this);
|
||||||
if($t !== false){
|
if($t instanceof ChestTile){
|
||||||
$t->unpair();
|
$t->unpair();
|
||||||
}
|
}
|
||||||
$this->level->setBlock($this, new AirBlock(), true, true, true);
|
$this->level->setBlock($this, new AirBlock(), true, true, true);
|
||||||
@ -83,19 +82,18 @@ class ChestBlock extends TransparentBlock{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$server = ServerAPI::request();
|
$t = $this->level->getTile($this);
|
||||||
$t = $server->api->tile->get($this);
|
|
||||||
$chest = false;
|
$chest = false;
|
||||||
if($t !== false){
|
if($t instanceof ChestTile){
|
||||||
$chest = $t;
|
$chest = $t;
|
||||||
}else{
|
}else{
|
||||||
$chest = $server->api->tile->add($this->level, Tile::CHEST, $this->x, $this->y, $this->z, array(
|
$chest = new ChestTile($this->level, new NBTTag_Compound(false, array(
|
||||||
"Items" => array(),
|
"Items" => new NBTTag_List("Items", array()),
|
||||||
"id" => Tile::CHEST,
|
"id" => new NBTTag_String("id", Tile::CHEST),
|
||||||
"x" => $this->x,
|
"x" => new NBTTag_Int("x", $this->x),
|
||||||
"y" => $this->y,
|
"y" => new NBTTag_Int("y", $this->y),
|
||||||
"z" => $this->z
|
"z" =>new NBTTag_Int("z", $this->z)
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -112,9 +110,9 @@ class ChestBlock extends TransparentBlock{
|
|||||||
$drops = array(
|
$drops = array(
|
||||||
array($this->id, 0, 1),
|
array($this->id, 0, 1),
|
||||||
);
|
);
|
||||||
$t = ServerAPI::request()->api->tile->get($this);
|
$t = $this->level->getTile($this);
|
||||||
if($t !== false and $t->class === Tile::CHEST){
|
if($t instanceof ChestTile){
|
||||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
for($s = 0; $s < ChestTile::SLOTS; ++$s){
|
||||||
$slot = $t->getSlot($s);
|
$slot = $t->getSlot($s);
|
||||||
if($slot->getID() > AIR and $slot->count > 0){
|
if($slot->getID() > AIR and $slot->count > 0){
|
||||||
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count);
|
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count);
|
||||||
|
@ -98,14 +98,6 @@ class PMFLevel extends PMF{
|
|||||||
private function createBlank(){
|
private function createBlank(){
|
||||||
$this->saveData();
|
$this->saveData();
|
||||||
@mkdir(dirname($this->file)."/chunks/", 0755);
|
@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(){
|
protected function parseLevel(){
|
||||||
|
@ -38,7 +38,7 @@ class ChestTile extends SpawnableTile{
|
|||||||
|
|
||||||
public function getPair(){
|
public function getPair(){
|
||||||
if($this->isPaired()){
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
@ -54,8 +54,8 @@ class ChestTile extends SpawnableTile{
|
|||||||
$tile->namedtag->pairx = $this->x;
|
$tile->namedtag->pairx = $this->x;
|
||||||
$tile->namedtag->pairz = $this->z;
|
$tile->namedtag->pairz = $this->z;
|
||||||
|
|
||||||
$this->server->api->tile->spawnToAll($this);
|
$this->spawnToAll();
|
||||||
$this->server->api->tile->spawnToAll($tile);
|
$tile->spawnToAll();
|
||||||
$this->server->handle("tile.update", $this);
|
$this->server->handle("tile.update", $this);
|
||||||
$this->server->handle("tile.update", $tile);
|
$this->server->handle("tile.update", $tile);
|
||||||
}
|
}
|
||||||
@ -68,10 +68,10 @@ class ChestTile extends SpawnableTile{
|
|||||||
$tile = $this->getPair();
|
$tile = $this->getPair();
|
||||||
unset($this->namedtag->pairx, $this->namedtag->pairz, $tile->namedtag->pairx, $tile->namedtag->pairz);
|
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);
|
$this->server->handle("tile.update", $this);
|
||||||
if($tile instanceof Tile){
|
if($tile instanceof ChestTile){
|
||||||
$this->server->api->tile->spawnToAll($tile);
|
$tile->spawnToAll();
|
||||||
$this->server->handle("tile.update", $tile);
|
$this->server->handle("tile.update", $tile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class SignTile extends SpawnableTile{
|
|||||||
$this->namedtag->Text2 = $line2;
|
$this->namedtag->Text2 = $line2;
|
||||||
$this->namedtag->Text3 = $line3;
|
$this->namedtag->Text3 = $line3;
|
||||||
$this->namedtag->Text4 = $line4;
|
$this->namedtag->Text4 = $line4;
|
||||||
$this->server->api->tile->spawnToAll($this);
|
$this->spawnToAll();
|
||||||
$this->server->handle("tile.update", $this);
|
$this->server->handle("tile.update", $this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
abstract class SpawnableTile extends Tile{
|
abstract class SpawnableTile extends Tile{
|
||||||
public abstract function spawn(Player $player);
|
public abstract function spawn(Player $player);
|
||||||
|
|
||||||
public function spawnToAll(Tile $t){
|
public function spawnToAll(){
|
||||||
foreach($this->level->getPlayers() as $player){
|
foreach($this->level->getPlayers() as $player){
|
||||||
if($player->eid !== false or $player->spawned !== true){
|
if($player->eid !== false or $player->spawned !== true){
|
||||||
$this->spawn($player);
|
$this->spawn($player);
|
||||||
|
@ -297,7 +297,7 @@ class Level{
|
|||||||
$this->server->api->entity->updateRadius($pos, 3);
|
$this->server->api->entity->updateRadius($pos, 3);
|
||||||
}
|
}
|
||||||
if($tiles === true){
|
if($tiles === true){
|
||||||
if(($t = $this->server->api->tile->get($pos)) !== false){
|
if(($t = $this->getTile($pos)) !== false){
|
||||||
$t->close();
|
$t->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -305,6 +305,21 @@ class Level{
|
|||||||
return $ret;
|
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){
|
public function getMiniChunk($X, $Z, $Y){
|
||||||
if(!isset($this->level)){
|
if(!isset($this->level)){
|
||||||
return false;
|
return false;
|
||||||
|
@ -39,10 +39,8 @@ class WorldGenerator{
|
|||||||
"generatorSettings" => $this->generator->getSettings(),
|
"generatorSettings" => $this->generator->getSettings(),
|
||||||
"extra" => ""
|
"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);
|
$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(){
|
public function generate(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user