Solved Enderchest Open Animation dosent work

Discussion in 'Spigot Plugin Help' started by HGGamers5, Apr 17, 2017.

  1. Hello,

    i want a enderchest open animation but i dosent work it opens and closes directly

    Heres my code what im Using:
    Code (Text):
    BlockPosition pos = new BlockPosition(e.getClickedBlock().getX(), e.getClickedBlock().getY(), e.getClickedBlock().getZ());
    PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(pos, Blocks.ENDER_CHEST, 1, 1);
    (CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
    for a normal chest its working
    and heres my code what im using for a normal chest:
    Code (Text):
     BlockPosition pos = new BlockPosition(e.getClickedBlock().getX(), e.getClickedBlock().getY(), e.getClickedBlock().getZ());
    PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(pos, Blocks.CHEST, 1, 1);
    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
    and no there is no error in the console​
     
    • Optimistic Optimistic x 1
  2. I also searched and found this here
    http://stackoverflow.com/questions/33162265/ender-chest-open-and-close-animation

    Code (Text):
    public static void changeChestState(Location loc, boolean open) {
        byte dataByte = (open) ? (byte) 1 : 0; // The byte of data used for the note and animation packet (1 if true, 0 if false)
        for (Player player : Bukkit.getOnlinePlayers()) {
            player.playNote(loc, (byte) 1, dataByte); // Play the sound
            BlockPosition position = new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); // Create the block position using loc
            // Instantiate animation packet, get NMS Block using getById() and loc.getBlock() (deprecated), the server version may vary
            PacketPlayOutBlockAction blockActionPacket = new PacketPlayOutBlockAction(position, net.minecraft.server.v1_8_R3.Block.getById(loc.getBlock().getTypeId()), (byte) 1, dataByte);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(blockActionPacket); // Send animation packet to CraftPlayer
        }
    }
    Apparently it's the same code, but try it like this
     
  3. thx but already tried this
    its the same
     
    #3 HGGamers5, Apr 17, 2017
    Last edited: Apr 17, 2017
  4. I found a solution if someone also needs that here is the code:
    Code (Text):

    Location location = e.getClickedBlock().getLocation();
    World world = ((CraftWorld) location.getWorld()).getHandle();
    BlockPosition position = new BlockPosition(location.getX(), location.getY(), location.getZ());

    if (e.getClickedBlock().getType() == Material.CHEST) {
         TileEntityChest tileChest = (TileEntityChest) world.getTileEntity(position);
         world.playBlockAction(position, tileChest.w(), 1, 1);
    } else {
         TileEntityEnderChest tileChest = (TileEntityEnderChest) world.getTileEntity(position);
         world.playBlockAction(position, tileChest.w(), 1, 1);
    }