Solved Looping through a large cubic section and more

Discussion in 'Plugin Development' started by 1SmallVille1, May 10, 2013.

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

    1SmallVille1

    So I'm working on a plugin that will cause a mine to collapse around the player. But I'm having troubles with looping through an area around the player. This is the code I have:
    Code:Java
    1. public void loopAndFall(Location loc1, Location loc2, World w) {
    2.  
    3. Bukkit.getServer().broadcastMessage("started loop");
    4.  
    5. int minx = Math.min(loc1.getBlockX(), loc2.getBlockX()), miny = Math
    6. .min(loc1.getBlockY(), loc2.getBlockY()), minz = Math.min(
    7. loc1.getBlockZ(), loc2.getBlockZ()), maxx = Math.max(
    8. loc1.getBlockX(), loc2.getBlockX()), maxy = Math.max(
    9. loc1.getBlockY(), loc2.getBlockY()), maxz = Math.max(
    10. loc1.getBlockY(), loc2.getBlockY());
    11.  
    12. for (int x = minx; x <= maxx; x++) {
    13. Bukkit.getServer().broadcastMessage("first loop");
    14. for (int y = miny; y <= maxy; y++) {
    15. Bukkit.getServer().broadcastMessage("second loop");
    16. for (int z = minz; z <= maxz; z++) {
    17.  
    18. Bukkit.getServer().broadcastMessage("looping...");
    19.  
    20. Block b = w.getBlockAt(x, y, z);
    21.  
    22. if (b.getType() == Material.STONE
    23. || b.getType() == Material.DIRT
    24. || b.getType() == Material.COAL_ORE
    25. || b.getType() == Material.IRON_ORE
    26. || b.getType() == Material.GOLD_ORE
    27. || b.getType() == Material.DIAMOND_ORE
    28. || b.getType() == Material.COBBLESTONE
    29. || b.getType() == Material.EMERALD_ORE
    30. || b.getType() == Material.REDSTONE_ORE
    31. || b.getType() == Material.OBSIDIAN) {
    32.  
    33. Bukkit.getServer().broadcastMessage("correct block");
    34.  
    35. if (w.getBlockAt(x, y - 1, z).getType() == Material.AIR) {
    36.  
    37. Bukkit.getServer().broadcastMessage("falling!");
    38.  
    39. w.spawnFallingBlock(new Location(w, x, y, z),
    40. b.getType(), (byte) 0);
    41.  
    42. }
    43.  
    44. }
    45.  
    46. }
    47. }
    48. }
    49.  
    50. } [Syntax=Java][/Syntax]
     
  2. Offline

    caseif

    What exactly is your problem, and what are the debug messages telling you?
     
  3. Offline

    1SmallVille1

    so what happens is it broadcasts the "first loop" a couple times, spams the "second loop" and never gets to the "looping..."
     
  4. Offline

    1SmallVille1

  5. Offline

    chasechocolate

Thread Status:
Not open for further replies.

Share This Page