Is this meant to work? (Inventory Implementation Question)

So I was playing with inventories a bit, and was wondering if the following is valid:

Player = ...;
EquipmentInventory inventory = player.getInventory().query(EquipmentInventory.class);

Currently, the above throws a ClassCastException, returning an EmptyInventory.

I understand that some stuff is still unimplemented, but I’ve also experienced issues with querying in the wrong places when I work with inventories, so I was wondering if the above code is written correctly, and EquipmentInventory is unimplemented, or if I’m querying in the wrong place. Any help is appreciated, thanks.

Looking at the below diagram, I would assume that my code is correct, but a confirmation would be nice.

(from @mumfrey’s API proposal)

I’m confused as to how it can return a value and throw an exception at the same time.[quote=“Socratic_Phoenix, post:1, topic:13364”]
Currently, the above throws a ClassCastException, returning an EmptyInventory.
[/quote]

Check GitHub:

https://github.com/SpongePowered/SpongeCommon/search?utf8=✓&q=equipmentinventory&type=Code

We couldn’t find any code matching ‘equipmentinventory’

So… not implemented.

@pie_flavor
“Returns a value” is referring to query(). “Throws an exception” is referring to the compiler-generated implicit cast.

Yes that’s what I mean

You will have to call .query(EquipmentInventory.class).first(); to get the inventory. If it’s actually implemented.

Why, the following functions perfectly:

player.getInventory().query(Hotbar.class)

no .first() required…

Well that should be a implementation issue, the query(...); method should return a query Inventory with all the Inventorys of a specific type.

For example: inventory.query(InventoryRow.class); will return a inventory with all the rows in it, and calling first() will return the first InventoryRow.

The way it works now would require you to check casts, because now inventory.query(Hotbar.class).first() returns a Slot, so giving a misleading behaviour.

The first behaviour I explained is also what Mumfrey used on the PR page (‘Inventory methods for executing queries’ section)