Solved Getting the extended Part of a Piston?

Discussion in 'Plugin Development' started by PreFiXAUT, May 29, 2014.

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

    PreFiXAUT

    Hey Guys, currently I'm struggling with a Problem.
    I'm trying to get the extended Part of a Piston (I already checked if it's powered), the once problem I have is, that I only have a Block-Objective of the Base-Piston. When I'ld search around the the piston for the extended Piston-Tile, I might get another extended Piston-Tile of another Piston.

    I already tried to get the Direction of the Piston, but the gotten Direction via: "b.getLocation().getDirection()" is always the same, doesn't matter how I rotate the Piston. I also tried the b.getBlockFace(BlockObjective) method, but this also only returns the same :/

    I have no more Ideas how I could solve this, I hope someone can help me.

    Thanks in advance, PreFiX / Dominik
     
  2. Offline

    renaud444

    You might want to cast the state of the block to Piston and see what methods there are to use?
    Code:java
    1. Piston piston = block.getState();
     
  3. Offline

    PreFiXAUT

    Where did you get the Piston-class from? I have Bukkit and CraftBukkit (booth 1.7.9) in my buildpath, but this won't show up.
     
  4. Offline

    renaud444

    Sorry, it was just a suggestion, I don't have access to either of the jars, as the repository server is down, and i figured since there is a Chest class, there would be a Piston class.
     
  5. Offline

    whitehooder

    Haven't tested it but it should work. It returns null when the block you give the function isn't a piston and when the piston hasn't extended for some reason.

    Code:java
    1. private Block getExtension(Block piston) {
    2. if (piston.getType() == Material.PISTON_BASE || piston.getType() == Material.PISTON_STICKY_BASE) {
    3. switch(piston.getData()) {
    4. case 0:
    5. // Facing Down
    6. if (piston.getRelative(BlockFace.DOWN).getType() == Material.PISTON_EXTENSION) {
    7. return piston.getRelative(BlockFace.DOWN);
    8. }
    9. break;
    10. case 1:
    11. // Facing Up
    12. if (piston.getRelative(BlockFace.UP).getType() == Material.PISTON_EXTENSION) {
    13. return piston.getRelative(BlockFace.UP);
    14. }
    15. break;
    16. case 2:
    17. // Facing North
    18. if (piston.getRelative(BlockFace.NORTH).getType() == Material.PISTON_EXTENSION) {
    19. return piston.getRelative(BlockFace.NORTH);
    20. }
    21. break;
    22. case 3:
    23. // Facing South
    24. if (piston.getRelative(BlockFace.SOUTH).getType() == Material.PISTON_EXTENSION) {
    25. return piston.getRelative(BlockFace.SOUTH);
    26. }
    27. break;
    28. case 4:
    29. // Facing West
    30. if (piston.getRelative(BlockFace.WEST).getType() == Material.PISTON_EXTENSION) {
    31. return piston.getRelative(BlockFace.WEST);
    32. }
    33. break;
    34. case 5:
    35. // Facing East
    36. if (piston.getRelative(BlockFace.EAST).getType() == Material.PISTON_EXTENSION) {
    37. return piston.getRelative(BlockFace.EAST);
    38. }
    39. break;
    40. }
    41. return null;
    42. }
    43. }
     
  6. Offline

    PreFiXAUT

    Thanks man :) Didn't quiet work, but after some debugging I got the Solution:
    Show Spoiler

    Code:java
    1. @SuppressWarnings("deprecation")
    2. private Block getExtension(Block piston) {
    3. if (piston.getType() == Material.PISTON_BASE || piston.getType() == Material.PISTON_STICKY_BASE) {
    4. Block extension = null;
    5. switch(piston.getData()) {
    6. case 8:
    7. // Facing Down
    8. if (piston.getRelative(BlockFace.DOWN).getType() == Material.PISTON_EXTENSION) {
    9. extension = piston.getWorld().getBlockAt(piston.getLocation().add(0,-1,0));
    10. }
    11. break;
    12. case 9:
    13. // Facing Up
    14. if (piston.getRelative(BlockFace.UP).getType() == Material.PISTON_EXTENSION) {
    15. extension = piston.getWorld().getBlockAt(piston.getLocation().add(0,1,0));
    16. }
    17. break;
    18. case 10:
    19. // Facing North
    20. if (piston.getRelative(BlockFace.NORTH).getType() == Material.PISTON_EXTENSION) {
    21. extension = piston.getWorld().getBlockAt(piston.getLocation().add(0,0,-1));
    22. }
    23. break;
    24. case 11:
    25. // Facing South
    26. if (piston.getRelative(BlockFace.SOUTH).getType() == Material.PISTON_EXTENSION) {
    27. extension = piston.getWorld().getBlockAt(piston.getLocation().add(0,0,1));
    28. }
    29. break;
    30. case 12:
    31. // Facing West
    32. if (piston.getRelative(BlockFace.WEST).getType() == Material.PISTON_EXTENSION) {
    33. extension = piston.getWorld().getBlockAt(piston.getLocation().add(-1,0,0));
    34. }
    35. break;
    36. case 13:
    37. // Facing East
    38. if (piston.getRelative(BlockFace.EAST).getType() == Material.PISTON_EXTENSION) {
    39. extension = piston.getWorld().getBlockAt(piston.getLocation().add(1,0,0));
    40. }
    41. break;
    42. }
    43. return extension;
    44. }
    45. return null;
    46. }

     
    whitehooder likes this.
Thread Status:
Not open for further replies.

Share This Page