I want get all blocks by ID and next add a block near it. I was trying to add multiple blocks to a .yml, but I think this is not easy, lol. Can anyone help me?
well, i know how to set blocks. but, i do not understand where are you trying to set this block. and, do you know "blocks" is plural and "it" is singular , i' m confused sorry, be more specific if you can
I know how to set a block,. This is not the problem... the problem is that I'm trying to save multiple blocks (x,y,z,level) to a yml.
Code: // Make a file for the island $islandFile = fopen($this->getDataFolder()."Islands/".$name.".txt", "w"); fwrite($islandFile, $randX.", ".$Y.", ".$randZ); $playerFile = fopen($this->getDataFolder()."Players/".$name.".txt", "w"); fwrite($playerFile, $player->getLevel()->getName()); tp player Code: $player->teleport(new Position($randX+4, $Y+10, $randZ+4, $this->getServer()->getLevelByName($levelName))); $player->sendMessage(TextFormat::GREEN . "Welcome to your new island"); $player->sendMessage(TextFormat::GREEN . "If your island didn't spawn,"); $player->sendMessage(TextFormat::GREEN . "Use /is delete"); $player->sendMessage(TextFormat::GREEN . "Then make a new island"); Code: elseif($args[0] == "home"){ if($sender->hasPermission("is") || $sender->hasPermission("is.command") || $sender->hasPermission("is.command.home")){ if(!(file_exists($this->getDataFolder()."Islands/".$sender->getName().".txt"))){ $sender->sendMessage("You don't have an island. Use /is create to make one"); return true; }else{ $level = $this->getServer()->getLevelByName(yaml_parse_file($this->getDataFolder()."Players/".$sender->getName().".txt")); if($level !== null){ $sender->sendMessage(TextFormat::GREEN."Teleporting to your island..."); if($sender->getLevel()->getName() !== $level->getName()){ $sender->sendMessage("You are not in the same world as your island. Use ".TextFormat::YELLOW."/mw tp ".$level->getName().TextFormat::RESET." and try again"); return true; }else{ sleep(5); $sender->teleport(new Vector3(yaml_parse_file($this->getDataFolder()."Islands/".$sender->getName().".txt"))); $sender->sendMessage(TextFormat::GREEN."Done!"); return true; } } Kinda same thing see in first part it save XYZ and then on is home it check xyz and tp player there
only this? do you want to save some blocks in a file? what about " I want get all blocks by ID and next add a block near it. " ? to save blocks you should have a point to start saving like A(1,2,3) . depending on what would you like to save (cube?) you can loop through blocks and save the coords and id of each block in an array like PHP: $array[]= array($x,$y,$z,$id,$meta); at the end you can serialize the array and put it in a file PHP: file_put_contents($file, serialize($array)); blocks to save shouldn't be too much. to set these saved blocks: PHP: foreach( unserialize(file_get_contents($file)) as $block){Level->setBlock(new Vector3($block[0], $block[1],$block[2]), Block::get($block[3],$block[4]));}
just check if the id is the same, if it is, save the block PHP: Level->getBlock(x,y,z)->getId() ...and same to what ?
I think @AndrewBit is not asking for a code to copy-paste, he is asking for an explanation/advice to do that.I was tring to explain him how he can save blocks, surely he can't copy paste the code i wrote , is only to give him an idea, i can't help him anymore because he don't know how to explain what is tring to do. sorry if you feel offended but, i was only tring to tell him he can use the getId() method to get the block id.I wrote it fastly, Vector3 is correct , you are right. but $level should be an instance of pocketmine/level/Level , you don't defined it, andrew can't copy-paste $x - $y - $z doesn't exists a semicolon is needed at the end of the statement or the server will crash
Spoiler Well, thanks Svile, but I'm trying to save a specific block (if id == any) on BlockPlaceEvent. The real problem is that I don't know how to create an multidimensional array in my yaml (with coords and level). ... and sorry if the last day I didn't explain as well my question. I was a bit asleep. x)