/** * Get a NBT wrapper from a NBT base. * * <p>This may clone the content if the NbtBase is not a NbtWrapper. * * @param <T> Type * @param base - the base class. * @return A NBT wrapper. */ @SuppressWarnings("unchecked") public static <T> NbtWrapper<T> fromBase(NbtBase<T> base) { if (base instanceof NbtWrapper) { return (NbtWrapper<T>) base; } else { if (base.getType() == NbtType.TAG_COMPOUND) { // Load into a NBT-backed wrapper WrappedCompound copy = WrappedCompound.fromName(base.getName()); T value = base.getValue(); copy.setValue((Map<String, NbtBase<?>>) value); return (NbtWrapper<T>) copy; } else if (base.getType() == NbtType.TAG_LIST) { // As above NbtList<T> copy = WrappedList.fromName(base.getName()); copy.setValue((List<NbtBase<T>>) base.getValue()); return (NbtWrapper<T>) copy; } else { // Copy directly NbtWrapper<T> copy = ofWrapper(base.getType(), base.getName()); copy.setValue(base.getValue()); return copy; } } }
/** * Construct a new NBT compound wrapper. * * @param name - the name of the compound wrapper. * @return The new wrapped NBT compound. */ public static NbtCompound ofCompound(String name) { return WrappedCompound.fromName(name); }
/** * Construct a new NBT compound initialized with a given list of NBT values. * * @param name - the name of the compound wrapper. * @param list - the list of elements to add. * @return The new wrapped NBT compound. */ public static NbtCompound ofCompound(String name, Collection<? extends NbtBase<?>> list) { return WrappedCompound.fromList(name, list); }