Set Blocks beetwin 2 Locations

Discussion in 'Plugin Development' started by re4ly, Jun 27, 2013.

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

    re4ly

    How can I put blocks between two locations, like the Worldedit command //set?

    Code:
    Location loc1 = new Location(world, x, y, z);
    Location loc2 = new Location(world, x2, y2, z2);
    Does anyone have an idea?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  2. Offline

    skipperguy12

    re4ly
    Well, you'd need a loop. I'm tired, this may not do anything at all, but here's a little like what it will look like (I was too lazy to test, and too lazy to actually define world, so I just initialized it with 0):
    Code:
            int minX = 0, minZ = 0, maxX = 0, maxZ = 0;
            for(int i=minX; i <= maxX; i ++){
                for(int i0=minZ; i0 <= maxZ; i0 ++){
                    Block currentBlock = Bukkit.getWorld("world").getBlockAt(new Location(Bukkit.getWorld("world"), i, 0, i0));
                    currentBlock.setType(Material.BEDROCK);
                }
            }
    That's a bit like what it will look like.

    You can always hook into the WE API, but I have never done that, sorry!

    Edit:
    Also, this will not do anything to y axis, you'll need to add one more loop for that, as of right now, you should see any effects, it'll be setting a square of bedrock at level 0, which is already bedrock. Like I said, you'll need to tweak it!
     
  3. Offline

    re4ly

    Code:java
    1. for(int i=minX; i <= maxX; i ++) {
    2. for(int i0=minZ; i0 <= maxZ; i0 ++){
    3. Block currentBlock = Bukkit.getWorld(worldname).getBlockAt(new Location(Bukkit.getWorld(worldname), i, floory, i0));
    4. currentBlock.setType(Material.STONE);
    5.  
    6. }
    7. }

    it works, thanks.
    But is there another easier way?
     
Thread Status:
Not open for further replies.

Share This Page