@@ -0,0 +1,2302 @@
+package com.elytradev.concrete;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport com.google.common.base.Supplier;%0Aimport net.minecraft.nbt.NBTBase;%0Aimport net.minecraft.nbt.NBTTagList;%0Aimport net.minecraftforge.common.util.INBTSerializable;%0A%0Apublic class NBTHelper %7B%0A%0A%09/**%0A%09 * Convert the given Collection of INBTSerializable objects into an%0A%09 * NBTTagList.%0A%09 */%0A%09public %3CT extends INBTSerializable%3CU%3E,%0A%09%09%09U extends NBTBase%3E NBTTagList serialize(Collection%3CT%3E in) %7B%0A%09%09NBTTagList out = new NBTTagList();%0A%09%09for (T t : in) %7B%0A%09%09%09out.appendTag(t.serializeNBT());%0A%09%09%7D%0A%09%09return out;%0A%09%7D%0A%09%0A%09/**%0A%09 * Convert the given NBTTagList into an ArrayList of INBTSerializable%0A%09 * objects, using freshly-created objects from the passed constructor.%0A%09 * %3Cp%3E%0A%09 * Example: %7B@code NBTHelper.deserialize(MyObject::new, myNBTList)%7D%0A%09 */%0A%09public %3CT extends INBTSerializable%3CU%3E,%0A%09%09%09U extends NBTBase%3E ArrayList%3CT%3E deserialize(Supplier%3CT%3E constructor, NBTTagList in) %7B%0A%09%09return deserialize(constructor, in, ArrayList::new);%0A%09%7D%0A%09%0A%09/**%0A%09 * Convert the given NBTTagList into a Collection of INBTSerializable%0A%09 * objects, using freshly-created objects from the passed constructor, and%0A%09 * a freshly-created collection from the passed collection constructor. %0A%09 * %3Cp%3E%0A%09 * Example: %7B@code NBTHelper.deserialize(MyObject::new, myNBTList, ArrayList::new)%7D%0A%09 */%0A%09public %3CT extends INBTSerializable%3CU%3E,%0A%09%09%09U extends NBTBase,%0A%09%09%09C extends Collection%3CT%3E%3E C deserialize(Supplier%3CT%3E constructor, NBTTagList in, Supplier%3CC%3E collectionConstructor) %7B%0A%09%09return deserializeInto(constructor, in, collectionConstructor.get());%0A%09%7D%0A%09%0A%09/**%0A%09 * Add INBTSerializable objects from the given NBTTagList into a%0A%09 * pre-existing Collection of the correct type, using freshly-created%0A%09 * objects from the passed constructor.%0A%09 * %3Cp%3E%0A%09 * This method does not clear the passed collection, that's up to you if you%0A%09 * want to do it. %0A%09 * %3Cp%3E%0A%09 * Example: %7B@code NBTHelper.deserialize(MyObject::new, myNBTList, myList)%7D%0A%09 */%0A%09public %3CT extends INBTSerializable%3CU%3E,%0A%09%09%09U extends NBTBase,%0A%09%09%09C extends Collection%3CT%3E%3E C deserializeInto(Supplier%3CT%3E constructor, NBTTagList in, C collection) %7B%0A%09%09for (int i = 0; i %3C in.tagCount(); i++) %7B%0A%09%09%09T t = constructor.get();%0A%09%09%09t.deserializeNBT((U)in.get(i));%0A%09%09%09collection.add(t);%0A%09%09%7D%0A%09%09return collection;%0A%09%7D%0A%09%0A%7D%0A

Add NBTHelper, with extra-fun generics