Change inventory archetype

When copying inventory, the archetype changes from DOUBLE_CHEST to UNKNOWN.
How would I be able to change that in the Inventory object?

I get the new inventory from the event.getTargetInventory().first(), which returns opened double chest’s inventory, but sets it’s archetype to UNKNOWN.

Kind regards, MGlolenstine

Why are you using .first()? And how are you coping the inventory?

I’m just taking the Inventory that I receive from the above command and store it, and I’m using the Inventory#first() because I believe that it returns the first inventory in the opened “inventory”, in this case first would be the chest’s and the second, next or last would be player’s inventories. Am I wrong in assuming that?

Its not guaranteed. The best idea is to use a Query on the inventory. Take a look at QueryOperationTypes for a guaranteed match.

I don’t seem to understand how I’d be able to get the correct item from the QueryOperationTypes… I tried getting it like this e.getTargetInventory().query(QueryOperationTypes.INVENTORY_TYPE); but to no avail. It returns an inventory class org.spongepowered.common.item.inventory.EmptyInventoryImpl

I found that there exists this method e.getTargetInventory().query(QueryOperationTypes.INVENTORY_TYPE.of(Inventory.class)); but it only gets a CustomInventory class from it, which doesn’t help me at all… I have no idea which inventory that is.

How are you getting the original inventory? Is it directly from a event? Is it from a ChestTileEntity?

The original inventory (player’s and double chest’s) are gotten from the event ClickInventoryEvent.

Is the double chest inventory created by you or is it from a real double chest?

It is created and opened from code.

Whats the inventory.builder code? = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST)
            .property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(id)))

Ah ok. So that isnt creating a double inventory. Its creating a empty inventory. You need to specify a size using InventoryDimension property

But it opens fine, so that isn’t the problem.

It will open fine. Even if its a empty inventory. Trust me its needed

Oh? Ok, will try that.

There have been many issues ive replied to where they are trying to set an item into an inventory and its been classed as an empty inventory because of that issue. You learn to spot it XD

No, still the same problem… = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST)
            .property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(id)))
            .property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9, 6))

This opens the chest the same way, here you have some pics
This is before the inventory opens
This is when it opens for the second time, after being modified

I have my pc next to me. Would you mind sending me your code to create, open and check the inventory? Ill see where it is going wrong?

I wouldn’t mind and I did send it to you in DM, because it’s a lot of code…

Ok. Ill take a look at it in a min. See what i can do.

1 Like