Solved Chest Open Animation - Error

Discussion in 'Plugin Development' started by OllieGardner, Apr 26, 2015.

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

    OllieGardner

    Hello

    I have a weird error when using Protocollib to achieve the chest open animation so that the inventory does not open.

    Code:
    PacketContainer chest = new PacketContainer(PacketType.Play.Server.BLOCK_ACTION);
                    chest.getBlocks().write(0, Material.CHEST);
                    try {
                        ProtocolLibrary.getProtocolManager().sendServerPacket(player, chest);
                    } catch (InvocationTargetException ex) {
                        throw new IllegalStateException("Unable to send packet " + chest, ex);
                    }
    This code is run when a player right clicks a chest and I get an error which forces me to quit the server.

    Error (open)
    [​IMG]


    Can someone tell me what I am doing wrong?

    Thanks :D
     
  2. Offline

    pie_flavor

    @OllieGardner I don't know much about packets but don't you have to put in a location somewhere?
     
  3. Offline

    mine-care

    @pie_flavor I have some experience on packets (not with this specific one thought) but I assume yes indeed a location should be used at a point :/ I cannot find the packet to check the constructor ATM but I will ASAP,
     
  4. Offline

    OllieGardner

  5. Offline

    OllieGardner

    Does anyone know how I would add a location to my code?
     
  6. Offline

    pie_flavor

  7. Offline

    WeeSkilz

    @OllieGardner

    Code:
    PacketContainer chest = new PacketContainer(PacketType.Play.Server.BLOCK_ACTION);
                chest.getBlocks().write(0, Material.CHEST);
                chest.getIntegers().write(0, x);
                chest.getIntegers().write(1, y);
                chest.getIntegers().write(2, z);
                chest.getBytes().write(0, (byte) 1);
                chest.getBytes().write(1, (byte) 1);
                try {
                    ProtocolLibrary.getProtocolManager().sendServerPacket(player, chest);
                } catch (InvocationTargetException ex) {
                    throw new IllegalStateException("Unable to send packet " + chest, ex);
                }
     
  8. Offline

    Konato_K

  9. Offline

    OllieGardner

    @Konato_K Yes tried that but doesn't work in 1.8.

    @WeeSkilz Very close.

    For anyone who would actually like to know how I got it to work.

    Code:
         
       PacketContainer chest = new PacketContainer(PacketType.Play.Server.BLOCK_ACTION);
            chest.getBlocks().write(0, Material.CHEST);
            chest.getBlockPositionModifier().write(0, new BlockPosition(chestLoc.getBlockX(), chestLoc.getBlockY(), chestLoc.getBlockZ()));
            chest.getIntegers().write(0, 1);
            chest.getIntegers().write(1, 1); //1 for open, 0 for close
    
            try {
                ProtocolLibrary.getProtocolManager().sendServerPacket(player, chest, true);
            } catch (InvocationTargetException ex) {
                throw new IllegalStateException("Unable to send packet " + chest, ex);
            }
    You should run the code in a scheduler and run it every tick.
     
Thread Status:
Not open for further replies.

Share This Page