How to setblock above another block

Discussion in 'Plugin Development' started by keeper317, Aug 10, 2014.

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

    keeper317

    I need to find an obsidian block in a specific area and then place wool one and two blocks above the obsidian if there is a redstone block up one and two away in the x or z direction.
     
  2. Offline

    Skionz

    That was confusing, mind explaining a bit more clearly?
     
  3. Offline

    artish1

    keeper317

    Do you already have the "specific area" set up? If so then just loop and check if the types of the blocks are obsidian, if it's an obsidian block, then get the location of that Obsidian, and then basically Location#add(x,y,z); is your best friend from here on now.
     
  4. Offline

    Skionz

    Not really sure if this is what you want but here, this check if the block type at loc is obsidian. But yea as artish said just loop through your region and check.
    Code:
    //specific location
    Location loc = new Location(world, 0, 0, 0);
    if(world.getBlockAt(loc).getType() == Material.OBSIDIAN) {
      //place all your wool and redstone stuff or whatever you want
    }
     
  5. Offline

    keeper317

    I am already doing that
    this is my code
    Code:java
    1. public class FieldManagement
    2. {
    3. public static void onGameStart()
    4. {
    5. int dx = (int) Math.abs(Math.abs(Main.field[0].getX()) - Math.abs(Main.field[1].getX()));
    6. int dy = (int) Math.abs(Math.abs(Main.field[0].getY()) - Math.abs(Main.field[1].getY()));
    7. int dz = (int) Math.abs(Math.abs(Main.field[0].getZ()) - Math.abs(Main.field[1].getZ()));
    8. for(int i = 0; i <= dx; i++)
    9. for(int k = 0; k <= dy; k++)
    10. for(int j = 0; j <= dz; j++)
    11. {
    12. if(Main.field[0].getX() < Main.field[1].getX())
    13. {
    14. if(Main.field[0].getY() < Main.field[1].getY())
    15. {
    16. if(Main.field[0].getZ() < Main.field[1].getZ())
    17. testBlock((int) (Main.field[0].getX() + i), (int) (Main.field[0].getY() + k), (int) (Main.field[0].getZ() + j), Main.field[0].getWorld());
    18. else if(Main.field[0].getZ() > Main.field[1].getZ())
    19. testBlock((int) (Main.field[0].getX() + i), (int) (Main.field[0].getY() + k), (int) (Main.field[0].getZ() - j), Main.field[0].getWorld());
    20. }
    21. else if(Main.field[0].getY() > Main.field[1].getY())
    22. {
    23. if(Main.field[0].getZ() < Main.field[1].getZ())
    24. testBlock((int) (Main.field[0].getX() + i), (int) (Main.field[0].getY() - k), (int) (Main.field[0].getZ() + j), Main.field[0].getWorld());
    25. else if(Main.field[0].getZ() > Main.field[1].getZ())
    26. testBlock((int) (Main.field[0].getX() + i), (int) (Main.field[0].getY() - k), (int) (Main.field[0].getZ() - j), Main.field[0].getWorld());
    27. }
    28. }
    29. else if(Main.field[0].getX() > Main.field[1].getX())
    30. {
    31. if(Main.field[0].getY() < Main.field[1].getY())
    32. {
    33. if(Main.field[0].getZ() < Main.field[1].getZ())
    34. testBlock((int) (Main.field[0].getX() - i), (int) (Main.field[0].getY() + k), (int) (Main.field[0].getZ() + j), Main.field[0].getWorld());
    35. else if(Main.field[0].getZ() > Main.field[1].getZ())
    36. testBlock((int) (Main.field[0].getX() - i), (int) (Main.field[0].getY() + k), (int) (Main.field[0].getZ() - j), Main.field[0].getWorld());
    37. }
    38. else if(Main.field[0].getY() > Main.field[1].getY())
    39. {
    40. if(Main.field[0].getZ() < Main.field[1].getZ())
    41. testBlock((int) (Main.field[0].getX() - i), (int) (Main.field[0].getY() - k), (int) (Main.field[0].getZ() + j), Main.field[0].getWorld());
    42. else if(Main.field[0].getZ() > Main.field[1].getZ())
    43. testBlock((int) (Main.field[0].getX() - i), (int) (Main.field[0].getY() - k), (int) (Main.field[0].getZ() - j), Main.field[0].getWorld());
    44. }
    45. }
    46. else if(Main.field[0].getX() == Main.field[1].getX() || Main.field[0].getY() == Main.field[1].getY() || Main.field[0].getZ() == Main.field[1].getZ())
    47. Bukkit.broadcastMessage("Set field start and end!");
    48. }
    49. }
    50. public static void testBlock(int x, int y, int z, World world)
    51. {
    52. Block tester = world.getBlockAt(x, y, z);
    53. if(tester.getType() == Material.CHEST)
    54. {
    55. Chest c = (Chest) tester.getState();
    56. if(c.getInventory().getTitle().equalsIgnoreCase("Archery"))
    57. Misc.setBlock(tester.getLocation(), Inventories.Archers);
    58. else if(c.getInventory().getTitle().equalsIgnoreCase("Potions"))
    59. Misc.setBlock(tester.getLocation(), Inventories.potions);
    60. else if(c.getInventory().getTitle().equalsIgnoreCase("Loot1"))
    61. Misc.setBlock(tester.getLocation(), Inventories.loot1);
    62. else if(c.getInventory().getTitle().equalsIgnoreCase("Loot2"))
    63. Misc.setBlock(tester.getLocation(), Inventories.loot2);
    64. else if(c.getInventory().getTitle().equalsIgnoreCase("Secret"))
    65. Misc.setBlock(tester.getLocation(), Inventories.secret);
    66. }
    67. else if(tester.getType() == Material.OBSIDIAN)
    68. {
    69. Bukkit.broadcastMessage("Found Obsidian");
    70. if(world.getBlockAt(x-2, y+1, z-2).getType() == Material.REDSTONE_BLOCK)
    71. for(int i = 1; i<=2; i++)
    72. {
    73. Bukkit.broadcastMessage("Found a RedStone Block");
    74. world.getBlockAt(x, y+1, z).setType(Material.WOOL);
    75. }
    76. else if(world.getBlockAt(x-2, y+1, z+2).getType() == Material.REDSTONE_BLOCK)
    77. for(int i = 1; i<=2; i++)
    78. {
    79. Bukkit.broadcastMessage("Found a RedStone Block");
    80. world.getBlockAt(x, y+1, z).setType(Material.WOOL);
    81.  
    82. }
    83. else if(world.getBlockAt(x+2, y+1, z-2).getType() == Material.REDSTONE_BLOCK)
    84. for(int i = 1; i<=2; i++)
    85. {
    86. Bukkit.broadcastMessage("Found a RedStone Block");
    87. world.getBlockAt(x, y+1, z).setType(Material.WOOL);
    88.  
    89. }
    90. else if(world.getBlockAt(x+2, y+1, z+2).getType() == Material.REDSTONE_BLOCK)
    91. for(int i = 1; i<=2; i++)
    92. {
    93. Bukkit.broadcastMessage("Found a RedStone Block");
    94. world.getBlockAt(x, y+1, z).setType(Material.WOOL);
    95.  
    96. }
    97. else if(world.getBlockAt(x-2, y+1, z-2).getType() == Material.LAPIS_BLOCK)
    98. for(int i = 1; i<=2; i++)
    99. {
    100. Bukkit.broadcastMessage("Found a RedStone Block");
    101. world.getBlockAt(x, y+1, z).setType(Material.WOOL);
    102. }
    103. else if(world.getBlockAt(x-2, y+1, z+2).getType() == Material.LAPIS_BLOCK)
    104. for(int i = 1; i<=2; i++)
    105. {
    106. Bukkit.broadcastMessage("Found a RedStone Block");
    107. world.getBlockAt(x, y+1, z).setType(Material.WOOL);
    108. }
    109. else if(world.getBlockAt(x+2, y+1, z-2).getType() == Material.LAPIS_BLOCK)
    110. for(int i = 1; i<=2; i++)
    111. {
    112. Bukkit.broadcastMessage("Found a RedStone Block");
    113. world.getBlockAt(x, y+1, z).setType(Material.WOOL);
    114. }
    115. else if(world.getBlockAt(x+2, y+1, z+2).getType() == Material.LAPIS_BLOCK)
    116. for(int i = 1; i<=2; i++)
    117. {
    118. Bukkit.broadcastMessage("Found a RedStone Block");
    119. world.getBlockAt(x, y+1, z).setType(Material.WOOL);
    120. }
    121. }
    122. }
    123. }
    124.  


    bump

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

    ZodiacTheories

    keeper317

    Then what are you trying to do?
     
  7. Offline

    keeper317

    Currently i am trying to on the start of a minigame placing two red wool blocks above an obsidian block that has a redstone block one block above and 2 blocks away in either the x or z axis
    the code that i am using is in an earlier post. When the game starts it finds the obsidian but not the redstone block and does not place wool.

    bump

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

    keeper317

    bump
    why does everyone just ask what what what? No one is helpful anymore.
     
Thread Status:
Not open for further replies.

Share This Page