Automatically save, load, and sync NBT data with a easy to use, easy to extend, annotation based API.
First add tterrag's alternate maven to your buildscript
repositories {
maven { url = "http://maven2.tterrag.com" } // AutoSave
}
Then add AutoSave as a maven dependency
dependencies {
compile "info.loenwind.autosave:AutoSave:${minecraft_version}-${autosave_version}"
}
Where autosave_version
is defined in your gradle.properties
file. See the maven listings for versions.
However, to allow for multiple mods to depend on AutoSave without conflict (and without shading) we recommend you use Forge's Contained Dependencies system.
Simply annotate any fields that need to be saved with @Store
.
public class MyObject {
@Store
private String name;
@Store
private int counter;
}
The (de)serialization API is very simple, only a single line of code!
NBTTagCompound tag = new NBTTagCompound();
Writer.write(tag, object);
Reader.read(tag, object);
@Storable
public class StorableExample {
@Store
private String name;
}
public class Wrapper {
@Store
private StorableExample storable;
}
Writer.write(tag, new Wrapper()); // This will work!
Registry registry = new Registry();
registry.register(new HandleMyObject());
...
class Wrapper {
@Store
private MyObject myObject = new MyObject();
}
NBTTagCompound tag = new NBTTagCompound();
Writer.write(registry, tag, new Wrapper());
- Array types will automatically look for a handler for their component type
- Supported generic types will do the same (List, Map, etc. See Java)
- All primitive types (including boxed types)
- String
- Enum
- List (ArrayList)
- LinkedList
- Set (HashSet)
- Map (HashMap)
- EnumMap
- Enum2EnumMap (Not a class, but a special case of EnumMap where the data is packed more efficiently)
- Block, Item, Enchantment, etc. are supported by the generic registry object handler
- BlockPos
- IBlockState
- ItemStack
- ResourceLocation
- All registry objects (Item, Block, Biome, Enchantment, etc.)
- Fluid
- FluidStack