I would like to save blocks into an.. array kind thing and save them into a file, database or whatever. i would have to do that for 256 blocks PER CHUNK! sooo.. I have the y of the block, the x and the z. And the meta. and id. for 16*16 blocks. per chunk. Any efficient way? Also, when a block changes i would have to update that chunk file. And i must be able to get the data of a block at the specific x-y-z values.
Simply copy the chunk file in the world directory? I don't know how you are using them, but my instinct tells me that it is possible to do that simply by using one of the default file formats in PocketMine and letting them save files without writing any code about binaries or what.
Well, i need to save every highest block (getHighestBlockAt()) and return what block it is. for every loaded chunk
Oh I see. What about something like this? PHP: $X = $chunk->getX();$Z = $chunk->getZ();$buffer = str_repeat("\0", 384);for($x = 0; $x < 16; $x++){ for($z = 0; $z < 16; $z++){ $y = "calculate this integer yourself"; $buffer{($x << 4) | $z} = $chunk->getBlockIdAt($x, $y, $z); $offset = 0x100 | ($x << 3) | ($z >> 1); $andMask = ($z & 1) ? "\x0F" : "\xF0"; $damage = $chunk->getBlockDamageAt($x, $y, $z); $orMask = ($z & 1) ? chr($damage << 4) : chr($damage & 0x0F); $buffer{$offset} &= $andMask; $buffer{$offset} |= $orMask; }}filc_put_contents($dir . "$X:$Z.dat", $buffer);
You cant use ":" in filenames. Also, when i change the ":" to "_", this crash happens: Fatal error: Cannot use assign-op operators with overloaded objects nor string offsets in C:\Users\Administrator\Desktop\Server\MinecraftPE\PocketMine-MP\plugins\DynMapPE\src\thebigsmileXD\DynMapPE\Main.php on line 243 Call Stack: 0.0177 371640 1. {main}() C:\Users\Administrator\Desktop\Server\MinecraftPE\PocketMine-MP\PocketMine-MP.phar:0 0.0205 366816 2. require('phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php') C:\Users\Administrator\Desktop\Server\MinecraftPE\PocketMine-MP\PocketMine-MP.phar:1 0.1541 506672 3. pocketmine\Server->__construct() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php:464 18.2979 21202248 4. pocketmine\Server->start() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1778 18.3418 21225496 5. pocketmine\Server->tickProcessor() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2178 32.5923 21277240 6. pocketmine\Server->tick() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2300 32.5923 21277304 7. pocketmine\Server->checkConsole() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2482 32.5933 21278736 8. pocketmine\Server->dispatchCommand() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1994 32.5933 21278920 9. pocketmine\command\SimpleCommandMap->dispatch() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2015 32.5934 21279160 10. pocketmine\command\PluginCommand->execute() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/command/SimpleCommandMap.php:193 32.5935 21279544 11. thebigsmileXD\DynMapPE\Main->onCommand() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/command/PluginCommand.php:57 32.5941 21279672 12. thebigsmileXD\DynMapPE\Main->saveFiles() C:\Users\Administrator\Desktop\Server\MinecraftPE\PocketMine-MP\plugins\DynMapPE\src\thebigsmileXD\DynMapPE\Main.php:75
This is my current code: PHP: public function saveFiles(){ foreach($this->getServer()->getLevels() as $level){ @mkdir($this->getDataFolder() . "data/" . $level->getName()); $this->getServer()->broadcastMessage($this->getDataFolder() . "data/" . $level->getName()); foreach($level->getChunks() as $chunk){ if($chunk->isLoaded()){ $chunkx = $chunk->getX(); $chunkz = $chunk->getZ(); $buffer = str_repeat("\0", 384); for($x = 0; $x < 16; $x++){ for($z = 0; $z < 16; $z++){ $buffer{($x << 4) | $z} = $chunk->getFullBlock($x, $chunk->getHighestBlockAt($x, $z), $z); $offset = 0x100 | ($x << 3) | ($z >> 1); $andMask = ($z & 1)?"\x0F":"\xF0"; $damage = $chunk->getHighestBlockAt($x, $z); $orMask = ($z & 1)?chr($damage << 4):chr($damage & 0x0F); $buffer{$offset} &= $andMask; $buffer{$offset} |= $orMask; } } $this->getServer()->broadcastMessage($this->getDataFolder() . "data/" . $level->getName() . " / " . $chunkx . "_" . $chunkz . ".dat"); file_put_contents($this->getDataFolder() . "data/" . $level->getName() . " / " . $chunkx . "_" . $chunkz . ".dat", $buffer); } } } }
I totally changed the way the blocks are saved. https://github.com/ImagicalCorp/DynMapPE/blob/master/src/thebigsmileXD/DynMapPE/Main.php And tada: the files save. Still, thanks to everyone!
sure ^^ but it didn't work. May you have a look at it again? I don't know, maybe thats just a php setting that must be changed?