Add getCompound and getType support for NBTListCompound
CC007 opened this issue ยท 2 comments
At the moment you only support a cutdown version of the NBTCompound
in NBTListCompound
, namely get/set integer/double/string.
Could you add a getCompound(key)
and getType(key)
method to the NBTListCompound
? That would make debugging skull NBT values way easier.
Maybe this will help you implement the getType(key)
:
private NBTType getType(NBTListCompound nbtListCompound, String key){
try {
Field compoundField = nbtListCompound.getClass().getDeclaredField("compound");
compoundField.setAccessible(true);
Object nbtTagCompound = Objects.requireNonNull(ReflectionUtils.getField(compoundField, nbtListCompound));
val typeId = nbtTagCompound.getClass().getMethod(ReflectionMethod.COMPOUND_GET_TYPE.getMethodName(), String.class).invoke(nbtTagCompound, key);
if(typeId == null) {
throw new RuntimeException("Error while getting type from NBTListCompound: type is null");
}
return NBTType.valueOf((Byte)typeId);
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException | NoSuchFieldException e) {
throw new RuntimeException("Error while getting type from NBTListCompound key: " + key, e);
}
}
And since you don't have to use reflection to get to the compound
field as it is in your part of the code, it should be even easier for you to implement.