Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Save blocks into file

Comments in 'Plugin Development' started by thebigsmileXD, Nov 19, 2015.

  1. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    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.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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.
  3. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Well, i need to save every highest block (getHighestBlockAt()) and return what block it is. for every loaded chunk
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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);
  5. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Sounds right :) thanks
  6. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    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
  7. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    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);
                    }
                }
            }
        }
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Mind pointing out the error line?
  9. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Yes 243.
  10. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You realize we cant see the line numbers right?
    PEMapModder likes this.
  11. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Whoops, nope. Its the line with buffer{offset} &= $andmask
  12. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  14. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    :p 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?

Share This Page

Advertisement