Jump to content

Get the contents of a chest the player has open


Recommended Posts

I'm making a client side mod that doesn't allow you to close chests with certain items in them... however, I've been encountering difficulties in not only finding out when a player opens a chest, but also reading the contents. Here's my code, for reference:

    public void openChest(PlayerInteractEvent event){
        Minecraft.getMinecraft().player.sendMessage(new TextComponentString(Minecraft.getMinecraft().player.openContainer.toString()));
        if (Minecraft.getMinecraft().player.openContainer instanceof ContainerChest) { // verify that it's really a chest
            ContainerChest chest = (ContainerChest)Minecraft.getMinecraft().player.openContainer; // it's now safe to cast
            IInventory inv = chest.getLowerChestInventory();
            //do things with inv


Link to comment
Share on other sites

This topic is now closed to further replies.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.