Inventory question

I personally have not dabbled in the Inventory API as much as the rest of what Sponge has to offer, but I am starting to. However I have a question.

In the Anvil inventory architecture. A player can type anything into the tiny box before setting that tiny box as the items name.

From

Inventory inv;

How would one get that text (guessing it has something to do with StringProperty) and also is there a event that is triggered when a player types a new character into the string?

It’s just all assumption so don’t expect them to work

First, I would query the appropriate Inventory for the anvil. My best shot would be CraftingInventory, but there are more Inventories here. The thing is, you have to acquire the inventory group via query.

Optional<CraftingInventory> ciOpt = inv.query(QueryOperationTypes.INVENTORY_TYPE.of(CraftingInventory.class));

then, I would say this inventory should contain the input String as an InventoryProperty.

Optional<StringProperty> spOpt = ci.getInventoryProperty(StringProperty.class)

But I never tried it myself.


Plus, I believe the input part (character by character) is client side. So unless you have some custom mods for it, you only get the final input String only

I’m not sure but I think the string in this field is only client side and there is no way to retrieve it until the item is renamed.

That wouldn’t make sense, because the server needs to update the result item.

Minecraft uses a plugin message for this action. The channel is MC|ItemName, and the payload is a string with the name the player has typed in. This packet is sent for each modification of the text field, letter by letter.

1 Like

Thanks. When I get a sec, ill see what I can do to listen for it