Replacing blocks within 2 locations

Discussion in 'Plugin Development' started by xLoGiiKzZo, Aug 12, 2013.

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

    xLoGiiKzZo

    I've been trying to replace all blocks that aren't grass with grass within 2 locations.

    Code:java
    1.  
    2. int xS = rm.getRegion(player + "shed2").getMinimumPoint().getBlockX();
    3. int zS = rm.getRegion(player + "shed2").getMinimumPoint().getBlockZ();
    4. int xE = rm.getRegion(player + "shed2").getMaximumPoint().getBlockX();
    5. int zE = rm.getRegion(player + "shed2").getMaximumPoint().getBlockZ();
    6. int y = rm.getRegion(player + "shed2").getMaximumPoint().getBlockY();
    7. for (int x = xS; x <= xE; x++){
    8. for (int z = zS; z <= zE; z++){
    9. Block checkedblock = plugin.getServer().getWorld("world").getBlockAt(xS, y, zS);
    10. if (checkedblock.getType() != Material.GRASS){
    11. checkedblock.setType(Material.GRASS);
    12. }
    13. }
    14. }
    15.  


    The region exists and the variables equal the following:
    xS = -69
    zS = 180
    xE = -53
    zE = 196
    y = 95

    But its not replacing the blocks :/
     
  2. Offline

    AndyMcB1

    while(condition && condition)

    {
    //code
    }
     
  3. Offline

    xTrollxDudex

    xLoGiiKzZo
    Shouldn't getting a block from a built location be easier than that?
     
  4. Offline

    desht

    Two things:
    • Don't repeatedly call getWorld() inside your for loops - that's a lot of unnecessary work for a method whose return value isn't dependent on the loop variables. Call it once before the loops.
    • (the cause of your problem) You're checking the block at (xS, y, zS) each time, but you want to be checking the block at (x, y, z).
     
Thread Status:
Not open for further replies.

Share This Page