How can I get & set ItemStack to ConfigurationNode in sponge 8.0?

In Sponge 7.0 I can set ItemStack to ConfigurationNode by this code.

ItemStack item;
ConfigurationNode node;

node.setValue(TypeToken.of(ItemStack.class), item);

but In sponge 8.0 I use this code.

node.set(item);
or
node.set(ItemStack.class, item);

It throws error on console

org.spongepowered.configurate.serialize.SerializationException: [item, 1, itemStack] of type net.minecraft.item.ItemStack: No serializer available for type class net.minecraft.item.ItemStack

How can I get & set ItemStack to ConfigurationNode in sponge 8.0 ?

Please help me.

Nooooo you should never set a actual itemstack. In api 7 you were supposed to do it by

.set(item.createSnapshot(), TypeTokens.ITEM_STACK_SNAPSHOT)

and I believe the same goes for api 8, only typeTokens isnt a thing in api 8, so it would be TypeToken.of or ItemStackSnapshot.class

1 Like

Thank you so much. but I’ve tried to use ItemStackSnapshot. It still not working.

It show this error.

org.spongepowered.configurate.serialize.SerializationException: [item, 0, itemStack] of type org.spongepowered.api.item.inventory.ItemStackSnapshot: No serializer available for type interface org.spongepowered.api.item.inventory.ItemStackSnapshot

node.set(ItemStackSnapshot.class, item.createSnapshot());
and
node.set( item.createSnapshot());

I’ve solved it already! Thank for you care!