Playing chest/enderchest opening animation

Discussion in 'Plugin Development' started by martijnpold, Oct 10, 2015.

Thread Status:
Not open for further replies.
  1. How do I play the animation of a chest opening? I'm trying to make it so when you click a chest it does not open the inventory but instead play the opening animation.

    I tried if it was possible with ProtocolLib but couldnt get it to work, this was the code i used for that:
    Code:
    CraftPlayer p = (CraftPlayer) on;
    PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction((int)event.getBlock().getLocation().getX(),(int)event.getBlock().getLocation().getY(),(int)event.getBlock().getLocation().getZ(), Blocks.ENDER_CHEST,1,1);
    p.getHandle().playerConnection.sendPacket(packet);
     
  2. Offline

    Zombie_Striker

    @martijnpold
    You should be able to get the Blocks state (Block.getState), cast it to a chest and set it so it is open.
     
  3. @Zombie_Striker
    How do i do this? I never used BlockStates so far, I assume i do something like this?
    Code:
    chest.getBlock().getState().setData(##Chest opening???##);
     
  4. Offline

    Zombie_Striker

    @martijnpold
    http://docs.codelanx.com/Bukkit/1.7.10/
    Bookmark this page. If you want to do anything big with bukkit,this is where you go. (Look under blocks/Chest to find all the methods pertaining to chests.)

    1. Get the chest
    2. Get all the tags pretaining to the chest (getData() should have strings about the data)
    3. Print out all the strings into the chat/command prompt
    4. Look and try to find a tag called "open" or "setOpen" (forget the name so thats why i'm telling you to do this)
    5. Go back to your code and use .setData("open or setOpen", "true") to open the chest
     
  5. Offline

    I Al Istannen

    @Zombie_Striker I don't know what block states have to do with that. There is no blockstate im aware of, that represents an opened chest. It is an animation triggered by a packet.


    @martijnpold I just tried your code. I have a 1.8 test server, so I had to adjust it slightly, but everything worked fine! You can read the documentation about Block actions here and here. Your code worked for me though, are you sure the x, y and z coordinates are right?
     
  6. @I Al Istannen I can't get it to work though for some reason...

    @I Al Istannen Where do I put this code? It does not know any of the methods called in the code...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  7. Offline

    I Al Istannen

    @martijnpold As this involves NMS (net.minecraft.server) you need to add the craftBukkit.jar to your build dependecies. After that, your IDE should be able to import everything you need or you write down the path by hand.
     
  8. Offline

    I Al Istannen

    @martijnpold If you use NMS it is just compatible with ONE version of bukkit/spigot. You can use Reflection or Maven to get around that, but I don't know Maven and Reflection is not really a pretty way and the methods names change in the future.

    If you just want to send packets and don't mind another plugin, try ProtocolLib.
     
Thread Status:
Not open for further replies.

Share This Page