h31ix

Untitled

Sep 21st, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. // In event handler
  2. Block block = event.getBlock();
  3. if(block.getType() == Material.STONE) { // Check if block placed was stone
  4. boolean found = true;
  5. Block newBlock;
  6. for(int i=1;i<=4;i++) { // Check +1-4 in x direction
  7. newBlock = block.getRealtive(i, 0, 0);
  8. if(newBlock.getType() != Material.STONE) {
  9. // If any of them are not stone, break and declare false
  10. found = false;
  11. break;
  12. }
  13. }
  14. // At the end of this, if all the blocks were stone, "found" will still be true.
  15. if(!found) {
  16. // Otherwise, try in the opposite x direction (-1-4)
  17. found = true;
  18. for(int i=1;i<=4;i++) {
  19. newBlock = block.getRealtive(-i, 0, 0);
  20. if(newBlock.getType() != Material.STONE) {
  21. found = false;
  22. break;
  23. }
  24. }
  25. }
  26. // Continue for +1-4 z and -1-4 z
  27. if(!found) {
  28. found = true;
  29. for(int i=1;i<=4;i++) {
  30. newBlock = block.getRealtive(0, 0, i);
  31. if(newBlock.getType() != Material.STONE) {
  32. found = false;
  33. break;
  34. }
  35. }
  36. }
  37. if(!found) {
  38. found = true;
  39. for(int i=1;i<=4;i++) {
  40. newBlock = block.getRealtive(0, 0, -i);
  41. if(newBlock.getType() != Material.STONE) {
  42. found = false;
  43. break;
  44. }
  45. }
  46. }
  47. if(found) {
  48. // 4 in a row
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment