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

Getting All Positions in an Area

Comments in 'Plugin Development' started by MCPEPIG, Jul 9, 2015.

  1. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    How do you get all positions in a certain area. For example, the first position is 1 1 1 and the second is 10 10 10, how do i get all positions in the area?​
  2. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
  3. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    also try to look at AxisAlignedBB i think you find this.
    (thx aliuly xD)
  4. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Example? :p
  5. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Try this:
    PHP:
    $level $this->getServer()->getLevelByName("sample");
    $positions = [];
    for(
    $x 1$x <= 10$x++){
      for(
    $y 1$y <= 10$y++){
        for(
    $z 1$z <= 10$z++){
          
    $positions[] = new Position($x$y$z$level);
        }
      }

    All positions are in the $positions array.
    Andrey Nazarchuk and LDX like this.
  6. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Ok ill try it, thanks!
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't do that. Just process each position one by one. You are wasting memory by making an array just to store so many references to a Level object, and so many objects that may not be collected by GC if you store them.
  8. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Example for your method?
    RekkuzaRage likes this.
  9. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    how do you want to use positions?
  10. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    I wanna set blocks in the area.
  11. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
  12. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    If you want to set blocks try this:
    PHP:
    $level $this->getServer()->getLevelByName("sample");
    for(
    $x 1$x <= 10$x++){
      for(
    $y 1$y <= 10$y++){
        for(
    $z 1$z <= 10$z++){
          
    $level->setBlock(new Vector3($x$y$z), Block::get($id), falsefalse); //the last parameter is to disable around block updating, if you are doing big chnages
        
    }
      }
    }
    LDX likes this.
  13. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    It works, thanks!
  14. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    PEMapModder likes this.

Share This Page

Advertisement