Map<String, Object> map = new HashMap<>();
NBTTagCompound nbt = new NBTTagCompound();
map.put("test1",123);
nbt.setInteger("test1",123);
map.put("test2", true);
nbt.setBoolean("test2", true);
map.put("test3", new HashMap<String, Object>());
nbt.setTag("test3", new NbtTagCompound());
Map<String, Object> map2 = nbt2Map(nbt);
NBTTagCompound nbt2 = map2Nbt(map);
println(map.equals(map2)); //true
println(nbt.equals(nbt2)); //true
//некоторые вспомогательные функции
//нужны чтобы показать эквивалентность мапы и нбт для предыдущих двух строк
//некоторые детали, вроде приведения типов опущены
public static Map<String, Object> nbt2Map(NBTTagCompound nbt){
Map<String, Object> r = new HashMap<>();
for(String key: nbt.getKeySet())
r.put(key, nbt2Object(nbt.getTag(key)));
return r;
}
public static NBTTagCompound map2Nbt(Map<String, Object> map){
NBTTagCompound r = new NBTTagCompound();
for(Entry<String,Object> e: map.entrySet())
r.setTag(e.getKey(), object2Nbt(e.getValue));
return r;
}
public static Object nbt2Object(NBTBase nbt){
if(nbt instanceof NBTTagInt)
return nbt.getInt();
else if(nbt instanceof NBTTagCompound)
return nbt2Map(nbt);
else if(...)
...
...
}
public static NBTBase object2Nbt(Object v){
if(v instanceof Integer)
return new NBTTagInt(v);
if(v instanceof Map)
return map2Nbt(v);
else if(...)
...
...
}