Ah okay so here's what I have on a custom class implementing ICapabilityProvider. The serializers confuse me and I'm not sure what they are for. Is it this when the capability is used in other mods, between server/client, or save/load?
public class FissionProvider implements ICapabilitySerializable<CompoundNBT>
{
private LazyOptional<IFission> instance = LazyOptional.of(CapabilityRegister.FISSION::getDefaultInstance);
@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side)
{
return CapabilityRegister.FISSION.orEmpty(cap, instance);
}
@Override
public CompoundNBT serializeNBT()
{
IFission fission = instance.orElseThrow(() -> new IllegalArgumentException("at serialize"));
CompoundNBT nbt = new CompoundNBT();
nbt.putFloat("temperature", fission.getTemperature());
nbt.putLong("neutrons", fission.getNeutrons());
return nbt;
}
@Override
public void deserializeNBT(CompoundNBT nbt)
{
//IFission fission = instance.orElseThrow(() -> new IllegalArgumentException("at serialize"));
}
}
I'm confused on the serializers on the register as well.
public class CapabilityRegister
{
@CapabilityInject(IFission.class)
public static Capability<IFission> FISSION = null;
public static void init()
{
CapabilityManager.INSTANCE.register(IFission.class, new IStorage<IFission>()
{
@Override
public INBT writeNBT(Capability<IFission> capability, IFission instance, Direction side)
{
return null;
}
@Override
public void readNBT(Capability<IFission> capability, IFission instance, Direction side, INBT nbt)
{
}
}, Fission::new);
}
}