Setting a chest to be open?

Discussion in 'Spigot Plugin Development' started by Inkzzz, May 29, 2015.

  1. Inkzzz

    Resource Staff

    How would I set a chest to be open? Thanks.
     
  2. NathanWolf

    Supporter

    As in you want to show the chest inventory to a Player? Or you want the chest block to visually appear to be open?
     
  3. Inkzzz

    Resource Staff

    Visible that it's open
     
  4. I used this in a previous plugin I made. Hope I helped!
    Code (Text):
    public void setOpen(Location loc, boolean open) {
        for (Player p : loc.getWorld().getPlayers()) {
            p.playNote(loc, (byte) 1, (byte) (open ? 1 : 0));
        }
    }
     
  5. Inkzzz

    Resource Staff

    Tried this, didn't work for some reason.
     
  6. Weird... I will look into it.
     
  7. I can't find anything else sorry!
     
  8. I looked into the p.playNote as a bit of a hack when I was trying to do the same but I couldn't get it working. I ended up just sending the packets.
    Code (Text):
    BlockPosition pos = new BlockPosition(chestLocation.getBlockX(), chestLocation.getBlockY(), chestLocation.getBlockZ());
            PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(pos, Blocks.CHEST, 1, 1);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    To close the chest you can change the second 1 to a 0.
    The reason that playNote could work is because the same packet handles chest opening and closing. Take a look at this for the block actions http://wiki.vg/Block_Actions. And here is the protocol info for the PacketPlayOutBlockAction packet http://wiki.vg/Protocol#Block_Action. Unfortunately playNote doesn't take a block (as it shouldnt because its playing a note) so it is working with a NoteBlock and there is no way we can tell it to send it with a chest instead.
     
    • Like Like x 1