Problem Creating/Offering Custom Keys

Hey there!

I’m simply trying to make my own Keys that I can offer to ItemStacks that contains simple pieces of data. Here’s an example of one of my Keys:

public static final Key<Value<Integer>> SUPPLY = Key.builder()
        .type(TypeTokens.INTEGER_VALUE_TOKEN)
        .id("supply")
        .name("Supply")
        .query(DataQuery.of("", "supply"))
        .build();

And now how I’m offering my Keys to an ItemStack:

ItemStack give = ItemStack.builder().itemType(ItemTypes.STONE).build();
DataTransactionResult result = give.offer(MyKeys.SUPPLY);
System.out.println(result.getType().toString());

The DataTransactionResult always prints as failure. I’m not too sure why here. I don’t have any custom DataManipulators made, but from what I gather from the docs (they’re a bit tricky to understand in terms of Data for me), a custom Key could work without a custom DataManipulator. Any ideas? I appreciate any help!

You sadly do need a data manipulator, need to register the key with the data manipulator using a custom built data builder.

It is tricky to understand from the docs, however I found that pie_flavour’s data example is best for understanding it.

1 Like

To clarify: The key is just a dumb object. It doesn’t know how to store something, or how to serialize it. That’s the DataManipulator's job. In API 8 manipulators are being removed because of how pointlessly confusing they are but for now you need one.

Oh, I see. Okay, that makes more sense then. Off the top of your head, is there any word on an ETA for API 8? In other words, is this (currently) relatively confusing Data API worth learning right now if it’s about to be changed? If API 8 is far off, then I’ll power through this.

Well api 7 is staying around for a while, even after api 8 gets released as api 7 targets mc 1.12.2 which is what mods are all targeting, the last MC that all mods targeted was 1.7.10. So even if api 8+ comes out, server owners will still be asking for api 7 plugins

1 Like

Ah, fair enough. Thanks for the input!