Blocks in a line ! please help :)

Discussion in 'Plugin Development' started by Jace_oio, May 19, 2013.

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

    Jace_oio

    Hi,

    How would I loop through a clicked Blocks East side line of Blocks until it hits a special block and check what type the special block is plus checking if the Whole line is for example melons ?

    Any help is appreciated :)

    Best wishes Jace_OiO :)
     
  2. Offline

    Craftiii4

    Get the location of the block, add 1 to x and 1 to y, check if this is melon block. If not then check the next one. Loop until a melon block is found. Once a melon block is found, keep on adding 1 to x and y through another loop (yes a loop within a loop :p) until the block is no longer melon, take away 1 from x and y and that's the location of the last melon block.
     
  3. Offline

    Jace_oio

    Craftiii4 if you have time could I have code example XD Im not that good at loops, unfortunately
    but if you don't have time just let it be and ill try my self :p, but note I have tried looping in 3* hours now :C
    EDIT: 3 hours
    Best wishes Jace_OiO
     
  4. Offline

    Craftiii4

    I have done this before, let me find it ;P
     
  5. Offline

    Jace_oio

    Craftiii4 Okay, thanks alot for the help :)
     
  6. Offline

    Craftiii4

    Here is an example, I use this to change a flag which could go in either -x +x -z +z & +y

    Use it to see how to do it ^^, it won't do what you want to do but it should help you.

    Code:java
    1.  
    2. public static void ChangeFlag(String #hidden#, final Location locationofsponge) {
    3.  
    4. Location locationoffirstwool = locationofsponge;
    5.  
    6. while (locationoffirstwool.getBlock().getType() != Material.WOOL && locationoffirstwool.getY() <= 255) {
    7. locationoffirstwool.add(0, 1, 0);
    8. }
    9.  
    10. final Location locationoffirstwoolfinal = locationoffirstwool;
    11.  
    12. byte flagcolour = 15;
    13.  
    14. if (#hidden#.equals("#secret1#")) {flagcolour = 14;}
    15. if (#hidden#.equals("#secret2#")) {flagcolour = 2;}
    16. if (#hidden#.equals("#secret3#")) {flagcolour = 0;}
    17. if (#hidden#.equals("#secret4#")) {flagcolour = 13;}
    18.  
    19. Location locationon = locationoffirstwoolfinal;
    20.  
    21. if (locationon.getBlock().getType() == Material.WOOL) {
    22. if (locationon.getBlock().getData() == flagcolour)
    23. return;
    24. }
    25.  
    26. while (locationon.getBlock().getType() == Material.WOOL) {
    27.  
    28. locationon.getBlock().setData(flagcolour);
    29.  
    30. final Location currentlocation = locationon;
    31.  
    32. final World world = currentlocation.getWorld();
    33. final double X = currentlocation.getX();
    34. final double Y = currentlocation.getY();
    35. final double Z = currentlocation.getZ();
    36.  
    37. if (true) {
    38. Location newlocation = new Location(world, X, Y, Z);
    39. newlocation.add(1,0,0);
    40. while (newlocation.getBlock().getType() == Material.WOOL) {
    41. newlocation.getBlock().setData(flagcolour);
    42. newlocation.add(1,0,0);
    43. }
    44. }
    45. if (true) {
    46. Location newlocation1 = new Location(world, X, Y, Z);
    47. newlocation1.add(-1,0,0);
    48. while (newlocation1.getBlock().getType() == Material.WOOL) {
    49. newlocation1.getBlock().setData(flagcolour);
    50. newlocation1.add(-1,0,0);
    51. }
    52. }
    53. if (true) {
    54. Location newlocation2 = new Location(world, X, Y, Z);
    55. newlocation2.add(0,0,1);
    56. while (newlocation2.getBlock().getType() == Material.WOOL) {
    57. newlocation2.getBlock().setData(flagcolour);
    58. newlocation2.add(0,0,1);
    59. }
    60. }
    61. if (true) {
    62. Location newlocation3 = new Location(world, X, Y, Z);
    63. newlocation3.add(0,0,-1);
    64. while (newlocation3.getBlock().getType() == Material.WOOL) {
    65. newlocation3.getBlock().setData(flagcolour);
    66. newlocation3.add(0,0,-1);
    67. }
    68. }
    69.  
    70. locationon.add(0,1,0);
    71. }
    72.  
    73. }
    74.  
     
  7. Offline

    Jace_oio

    Craftiii4 I gotta go eat :/ ill try after :)
     
  8. Offline

    Craftiii4

    np ;)
     
Thread Status:
Not open for further replies.

Share This Page