Help with De-serializing ItemStack from confignode

Sponge Build: spongevanilla-1.8.9-3.1.0-BETA-236
Java Version: java8

i try to De-serializing ItemStack from confignode,but get errors

“java.lang.IllegalStateException: Item type has not been set”

and i found
ConfigurateTranslator.instance().translateFrom(node)
include “node”'s path info
test code:
cfg.getNode("item").setValue(TypeToken.of(ItemStack.class),p.getItemInHand().get()); saveconfig("config.conf"); Sponge.getServer().getBroadcastChannel().send(Text.of(ConfigurateTranslator.instance().translateFrom(cfg.getNode("item")))); Sponge.getServer().getBroadcastChannel().send(Text.of(p.getItemInHand().get().toContainer()));

message1=MemoryDataContainer{map={item=MemoryDataView{path=item, map={ContentVersion=1, ItemType=minecraft:arrow, Count=1, UnsafeDamage=0}}}}

message2=MemoryDataContainer{map={ContentVersion=1, ItemType=minecraft:arrow, Count=1, UnsafeDamage=0}}

how can i remove the path info and get real DataView?

It looks like the item type is not being set when deserializing an itemstack. This is a bug in sponge.

Edit maybe I’m wrong there, I think it’s a problem with the data you’re passing in.

What if you try doing getNode("item").getNode("item") because it’s almost as though it’s being nested twice

Sponge.getServer().getBroadcastChannel().send(Text.of(ConfigurateTranslator.instance().translateFrom(cfg.getNode("item").getNode("item"))));

and the final message is MemoryDataContainer{map={}}

As I mentioned here:

There might be an issue with the ConfigurateTranslator, please print out what the translated DataView is after translating it from the ConfigurationNode.

you mean this ?
DataView dv = ConfigurateTranslator.instance().translateFrom(cfg.getNode("item")); System.out.println(dv)

and this is ConfigurationNode:
item { ContentVersion=1 Count=1 ItemType="minecraft:chest" UnsafeDamage=0 }

and this is console message :
[15:38:16 INFO] [STDOUT]: [ysjdmg.Ysjdmg.reloadcfg(Ysjdmg.java:358)]: MemoryDataContainer{map={item=MemoryDataView{path=item, map={ContentVersion=1, ItemType=minecraft:chest, Count=1, UnsafeDamage=0}}}}

This has been fixed as of Fix ConfigurateTranslator not translating Maps and Lists in nodes wit… · SpongePowered/SpongeAPI@6066a68 · GitHub

1 Like