1.8.8 V1.8.8 PacketPlayOutBlockBreakAnimation

Discussion in 'Spigot Plugin Development' started by Excendia, Feb 23, 2020.

  1. Hello guys,
    I am working on a break block animation where when i place a new block it breaks after 5 seconds with small cracks increasing. I got it mostly the way i want it but whenever i place a block on the previous location where a block already broke before, the animation starts with full cracks again.

    People with similar problems said that you have to use the same Entity-ID you used before. And since i am either tired or stupid I don't know how to implement it that way. Maybe also useful: using -1 should reset the animation but as mentioned before i don't know how to get started.

    Code:
    Code (Text):

    @EventHandler
    public void placeBlockEvent(BlockPlaceEvent e) {

        Block placedBlock = e.getBlockPlaced();
        Player p = e.getPlayer();


        new BukkitRunnable() {
            int a = 0;
            int i = 0;
           // int b = 0;
            @Override
            public void run() {
                i += 2;
                a++;
               // b++;

                PacketPlayOutBlockBreakAnimation packet = new PacketPlayOutBlockBreakAnimation(new Random().nextInt(5000), new BlockPosition(placedBlock.getX(), placedBlock.getY(), placedBlock.getZ()), i);
                int dimension = ((CraftWorld) p.getWorld()).getHandle().dimension;
                ((CraftServer) e.getPlayer().getServer()).getHandle().sendPacketNearby(placedBlock.getX(), placedBlock.getY(), placedBlock.getZ(), 120, dimension, packet);

                if (a == 5) {
                    this.cancel();
                    placedBlock.breakNaturally();
                }
            }
        }.runTaskTimer(oneLinePlugin, 0, 20);

    }
     
    Simply put.
    I want to somehow "clear" the animation when i place a new block so the block breaks in a usual way.

    I am thankful for any help
     
  2. I guess that first argument in the constructor is entity-id. Just use some constant value like 0, or store your random value(use ThreadLocalRandom.current() instead).
     
    • Like Like x 1
  3. As I see, you randomize the Entity-ID, so I recomend you to store it so you can, after breaking the block, set the breaking animation at coords 0, 0, 0 to clear it, that's what I did.
     
    • Like Like x 1
  4. So if i recall correctly i have to save the id for each block and reaccess it for each block? Since (when I use a constant value) the animation is bugged for all coordinates I used the animation on.
     
  5. I would think the breakNaturally() would do a block state update but maybe you need to send a packet to the client also?