Change inventory archetype


#1

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


#2

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


#3

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?


#4

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


#5

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.


#6

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


#7

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


#8

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


#9

It is created and opened from code.


#10

Whats the inventory.builder code?


#11
this.storage = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST)
            .property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(id)))
            .build(stalls);

#12

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


#13

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


#14

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


#15

Oh? Ok, will try that.


#16

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


#17

No, still the same problem…

this.storage = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST)
            .property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(id)))
            .property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9, 6))
            .build(stalls);

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


#18

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?


#19

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


#20

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