.

Discussion in 'Plugin Development' started by elementalgodz11, Dec 22, 2013.

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

    elementalgodz11

    .
     

    Attached Files:

  2. Offline

    SunShe

    I think something is wrong here:

    Code:java
    1. if (hasmat) {
    2. if (bmat == mat1) {
    3. length++;
    4. if (mat1 == Material.COBBLESTONE)
    5. block.setType(Material.AIR);
    6. } else {
    7. if (bmat == mat2) {
    8. hasmat = false;
    9. length++;
    10. if (mat1 != Material.COBBLESTONE)
    11. break;
    12. block.setType(Material.AIR);
    13. break;
    14. }
    15. return 0;
    16. }
    17. }


    Your tabulation is so strange... What is this "if (mat1 == Material.COBBLESTONE)" in the middle ? it's hard to understand where is your ends of your "if" tests.

    EDIT: Maybe try to add something to test if the end of your way blocks is a "Stone".

    Your function findBlock scaring me, i'll make you something more clean. give me a moment.

    Ok try something like that:
    I have directly created a void function for removing your cross.

    You can use it like this:
    Code:java
    1. Block block = new Location(player.getWorld(), player.getLocation().getBlockX(), player.getLocation().getBlockY() - 1, player.getLocation().getBlockZ()).getBlock();
    2. RemoveCross(block, mat1, mat2);

    I haven't tested it, but not worry, normally nothing shook deleted if no cross is detected.

    The void procedure:
    Code:java
    1. public void RemoveCross(Block block, Material mat1, Material mat2){
    2. if(block.getType() == Material.OBSIDIAN){
    3.  
    4. int MaxLength = 25;
    5. int BlockX = block.getX();
    6. int BlockY = block.getY();
    7. int BlockZ = block.getZ();
    8. int DecX = 0;
    9. int DecZ = 0;
    10. Block CurBlock = null;
    11.  
    12. // Remove Obsidian
    13. block.setType(Material.AIR);
    14.  
    15. // Check 4 directions around the Obsidian
    16. for(int e = 1; e <= 4; e++){
    17. for(int i = 1; i <= MaxLength; i++){
    18.  
    19. switch(e){
    20. case 1:
    21. DecX = +i;
    22. DecZ = 0;
    23. break;
    24. case 2:
    25. DecX = -i;
    26. DecZ = 0;
    27. break;
    28. case 3:
    29. DecX = 0;
    30. DecZ = +i;
    31. break;
    32. case 4:
    33. DecX = 0;
    34. DecZ = -i;
    35. break;
    36. }
    37.  
    38. // Remove Cobblestone & Stone ( mat1 & mat2 )
    39. CurBlock = block.getWorld().getBlockAt(BlockX + DecX, BlockY, BlockZ + DecZ);
    40. if(CurBlock.getType() == mat1 || CurBlock.getType() == mat2){
    41. CurBlock.setType(Material.AIR);
    42. }else{
    43. i = MaxLength;
    44. }
    45.  
    46. }
    47. }
    48. }
    49. }


    Tell me if this helped you. Happy christmas!
    _

    Thank you.

    You can keep your findBlock and remove the part of your code that removes blocks. Then put my 2 lines of code in it.
    Then... i think your problem will be solved no?

    _

    Normal because mat1 and mat2 need to be set. In your onCommand it's not set, but in your findBlock it is.

    You still can use it like this:
    Code:java
    1. RemoveCross(block, Material.COBBLESTONE, Material.STONE);


    You begin your findBlock by:
    Code:java
    1. boolean hasmat = true;

    I do not know if this is normal...

    And you know, my previous code can be updated if you want, by checking for the OBSIDIAN etc... to not be destroyed etc... we can work on it...

    EDIT:
    then for your OBSIDIAN problem, you need to check here:
    Code:java
    1. if (block.getType().equals(Material.OBSIDIAN)) {


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

    SunShe

    So i rebuilt my previous void and this time, i have tested it and everything works. Fixed your 2 mentionned problems.

    Code:java
    1. public void RemoveCross(Block block, Material mat1, Material mat2){
    2. if(block.getType() == Material.OBSIDIAN){
    3.  
    4. int MaxLength = 25;
    5. int BlockX = block.getX();
    6. int BlockY = block.getY();
    7. int BlockZ = block.getZ();
    8. int DecX = 0;
    9. int DecZ = 0;
    10. int FoundBlocks = 0;
    11. Block blocks[] = new Block[5];
    12.  
    13. // Check 4 directions around the Obsidian
    14. for(int i = 1; i <= MaxLength; i++){
    15. FoundBlocks = 0;
    16.  
    17. for(int e = 1; e <= 4; e++){
    18.  
    19. switch(e){
    20. case 1:
    21. DecX = +i; DecZ = 0;
    22. break;
    23. case 2:
    24. DecX = -i; DecZ = 0;
    25. break;
    26. case 3:
    27. DecX = 0; DecZ = +i;
    28. break;
    29. case 4:
    30. DecX = 0; DecZ = -i;
    31. break;
    32. }
    33.  
    34. // Check if found Cobblestone & Stone ( mat1 & mat2 )
    35. blocks[0] = block.getWorld().getBlockAt(BlockX + DecX, BlockY, BlockZ + DecZ);
    36. if(blocks[0].getType() == mat1 || blocks[0].getType() == mat2){
    37. blocks[e] = blocks[0];
    38. FoundBlocks = FoundBlocks + 1;
    39. }else{
    40. i = MaxLength;
    41. }
    42.  
    43. }
    44.  
    45. // Remove if exactly 4 blocks have been found
    46. if(FoundBlocks == 4){
    47. for(int e = 1; e <= 4; e++){
    48. blocks[e].setType(Material.AIR);
    49. }
    50. // Remove Obsidian if only something as been removed
    51. if(block.getType() == Material.OBSIDIAN){
    52. block.setType(Material.AIR);
    53. }
    54. }
    55.  
    56. }
    57.  
    58. }
    59. }


    Have you read my code?
    Code:java
    1. // Remove if exactly 4 blocks have been found

    That's why.

    This can be changed.
    Code:java
    1. if(FoundBlocks == 4){

    To
    Code:java
    1. if(FoundBlocks >= 1){


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

    SunShe

    The error is here: "for(int e = 1; e > 4; e++){" <-- It's not my code from. You have changed something. Look at my code for the correct line.
     
Thread Status:
Not open for further replies.

Share This Page