use of com.nukkitx.nbt.NbtType in project BlockStateUpdater by CloudburstMC.
the class TagUtils method toImmutable.
public static Object toImmutable(Object mutable) {
if (mutable instanceof Map) {
Map<String, Object> map = (Map<String, Object>) mutable;
NbtMapBuilder immutable = NbtMap.builder();
for (Map.Entry<String, Object> entry : map.entrySet()) {
immutable.put(entry.getKey(), toImmutable(entry.getValue()));
}
return immutable.build();
} else if (mutable instanceof List) {
List<Object> list = new ArrayList<>();
NbtType<?> type = NbtType.END;
for (Object value : (List<?>) mutable) {
if (type == NbtType.END) {
type = NbtType.byClass(value.getClass());
}
list.add(toImmutable(value));
}
return new NbtList(type, list);
}
return mutable;
}
Aggregations