Solved Breaking a block with the "breaking effect"

Discussion in 'Plugin Development' started by 4thegame3, Aug 30, 2014.

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

    4thegame3

    i really have no idea where to start, a friend told me somthing about nbt but i cant find anything helpfull.
    My question is, how can i make my plugin break a block with texture change effect?

    PS: sorry for my english

    UPDATE:
    i found this code in a old thread but seems outdated since eclipse cant find the libraries, any ideas?
    Code:
        Packet55BlockBreakAnimation packet = new Packet55BlockBreakAnimation(0, block.getX(), block.getY(), block.getZ(), damage);
        int dimension = ((CraftWorld) player.getWorld()).getHandle().dimension;
        ((CraftServer) player.getServer()).getHandle().sendPacketNearby(block.getX(), block.getY(), block.getZ(), 120, dimension, packet);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  2. Offline

    BillyGalbreath

    Dont use packets where not needed...

    world.playEffect(location, Effect.STEP_SOUND, blockID, radius);
     
  3. Offline

    BlackBeltPanda

    Correct me if I'm wrong, but wouldn't this just play the block break sound? OP wants the block crack animation.

    4thegame3 The code you posted should work if your imports are correct. If you're using Maven, you'll need your CraftBukkit dependency to be above your Bukkit dependency in the pom.xml file.
    I think there's 10 different crack textures, so to get the animation to work I believe you'll need to create a loop and send the packet where "damage" is a number from 1-10, representing the different levels of cracking. You'll need a delay, of course, in each iteration of the loop dependent on how fast you want the animation to play.
     
  4. Offline

    jpjunho

  5. Offline

    BlackBeltPanda

    Are you referring to world.playeffect? If so, that's what I said. =)
    The OP is looking for the cracking animation when you mine a block.
     
  6. Offline

    jpjunho

  7. Offline

    1Rogue Retired Staff


    It will also play the particle effect for the block, however I'm uncertain about showing cracks on a block.

    There's also no way of sending the data in a form of some things like colored wool, etc.
     
  8. Offline

    BlackBeltPanda

    Just tested, it only plays the sound and shows the particles, doesn't display the cracking animation.
     
  9. Offline

    hackercore

    Use block.breakNaturally() ??? with the packet sending code (they should work if you import BOTH the Craftbukkit and the Bukkit jars...)
     
  10. Offline

    4thegame3

    beakNaturally breaks the block and drops it, but witout crack animation, btw i solved that, for the people who has same problem here's the code
    Code:java
    1. PacketPlayOutBlockBreakAnimation packet0 = new PacketPlayOutBlockBreakAnimation(0, block.getX(), block.getY(), block.getZ(), -1);
    2. PacketPlayOutBlockBreakAnimation packet1 = new PacketPlayOutBlockBreakAnimation(0, block.getX(), block.getY(), block.getZ(), 1);
    3. PacketPlayOutBlockBreakAnimation packet2 = new PacketPlayOutBlockBreakAnimation(0, block.getX(), block.getY(), block.getZ(), 2);
    4. PacketPlayOutBlockBreakAnimation packet3 = new PacketPlayOutBlockBreakAnimation(0, block.getX(), block.getY(), block.getZ(), 3);
    5. PacketPlayOutBlockBreakAnimation packet4 = new PacketPlayOutBlockBreakAnimation(0, block.getX(), block.getY(), block.getZ(), 4);
    6. PacketPlayOutBlockBreakAnimation packet5 = new PacketPlayOutBlockBreakAnimation(0, block.getX(), block.getY(), block.getZ(), 5);
    7. PacketPlayOutBlockBreakAnimation packet6 = new PacketPlayOutBlockBreakAnimation(0, block.getX(), block.getY(), block.getZ(), 6);
    8. PacketPlayOutBlockBreakAnimation packet7 = new PacketPlayOutBlockBreakAnimation(0, block.getX(), block.getY(), block.getZ(), 7);
    9.  
    10. loc.getWorld().playSound(loc, Sound.DIG_STONE, 1, 0);
    11. try {
    12. Thread.sleep(700);
    13. } catch (InterruptedException e) {
    14. // TODO Auto-generated catch block
    15. e.printStackTrace();
    16. }
    17. ((CraftServer) player.getServer()).getHandle().sendPacketNearby(
    18. block.getX(), block.getY(), block.getZ(), 120, dimension,
    19. packet2);
    20. loc.getWorld().playSound(loc, Sound.DIG_STONE, 1, 0);
    21. try {
    22. Thread.sleep(700);
    23. } catch (InterruptedException e) {
    24. // TODO Auto-generated catch block
    25. e.printStackTrace();
    26. }
    27. ((CraftServer) player.getServer()).getHandle().sendPacketNearby(
    28. block.getX(), block.getY(), block.getZ(), 120, dimension,
    29. packet3);
    30. loc.getWorld().playSound(loc, Sound.DIG_STONE, 1, 0);
    31. try {
    32. Thread.sleep(700);
    33. } catch (InterruptedException e) {
    34. // TODO Auto-generated catch block
    35. e.printStackTrace();
    36. }
    37. ((CraftServer) player.getServer()).getHandle().sendPacketNearby(
    38. block.getX(), block.getY(), block.getZ(), 120, dimension,
    39. packet4);
    40. loc.getWorld().playSound(loc, Sound.DIG_STONE, 1, 0);
    41. try {
    42. Thread.sleep(700);
    43. } catch (InterruptedException e) {
    44. // TODO Auto-generated catch block
    45. e.printStackTrace();
    46. }
    47. ((CraftServer) player.getServer()).getHandle().sendPacketNearby(
    48. block.getX(), block.getY(), block.getZ(), 120, dimension,
    49. packet5);
    50. loc.getWorld().playSound(loc, Sound.DIG_STONE, 1, 0);
    51. try {
    52. Thread.sleep(700);
    53. } catch (InterruptedException e) {
    54. // TODO Auto-generated catch block
    55. e.printStackTrace();
    56. }
    57. ((CraftServer) player.getServer()).getHandle().sendPacketNearby(
    58. block.getX(), block.getY(), block.getZ(), 120, dimension,
    59. packet6);
    60. loc.getWorld().playSound(loc, Sound.DIG_STONE, 1, 0);
    61. try {
    62. Thread.sleep(700);
    63. } catch (InterruptedException e) {
    64. // TODO Auto-generated catch block
    65. e.printStackTrace();
    66. }
    67. ((CraftServer) player.getServer()).getHandle().sendPacketNearby(
    68. block.getX(), block.getY(), block.getZ(), 120, dimension,
    69. packet7);
    70. loc.getWorld().playSound(loc, Sound.DIG_STONE, 1, 0);
    71. try {
    72. Thread.sleep(700);
    73. } catch (InterruptedException e) {
    74. // TODO Auto-generated catch block
    75. e.printStackTrace();
    76. }
    77.  


    i dont uderstand why i need the trys but whatever
     
  11. Offline

    Techy4198

    4thegame3 big nono right there. NEVER use Thread.sleep() in the main thread in Bukkit. Even if it's in a different thread, use schedulers instead.
     
  12. Offline

    4thegame3

    i used an async task, is that right?
     
  13. Offline

    fireblast709

    4thegame3 aside the huge issue called thread safety
     
    4thegame3 likes this.
  14. Offline

    4thegame3

    damn now im stuck on this
    Code:
    itemStack[cont].
                        setType(Material.
                                getMaterial(id));
    id is 322 but says error null pointer at second line.. (setType(Material.)

    forgot to initialize (facepalm)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
Thread Status:
Not open for further replies.

Share This Page