Class NBTClassType<T>

java.lang.Object
org.cyclops.cyclopscore.persist.nbt.NBTClassType<T>
Type Parameters:
T - The field class type.
Direct Known Subclasses:
INBTSerializable.SelfNBTClassType

public abstract class NBTClassType<T> extends Object
Types of NBT field classes used for persistence of fields in CyclopsBlockEntity.
See Also:
  • Field Details

    • NBTYPES

      public static Map<Class<?>,NBTClassType<?>> NBTYPES
      A map of all the types to their persist actions.
  • Constructor Details

    • NBTClassType

      public NBTClassType()
  • Method Details

    • getClassType

      public static <T> NBTClassType<T> getClassType(Class<T> clazz)
      Get the serialization class for the given object.
      Type Parameters:
      T - The object type
      Parameters:
      clazz - The class of the object.
      Returns:
      The serialization class.
    • writeNbt

      public static <T, I extends T> void writeNbt(Class<T> clazz, String name, I instance, net.minecraft.nbt.CompoundTag tag)
      Write the given object to NBT.
      Type Parameters:
      T - The class type.
      I - The object type.
      Parameters:
      clazz - The class of the object.
      name - The NBT key name to write to.
      instance - The instance to serialize.
      tag - The NBT tag to write in.
    • readNbt

      public static <T> T readNbt(Class<T> clazz, String name, net.minecraft.nbt.CompoundTag tag)
      Read an object from NBT.
      Type Parameters:
      T - The class type.
      Parameters:
      clazz - The class of the object.
      name - The NBT key name to read from.
      tag - The NBT tag to read in.
      Returns:
      The read object.
    • getType

      public static NBTClassType getType(Class<?> type, Object target)
    • performActionForField

      public static void performActionForField(INBTProvider provider, Field field, net.minecraft.nbt.CompoundTag tag, boolean write)
      Perform a field persist action.
      Parameters:
      provider - The provider that has the field.
      field - The field to persist or read.
      tag - The tag compound to read or write to.
      write - If there should be written, otherwise there will be read.
    • persistedFieldAction

      public void persistedFieldAction(INBTProvider provider, Field field, net.minecraft.nbt.CompoundTag tag, boolean write) throws IllegalAccessException
      Called to read or write a field.
      Parameters:
      provider - The provider that has the field.
      field - The field to persist or read.
      tag - The tag compound to read or write to.
      write - If there should be written, otherwise there will be read.
      Throws:
      IllegalArgumentException - Argument exception;
      IllegalAccessException - Access exception;
    • writePersistedField

      public abstract void writePersistedField(String name, T object, net.minecraft.nbt.CompoundTag tag)
    • readPersistedField

      public abstract T readPersistedField(String name, net.minecraft.nbt.CompoundTag tag)
    • getDefaultValue

      public abstract T getDefaultValue()