diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index b0beab38f..54751d96d 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -191,7 +191,7 @@ class BlockAPI{ } public function init(){ - $this->server->event("server.tick", array($this, "blockUpdateTick")); + $this->server->schedule(1, array($this, "blockUpdateTick"), array(), true); $this->server->api->console->register("give", " [amount]", array($this, "commandHandler")); } @@ -728,11 +728,14 @@ class BlockAPI{ if(!($pos instanceof Block)){ $block = $pos->level->getBlock($pos); }else{ - $block = $pos; + $pos = new Position($pos->x, $pos->y, $pos->z, $pos->level); + $block = $pos->level->getBlock($pos); } $level = $block->onUpdate($type); if($level === BLOCK_UPDATE_NORMAL){ $this->blockUpdateAround($block, $level); + }elseif($level === BLOCK_UPDATE_RANDOM){ + $this->scheduleBlockUpdate($pos, Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); } return $level; } @@ -743,33 +746,27 @@ class BlockAPI{ return false; } - $index = $pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName(); + $index = $pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".$type; $delay = microtime(true) + $delay * 0.05; if(!isset($this->scheduledUpdates[$index])){ - $this->scheduledUpdates[$index] = array( - $pos, - $type, - $delay, - ); - $this->server->query("INSERT INTO blockUpdates (x, y, z, level, delay) VALUES (".$pos->x.", ".$pos->y.", ".$pos->z.", '".$pos->level->getName()."', ".$delay.");"); + $this->scheduledUpdates[$index] = $pos; + $this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES (".$pos->x.", ".$pos->y.", ".$pos->z.", '".$pos->level->getName()."', ".$type.", ".$delay.");"); return true; } return false; } - public function blockUpdateTick($time, $event){ - if($event !== "server.tick"){ //WTF?? - return; - } + public function blockUpdateTick(){ + $time = microtime(true); if(count($this->scheduledUpdates) > 0){ - $update = $this->server->query("SELECT x,y,z,level FROM blockUpdates WHERE delay <= ".$time.";"); + $update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= ".$time.";"); if($update !== false and $update !== true){ while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){ - $index = $up["x"].".".$up["y"].".".$up["z"].".".$up["level"]; + $index = $up["x"].".".$up["y"].".".$up["z"].".".$up["level"].".".$up["type"]; if(isset($this->scheduledUpdates[$index])){ - $up = $this->scheduledUpdates[$index]; + $upp = $this->scheduledUpdates[$index]; unset($this->scheduledUpdates[$index]); - $this->blockUpdate($up[0], $up[1]); + $this->blockUpdate($upp, (int) $up["type"]); } } } diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 301b7e601..1de55bd28 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -104,6 +104,7 @@ class LevelAPI{ } $gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):(int) $seed); $gen->generate(); + $gen->close(); return true; } @@ -159,7 +160,8 @@ class LevelAPI{ @rename($path."tileEntities.yml", $path."tiles.yml"); } $tiles = new Config($path."tiles.yml", CONFIG_YAML); - $this->levels[$name] = new Level($level, $entities, $tiles, $name); + $blockUpdates = new Config($path."bupdates.yml", CONFIG_YAML); + $this->levels[$name] = new Level($level, $entities, $tiles, $blockUpdates, $name); foreach($entities->getAll() as $entity){ if(!isset($entity["id"])){ break; @@ -195,6 +197,11 @@ class LevelAPI{ } $t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile); } + + $timeu = microtime(true); + foreach($blockUpdates->getAll() as $bupdate){ + $this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), $bupdate["delay"], (int) $bupdate["type"]); + } return true; } diff --git a/src/Player.php b/src/Player.php index b14425a15..18ce20cbe 100644 --- a/src/Player.php +++ b/src/Player.php @@ -742,8 +742,8 @@ class Player{ $this->lag = array(); $this->sendBuffer(); if($this->packetLoss >= PLAYER_MAX_PACKET_LOSS){ - $this->sendChat("Your connection suffers high packet loss"); - $this->close("packet.loss"); + //$this->sendChat("Your connection suffers high packet loss"); + //$this->close("packet.loss"); } $this->lastMeasure = microtime(true); } diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index d1e79215c..dcddaec33 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -122,7 +122,7 @@ class PocketMinecraftServer{ $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, delay NUMERIC);"); + $this->query("CREATE TABLE blockUpdates (level TEXT, x INTEGER, y INTEGER, z INTEGER, type INTEGER, delay NUMERIC);"); //$this->query("PRAGMA synchronous = OFF;"); $this->preparedSQL->selectHandlers = $this->database->prepare("SELECT DISTINCT ID FROM handlers WHERE name = :name ORDER BY priority DESC;"); $this->preparedSQL->selectActions = $this->database->prepare("SELECT ID,code,repeat FROM actions WHERE last <= (:time - interval);"); diff --git a/src/material/block/ore/GlowingRedstoneOre.php b/src/material/block/ore/GlowingRedstoneOre.php index dea47a597..e19557708 100644 --- a/src/material/block/ore/GlowingRedstoneOre.php +++ b/src/material/block/ore/GlowingRedstoneOre.php @@ -35,7 +35,7 @@ class GlowingRedstoneOreBlock extends SolidBlock{ $this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false); return BLOCK_UPDATE_WEAK; }else{ - $this->level->scheduleBlockUpdate($this, mt_rand(45, 100)); + $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); } return false; } diff --git a/src/material/block/ore/RedstoneOre.php b/src/material/block/ore/RedstoneOre.php index d7ad0557a..0fbba670a 100644 --- a/src/material/block/ore/RedstoneOre.php +++ b/src/material/block/ore/RedstoneOre.php @@ -33,7 +33,7 @@ class RedstoneOreBlock extends SolidBlock{ public function onUpdate($type){ if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){ $this->level->setBlock($this, BlockAPI::get(GLOWING_REDSTONE_ORE, $this->meta), false); - $this->level->scheduleBlockUpdate($this, mt_rand(45, 100)); + $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); return BLOCK_UPDATE_WEAK; } return false; diff --git a/src/material/block/plant/Cactus.php b/src/material/block/plant/Cactus.php index 0b4cea186..925475522 100644 --- a/src/material/block/plant/Cactus.php +++ b/src/material/block/plant/Cactus.php @@ -26,19 +26,37 @@ the Free Software Foundation, either version 3 of the License, or */ class CactusBlock extends TransparentBlock{ - public function __construct(){ - parent::__construct(CACTUS, 0, "Cactus"); + public function __construct($meta = 0){ + parent::__construct(CACTUS, $meta, "Cactus"); $this->isFullBlock = false; } public function onUpdate($type){ if($type === BLOCK_UPDATE_NORMAL){ - $down = $this->getSide(0)->getID(); - if($down !== SAND and $down !== CACTUS){ //Replace wit common break method - ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); + $down = $this->getSide(0); + if($down->getID() !== SAND and $down->getID() !== CACTUS){ //Replace wit common break method $this->level->setBlock($this, new AirBlock(), false); + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); return BLOCK_UPDATE_NORMAL; } + }elseif($type === BLOCK_UPDATE_RANDOM){ + if($this->getSide(0)->getID() !== CACTUS){ + if($this->meta == 0x0F){ + for($y = 1; $y < 3; ++$y){ + $b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); + if($b->getID() === AIR){ + $this->level->setBlock($b, new CactusBlock()); + break; + } + } + $this->meta = 0; + $this->level->setBlock($this, $this); + }else{ + ++$this->meta; + $this->level->setBlock($this, $this); + } + return BLOCK_UPDATE_RANDOM; + } } return false; } @@ -51,11 +69,17 @@ class CactusBlock extends TransparentBlock{ $block2 = $this->getSide(4); $block3 = $this->getSide(5); if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){ - $this->level->setBlock($block, $this); + $this->level->setBlock($this, $this); + $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); return true; } } return false; } + public function getDrops(Item $item, Player $player){ + return array( + array($this->id, 0, 1), + ); + } } \ No newline at end of file diff --git a/src/material/block/plant/MelonStem.php b/src/material/block/plant/MelonStem.php index 86cbc51c6..6e8c7f51e 100644 --- a/src/material/block/plant/MelonStem.php +++ b/src/material/block/plant/MelonStem.php @@ -34,6 +34,7 @@ class MelonStemBlock extends FlowableBlock{ $down = $this->getSide(0); if($down->getID() === FARMLAND){ $this->level->setBlock($block, $this); + $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); return true; } return false; @@ -46,6 +47,27 @@ class MelonStemBlock extends FlowableBlock{ $this->level->setBlock($this, new AirBlock(), false); return BLOCK_UPDATE_NORMAL; } + }elseif($type === BLOCK_UPDATE_RANDOM){ + if(mt_rand(0, 2) == 1){ + if($this->meta < 0x07){ + ++$this->meta; + $this->level->setBlock($this, $this); + return BLOCK_UPDATE_RANDOM; + }else{ + for($side = 2; $side <= 5; ++$side){ + $b = $this->getSide($side); + if($b->getID() === MELON_BLOCK){ + return BLOCK_UPDATE_RANDOM; + } + } + $side = $this->getSide(mt_rand(2,5)); + $d = $side->getSide(0); + if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){ + $this->level->setBlock($side, new MelonBlock()); + } + } + } + return BLOCK_UPDATE_RANDOM; } return false; } diff --git a/src/material/block/plant/Sapling.php b/src/material/block/plant/Sapling.php index 143c1bd47..d48007064 100644 --- a/src/material/block/plant/Sapling.php +++ b/src/material/block/plant/Sapling.php @@ -46,6 +46,7 @@ class SaplingBlock extends FlowableBlock{ $down = $this->getSide(0); if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){ $this->level->setBlock($block, $this); + $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); return true; } return false; @@ -65,12 +66,17 @@ class SaplingBlock extends FlowableBlock{ $this->level->setBlock($this, new AirBlock(), false); return BLOCK_UPDATE_NORMAL; } - }elseif($type === BLOCK_UPDATE_RANDOM and mt_rand(0,2) === 0){ //Growth - if(($this->meta & 0x08) === 0x08){ - TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03); + }elseif($type === BLOCK_UPDATE_RANDOM){ //Growth + if(mt_rand(1,7) === 1){ + if(($this->meta & 0x08) === 0x08){ + TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03); + }else{ + $this->meta |= 0x08; + $this->level->setBlock($this, $this); + return BLOCK_UPDATE_RANDOM; + } }else{ - $this->meta |= 0x08; - $this->level->setBlock($this, $this); + return BLOCK_UPDATE_RANDOM; } return true; } diff --git a/src/material/block/plant/Sugarcane.php b/src/material/block/plant/Sugarcane.php index b10edbdc4..e185fd8e5 100644 --- a/src/material/block/plant/Sugarcane.php +++ b/src/material/block/plant/Sugarcane.php @@ -26,8 +26,8 @@ the Free Software Foundation, either version 3 of the License, or */ class SugarcaneBlock extends FlowableBlock{ - public function __construct(){ - parent::__construct(SUGARCANE_BLOCK, 0, "Sugarcane"); + public function __construct($meta = 0){ + parent::__construct(SUGARCANE_BLOCK, $meta, "Sugarcane"); } public function getDrops(Item $item, Player $player){ @@ -38,11 +38,30 @@ class SugarcaneBlock extends FlowableBlock{ public function onUpdate($type){ if($type === BLOCK_UPDATE_NORMAL){ - if($this->getSide(0)->isTransparent === true){ //Replace wit common break method + $down = $this->getSide(0); + if($down->isTransparent === true and $down->getID() !== SUGARCANE_BLOCK){ //Replace wit common break method ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE)); $this->level->setBlock($this, new AirBlock(), false); return BLOCK_UPDATE_NORMAL; } + }elseif($type === BLOCK_UPDATE_RANDOM){ + if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){ + if($this->meta === 0x0F){ + for($y = 1; $y < 3; ++$y){ + $b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); + if($b->getID() === AIR){ + $this->level->setBlock($b, new SugarcaneBlock()); + break; + } + } + $this->meta = 0; + $this->level->setBlock($this, $this); + }else{ + ++$this->meta; + $this->level->setBlock($this, $this); + } + return BLOCK_UPDATE_RANDOM; + } } return false; } @@ -53,19 +72,19 @@ class SugarcaneBlock extends FlowableBlock{ $this->level->setBlock($block, new SugarcaneBlock()); return true; }elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){ - $block0 = $this->getSide(2); - $block1 = $this->getSide(3); - $block2 = $this->getSide(4); - $block3 = $this->getSide(5); - if($block0->getID() === WATER or $block0->getID() === STILL_WATER - or $block1->getID() === WATER or $block1->getID() === STILL_WATER - or $block2->getID() === WATER or $block2->getID() === STILL_WATER - or $block3->getID() === WATER or $block3->getID() === STILL_WATER){ + $block0 = $down->getSide(2); + $block1 = $down->getSide(3); + $block2 = $down->getSide(4); + $block3 = $down->getSide(5); + if(($block0 instanceof WaterBlock) + or ($block1 instanceof WaterBlock) + or ($block2 instanceof WaterBlock) + or ($block3 instanceof WaterBlock)){ $this->level->setBlock($block, new SugarcaneBlock()); + $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); return true; } } return false; } - } \ No newline at end of file diff --git a/src/material/block/plant/Wheat.php b/src/material/block/plant/Wheat.php index 33ec972ce..bc51d687a 100644 --- a/src/material/block/plant/Wheat.php +++ b/src/material/block/plant/Wheat.php @@ -35,6 +35,7 @@ class WheatBlock extends FlowableBlock{ $down = $this->getSide(0); if($down->getID() === FARMLAND){ $this->level->setBlock($block, $this); + $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); return true; } return false; @@ -56,6 +57,16 @@ class WheatBlock extends FlowableBlock{ $this->level->setBlock($this, new AirBlock(), false); return BLOCK_UPDATE_NORMAL; } + }elseif($type === BLOCK_UPDATE_RANDOM){ + if(mt_rand(0, 2) == 1){ + if($this->meta < 0x07){ + ++$this->meta; + $this->level->setBlock($this, $this); + return BLOCK_UPDATE_RANDOM; + } + }else{ + return BLOCK_UPDATE_RANDOM; + } } return false; } diff --git a/src/pmf/Level.php b/src/pmf/Level.php index 03fd67f53..8294e573f 100644 --- a/src/pmf/Level.php +++ b/src/pmf/Level.php @@ -356,6 +356,7 @@ class PMFLevel extends PMF{ }else{ $m = ($meta << 4) | ($old_m & 0x0F); } + if($old_b !== $block or $old_m !== $m){ $this->chunks[$index][$Y]{$bindex} = chr($block); $this->chunks[$index][$Y]{$mindex} = chr($m); diff --git a/src/utils/Utils.php b/src/utils/Utils.php index a739fdbb4..ccada9bb8 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -107,6 +107,10 @@ class Utils{ public static function writeTriad($value){ return substr(pack("N", $value), 1); } + + public static function getRandomUpdateTicks(){ + return -log(lcg_value())*1365.4; //Poisson distribution (1/(68.27 * 20)) + } public static function writeMetadata($data){ $m = ""; diff --git a/src/world/Level.php b/src/world/Level.php index 9bb37ac63..812b49888 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -26,14 +26,15 @@ the Free Software Foundation, either version 3 of the License, or */ class Level{ - public $entities, $tiles, $nextSave, $players = array(); + public $entities, $tiles, $blockUpdates, $nextSave, $players = array(); private $level, $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount; - public function __construct(PMFLevel $level, Config $entities, Config $tiles, $name){ + public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ $this->server = ServerAPI::request(); $this->level = $level; $this->entities = $entities; $this->tiles = $tiles; + $this->blockUpdates = $blockUpdates; $this->startTime = $this->time = (int) $this->level->getData("time"); $this->nextSave = $this->startCheck = microtime(true); $this->nextSave += 90; @@ -116,7 +117,7 @@ class Level{ $this->level->unloadChunk((int) array_pop($X), (int) $Z, $this->server->saveEnabled); } } - $this->save(); + $this->save(false, false); } } @@ -126,40 +127,23 @@ class Level{ unset($this->level); } - public function save($force = false){ + public function save($force = false, $extra = true){ if(!isset($this->level)){ return false; } if($this->server->saveEnabled === false and $force === false){ return; } - $entities = array(); - foreach($this->server->api->entity->getAll($this) as $entity){ - if($entity->class === ENTITY_MOB){ - $entities[] = array( - "id" => $entity->type, - "Color" => @$entity->data["Color"], - "Sheared" => @$entity->data["Sheared"], - "Health" => $entity->health, - "Pos" => array( - 0 => $entity->x, - 1 => $entity->y, - 2 => $entity->z, - ), - "Rotation" => array( - 0 => $entity->yaw, - 1 => $entity->pitch, - ), - ); - }elseif($entity->class === ENTITY_OBJECT){ - if($entity->type === OBJECT_PAINTING){ + + if($extra !== false){ + $entities = array(); + foreach($this->server->api->entity->getAll($this) as $entity){ + if($entity->class === ENTITY_MOB){ $entities[] = array( "id" => $entity->type, - "TileX" => $entity->x, - "TileX" => $entity->y, - "TileX" => $entity->z, + "Color" => @$entity->data["Color"], + "Sheared" => @$entity->data["Sheared"], "Health" => $entity->health, - "Motive" => $entity->data["Motive"], "Pos" => array( 0 => $entity->x, 1 => $entity->y, @@ -170,65 +154,99 @@ class Level{ 1 => $entity->pitch, ), ); - }else{ + }elseif($entity->class === ENTITY_OBJECT){ + if($entity->type === OBJECT_PAINTING){ + $entities[] = array( + "id" => $entity->type, + "TileX" => $entity->x, + "TileX" => $entity->y, + "TileX" => $entity->z, + "Health" => $entity->health, + "Motive" => $entity->data["Motive"], + "Pos" => array( + 0 => $entity->x, + 1 => $entity->y, + 2 => $entity->z, + ), + "Rotation" => array( + 0 => $entity->yaw, + 1 => $entity->pitch, + ), + ); + }else{ + $entities[] = array( + "id" => $entity->type, + "Health" => $entity->health, + "Pos" => array( + 0 => $entity->x, + 1 => $entity->y, + 2 => $entity->z, + ), + "Rotation" => array( + 0 => $entity->yaw, + 1 => $entity->pitch, + ), + ); + } + }elseif($entity->class === ENTITY_FALLING){ $entities[] = array( "id" => $entity->type, "Health" => $entity->health, + "Tile" => $entity->data["Tile"], + "Pos" => array( + 0 => $entity->x, + 1 => $entity->y, + 2 => $entity->z, + ), + "Rotation" => array( + 0 => 0, + 1 => 0, + ), + ); + }elseif($entity->class === ENTITY_ITEM){ + $entities[] = array( + "id" => 64, + "Item" => array( + "id" => $entity->type, + "Damage" => $entity->meta, + "Count" => $entity->stack, + ), + "Health" => $entity->health, "Pos" => array( 0 => $entity->x, 1 => $entity->y, 2 => $entity->z, ), "Rotation" => array( - 0 => $entity->yaw, - 1 => $entity->pitch, + 0 => 0, + 1 => 0, ), ); } - }elseif($entity->class === ENTITY_FALLING){ - $entities[] = array( - "id" => $entity->type, - "Health" => $entity->health, - "Tile" => $entity->data["Tile"], - "Pos" => array( - 0 => $entity->x, - 1 => $entity->y, - 2 => $entity->z, - ), - "Rotation" => array( - 0 => 0, - 1 => 0, - ), - ); - }elseif($entity->class === ENTITY_ITEM){ - $entities[] = array( - "id" => 64, - "Item" => array( - "id" => $entity->type, - "Damage" => $entity->meta, - "Count" => $entity->stack, - ), - "Health" => $entity->health, - "Pos" => array( - 0 => $entity->x, - 1 => $entity->y, - 2 => $entity->z, - ), - "Rotation" => array( - 0 => 0, - 1 => 0, - ), - ); } + $this->entities->setAll($entities); + $this->entities->save(); + $tiles = array(); + foreach($this->server->api->tile->getAll($this) as $tile){ + $tiles[] = $tile->data; + } + $this->tiles->setAll($tiles); + $this->tiles->save(); + + $blockUpdates = array(); + $updates = $this->server->query("SELECT x,y,z,type,delay FROM blockUpdates WHERE level = '".$this->getName()."';"); + if($updates !== false and $updates !== true){ + $timeu = microtime(true); + while(($bupdate = $updates->fetchArray(SQLITE3_ASSOC)) !== false){ + $bupdate["delay"] = max(1, ($bupdate["delay"] - $timeu) * 20); + $blockUpdates[] = $bupdate; + } + } + + $this->blockUpdates->setAll($blockUpdates); + $this->blockUpdates->save(); + } - $this->entities->setAll($entities); - $this->entities->save(); - $tiles = array(); - foreach($this->server->api->tile->getAll($this) as $tile){ - $tiles[] = $tile->data; - } - $this->tiles->setAll($tiles); - $this->tiles->save(); $this->level->setData("time", (int) $this->time); $this->level->doSaveRound(); @@ -272,7 +290,7 @@ class Level{ if((($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){ return false; } - + $ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata()); if($ret === true){ if(!($pos instanceof Position)){ diff --git a/src/world/LevelImport.php b/src/world/LevelImport.php index 438bed8b6..1e1c109b7 100644 --- a/src/world/LevelImport.php +++ b/src/world/LevelImport.php @@ -72,7 +72,7 @@ class LevelImport{ "width" => 16, "height" => 8 )); - $chunks = new ChunkParser(); + $chunks = new PocketChunkParser(); $chunks->loadFile($this->path."chunks.dat"); $chunks->loadMap(); for($Z = 0; $Z < 16; ++$Z){ diff --git a/src/world/PocketChunkParser.php b/src/world/PocketChunkParser.php index debbb94c5..ac8591b81 100644 --- a/src/world/PocketChunkParser.php +++ b/src/world/PocketChunkParser.php @@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or */ -class ChunkParser{ +class PocketChunkParser{ private $location, $raw = b"", $file; var $sectorLength = 4096; //16 * 16 * 16 var $chunkLength = 86016; //21 * $sectorLength diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index 08adefaf8..9cb524d62 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -47,7 +47,8 @@ class WorldGenerator{ )); $entities = new Config($this->path."entities.yml", CONFIG_YAML); $tiles = new Config($this->path."tiles.yml", CONFIG_YAML); - $this->level = new Level($level, $entities, $tiles, $name); + $blockUpdates = new Config($this->path."bupdates.yml", CONFIG_YAML); + $this->level = new Level($level, $entities, $tiles, $blockUpdates, $name); } public function generate(){ @@ -66,5 +67,9 @@ class WorldGenerator{ $this->level->setSpawn($this->generator->getSpawn()); $this->level->save(true); } + + public function close(){ + $this->level->close(); + } } \ No newline at end of file