Set/Get/Modify subID of ItemStack?

How I can create ItemStack with subID?
I know, that I can use something like this for stone:
item.offer(Keys.STONE_DATA, StroneTypes.GRANITE),
But I need universal method, how example - for mod items, and for any items that user can set in config.
Config will looks like this:
TYPE: STONE
SUBID: 4

The user would enter in the config:

type = "minecraft:stone[variant=granite]"

You would retrieve:

BlockState type = root.getNode("type").getValue(TypeToken.of(BlockState.class));
1 Like

Thanks, but I have one more question:
How user (or me) can find out what “variant” has item?
For example, how do I find out what “variant” have this items?:

OKay, I try to get diorite and granite… That is what I got:

  1. Code
  2. Config
  3. Log
    What Im doing wrong?

To answer your first question, you should be able to see it from the F3 menu.

For the second one, try making STATE and ITEM_TYPE mutually exclusive (i.e. you check ITEM_TYPE first, and if it’s virtual, then you check STATE instead) - maybe there’s a problem when the BlockState is set when the ItemType has already been set.
Whether this is the solution or not, definitely file a ticket on GitHub, because there’s no way that’s intended behavior.

Also, minor annoyance: Java local variables = camelCase, HOCON keys = kebab-case.

  1. Thanks, it helps to get “variant” of placed block, but not for item in inventory that can`t be placed (how exaple - enchanted golden apple).
    http://imgur.com/a/D4qgI
  2. Now my code and config looks so:

Code
Config
But I still got same exception in console… :frowning:
I need to create issue on github?

Yeah, BlockStates only work on blocks. For items, it won’t be a single value, you’d probably be better off using a config sub-object where keys are Data API Key IDs and values are the respective Key's value.

And yes, you should create an issue on github. I linked the proper spot in my last post.

I highly encourage making an issue on GitHub for this as well because it was confusing me as well. Ran into the same problems and would love to see an “itemstate”

1 Like

I found a bit of a solution, although it’s a bit “hacky”

What you have to do is run .toContainer() on the ItemStack.
Then, with that DataView, run .set(DataQuery.of("UnsafeDamage"),3)
That will set the damage value to 3. Then, you can either…

  • Replace it by…
    • ItemStack.builder().fromContainer(dataView).build()
    • Put it in place of what you were returning?
  • Or just update the dataview…
    • itemStack.setRawData(dataView);
1 Like

Your solution is a little better than mine :slight_smile:
//Mega-shit-code start ConfigurationNode temp_node = node.getNode("TEMP_SPONGE_ITEM_STACK_NODE"); temp_node.getNode("ItemType").setValue(item_type_node.getString()); temp_node.getNode("UnsafeDamage").setValue(sub_id_node.getInt(0)); temp_node.getNode("Count").setValue(quantity_node.getInt(1)); ItemStack item = temp_node.getValue(TypeToken.of(ItemStack.class)); temp_node.setValue(null); //Mega-shit-code end

:dizzy_face: yeah that’s a more little mega shit codey.

1 Like