Spawn 2x2 cube on location

Discussion in 'Plugin Development' started by Wantsome909, Sep 2, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Wantsome909

    how would i be able to spawn a cube with out a lot of
    Code:java
    1. Location block = new Location(p.getWorld(), 104, 72, 176);
    2. block.getBlock().setType(Material.WOOD);
     
  2. Offline

    tommycake50

    Loop through all the cube blocks?
     
  3. Offline

    newboyhun

    Wantsome909
    Simple loop?
    Use nested for loop, to loop the 2x2 or so.

    for (int x = 0; x < 2; x++) {
    for (int y = 0; y < 2; y++) {
    // set block
    }
    }

    EDIT: late
     
  4. Offline

    The_Doctor_123

    Yeah, just use a bunch of for loops. I have a method I use, but it cannot make cubes with even number lengths since it gets the center block and goes out.

    Code:
    public List<Block> getNearbyBlocks(Location location, int Radius)
        {
            List<Block> Blocks = new ArrayList<Block>();
           
            for (int X = location.getBlockX() - Radius ; X <= location.getBlockX() + Radius ; X++)
            {
                for (int Y = location.getBlockY() - Radius ; Y <= location.getBlockY() + Radius ; Y++)
                {
                    for (int Z = location.getBlockZ() - Radius ; Z <= location.getBlockZ() + Radius ; Z++)
                    {
                        Block block = location.getWorld().getBlockAt(X, Y, Z);
                        Blocks.add(block);
                    }
                }
            }
           
            return Blocks;
        }
    
     
  5. Offline

    Wantsome909

    @newboyhunhow would you set the block? and the location? like i did up there?
     
  6. Offline

    CraftingRealm

    Wantsome909
    Code:java
    1. Location corner1 = new Location(p.getWorld(), 104, 72, 176);
    2. Location corner2 = new Location(p.getWorld(), 105, 73, 177);
    3. for (int x = corner1.getX(); x<=corner2.getY(); x++) {
    4. for (int y = corner1.getY(); y<=corner2.getY(); y++) {
    5. for (int z = corner1.getZ(); z<=corner2.getZ(); z++) {
    6. Location block = new Location(p.getWorld(),x,y,z);
    7. block.setMaterial(Material.WOOD);
    8. }
    9. }
    10. }
     
Thread Status:
Not open for further replies.

Share This Page