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

Get all blocks by id

Comments in 'Plugin Development' started by AndrewBit, Jan 13, 2016.

  1. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    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?
  2. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    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 o_O
    sorry, be more specific if you can
  3. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    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.
  4. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    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
    applqpak likes this.
  5. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    -.-
    is this a troll or what ?
    do you know what you wrote or just copy paste?
  6. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    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($fileserialize($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]));
    }
    AndrewBit and PEMapModder like this.
  7. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    If I have a good method for save all blocks into a yml, is pretty easy add a block near it.
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    What blocks are you even talking about. All the blocks in a level? Your explanation is confusing.
  9. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Get all blocks with the same id and them add it to a yaml
  10. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Get blocks from where? A world?
  11. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    again... do you know "blocks" is plural and "it" is singular !

    IT WHO ?????
  12. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    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 ?
  13. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    That wouldn't work.
    PHP:
    $level->getBlock(new Vector3($x$y$z))->getId()
    applqpak likes this.
  14. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    [​IMG]
    PEMapModder likes this.
  15. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Why are you being salty? I was correcting your mistake, chill.
    iDirtPlayzMC likes this.
  16. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    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
    AndrewBit and PEMapModder like this.
  17. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    do you think this is a competition? ok, you won... nothing
    AndrewBit likes this.
  18. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    I wasn't competing but thanks for the prize :D
    TheDeibo likes this.
  19. TheDeibo
    Offline

    TheDeibo Notable Member Plugin Developer

    Joined:
    Sep 8, 2014
    Posts:
    692
    Plugins:
    1
    Minecraft User:
    TheDeibo
    WHOOP WHOOP WINNER BING BING BING BING! WHOOP WHOOP.
  20. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    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)

Share This Page

Advertisement