package aeronicamc.mods.mxtune.caps;

import net.minecraft.nbt.INBT;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.INBTSerializable;

import javax.annotation.Nullable;

public class SerializableCapabilityProvider<HANDLER> extends SimpleCapabilityProvider<HANDLER> implements INBTSerializable<INBT>
{
    /**
     * Create a provider for the default handler instance.
     *
     * @param capability The Capability instance to provide the handler for
     * @param facing     The Direction to provide the handler for
     */
    public SerializableCapabilityProvider(final Capability<HANDLER> capability, @Nullable final Direction facing) {
        this(capability, facing, capability.getDefaultInstance());
    }

    /**
     * Create a provider for the specified handler instance.
     *
     * @param capability The Capability instance to provide the handler for
     * @param facing     The Direction to provide the handler for
     * @param instance   The handler instance to provide
     */
    public SerializableCapabilityProvider(final Capability<HANDLER> capability, @Nullable final Direction facing, @Nullable final HANDLER instance) {
        super(capability, facing, instance);
    }

    @Nullable
    @Override
    public INBT serializeNBT() {
        final HANDLER instance = getInstance();

        if (instance == null) {
            return null;
        }

        return getCapability().writeNBT(instance, getFacing());
    }

    @Override
    public void deserializeNBT(final INBT nbt) {
        final HANDLER instance = getInstance();

        if (instance == null) {
            return;
        }

        getCapability().readNBT(instance, getFacing(), nbt);
    }

}

@@ -194,66 +194,466 @@
 mon.
-util.INBTSerializable;%0A%0Aimport javax.annotation.Nullable;%0A
+capabilities.Capability.IStorage;%0Aimport net.minecraftforge.common.capabilities.ICapabilityProvider;%0Aimport net.minecraftforge.common.util.INBTSerializable;%0A%0Aimport javax.annotation.Nullable;%0A%0A/**%0A * A simple implementation of %7B@link ICapabilityProvider%7D and %7B@link INBTSerializable%7D that supports a single %7B@link Capability%7D handler instance.%0A * %3Cp%3E%0A * Uses the %7B@link Capability%7D's %7B@link IStorage%7D to serialise/deserialise NBT.%0A *%0A * @author Choonster%0A */
 %0Apub

Add authors javadoc