package org.cyclops.cyclopscore.helper;

import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.text.ITextComponent;
import org.cyclops.cyclopscore.inventory.IValueNotifier;

/**
 * Helper methods for {@link org.cyclops.cyclopscore.inventory.IValueNotifiable} and
 * {@link org.cyclops.cyclopscore.inventory.IValueNotifier}.
 * @author rubensworks
 */
public class ValueNotifierHelpers {

    public static String KEY = "v";

    /**
     * Set the int value
     * @param notifier The notifier instance
     * @param valueId The value id
     * @param value The value
     */
    public static void setValue(IValueNotifier notifier, int valueId, int value) {
        CompoundNBT tag = new CompoundNBT();
        tag.putInt(KEY, value);
        notifier.setValue(valueId, tag);
    }

    /**
     * Set the string value
     * @param notifier The notifier instance
     * @param valueId The value id
     * @param value The value
     */
    public static void setValue(IValueNotifier notifier, int valueId, String value) {
        CompoundNBT tag = new CompoundNBT();
        tag.putString(KEY, value);
        notifier.setValue(valueId, tag);
    }

    /**
     * Set the {@link ITextComponent} value
     * @param notifier The notifier instance
     * @param valueId The value id
     * @param value The value
     */
    public static void setValue(IValueNotifier notifier, int valueId, ITextComponent value) {
        CompoundNBT tag = new CompoundNBT();
        tag.putString(KEY, ITextComponent.Serializer.toJson(value));
        notifier.setValue(valueId, tag);
    }

    /**
     * get the int value
     * @param notifier The notifier instance
     * @param valueId The value id
     * @return The value
     */
    public static int getValueInt(IValueNotifier notifier, int valueId) {
        CompoundNBT tag = notifier.getValue(valueId);
        if(tag != null) {
            return tag.getInt(KEY);
        }
        return 0;
    }

    /**
     * Get the string value
     * @param notifier The notifier instance
     * @param valueId The value id
     * @return The value
     */
    public static String getValueString(IValueNotifier notifier, int valueId) {
        CompoundNBT tag = notifier.getValue(valueId);
        if(tag != null) {
            return tag.getString(KEY);
        }
        return null;
    }

    /**
     * Get the {@link ITextComponent} value
     * @param notifier The notifier instance
     * @param valueId The value id
     * @return The value
     */
    public static ITextComponent getValueTextComponent(IValueNotifier notifier, int valueId) {
        CompoundNBT tag = notifier.getValue(valueId);
        if(tag != null) {
            return ITextComponent.Serializer.fromJson(tag.getString(KEY));
        }
        return null;
    }

}

@@ -34,16 +34,56 @@
 elper;%0A%0A
+import com.google.common.collect.Lists;%0A
 import n
@@ -137,89 +137,266 @@
 aft.
-util.text.ITextComponent;%0Aimport org.cyclops.cyclopscore.inventory.IValueNotifier
+nbt.ListNBT;%0Aimport net.minecraft.nbt.StringNBT;%0Aimport net.minecraft.util.text.ITextComponent;%0Aimport net.minecraftforge.common.util.Constants;%0Aimport org.cyclops.cyclopscore.inventory.IValueNotifier;%0A%0Aimport javax.annotation.Nullable;%0Aimport java.util.List
 ;%0A%0A/
@@ -1790,32 +1790,603 @@
 d, tag);%0A    %7D%0A%0A
+    /**%0A     * Set the %7B@link ITextComponent%7D list value%0A     * @param notifier The notifier instance%0A     * @param valueId The value id%0A     * @param values The values%0A     */%0A    public static void setValue(IValueNotifier notifier, int valueId, List%3CITextComponent%3E values) %7B%0A        CompoundNBT tag = new CompoundNBT();%0A        ListNBT list = new ListNBT();%0A        for (ITextComponent value : values) %7B%0A            list.add(new StringNBT(ITextComponent.Serializer.toJson(value)));%0A        %7D%0A        tag.put(KEY, list);%0A        notifier.setValue(valueId, tag);%0A    %7D%0A%0A
     /**%0A     * g
@@ -2881,32 +2881,46 @@
 e value%0A     */%0A
+    @Nullable%0A
     public stati
@@ -3297,32 +3297,46 @@
 e value%0A     */%0A
+    @Nullable%0A
     public stati
@@ -3607,10 +3607,731 @@
 %0A    %7D%0A%0A
+    /**%0A     * Get the %7B@link ITextComponent%7D list value%0A     * @param notifier The notifier instance%0A     * @param valueId The value id%0A     * @return The value%0A     */%0A    @Nullable%0A    public static List%3CITextComponent%3E getValueTextComponentList(IValueNotifier notifier, int valueId) %7B%0A        CompoundNBT tag = notifier.getValue(valueId);%0A        if(tag != null) %7B%0A            ListNBT listTag = tag.getList(KEY, Constants.NBT.TAG_STRING);%0A            List%3CITextComponent%3E list = Lists.newArrayList();%0A            for (int i = 0; i %3C listTag.size(); i++) %7B%0A                list.add(ITextComponent.Serializer.fromJson(listTag.getString(i)));%0A            %7D%0A            return list;%0A        %7D%0A        return null;%0A    %7D%0A%0A
 %7D%0A

Support lists of ITextComponent in value notify helpers