Getting specific inventory view from the Container object

Documentation for org.spongepowered.api.item.inventory.Container says

  • A Container is effectively a ViewModel for a particular set of
  • {@link Inventory} objects used to allow players to interact
  • with the Inventories, usually via a GUI (the View).

Lets say player is viewing content of a doublechest, how can i get the inventory object representing only the content of the doublechst?

tried container.query(GridInventory.class) but it seems to be returning both inventories - (chest and player - without hotbar ) because MainPlayerInventory inherits from the GridInventory.

There might be a better way, but I’ve found that this returns the chest’s inventory:

GridInventory chestInventory = container.query(GridInventory.class).first();

As you said, querying for GridInventory returns two of them. The first one seems to always be the chest.

If you don’t care about it being a GridInventory, you can just use container.first().