package org.cyclops.cyclopscore.helper;

import net.minecraft.nbt.CompoundNBT;
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);
    }

    /**
     * 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;
    }

}

@@ -72,16 +72,63 @@
 undNBT;%0A
+import net.minecraft.util.text.ITextComponent;%0A
 import o
@@ -176,16 +176,16 @@
 tifier;%0A
-
 %0A/**%0A * 
@@ -1147,32 +1147,458 @@
 d, tag);%0A    %7D%0A%0A
+    /**%0A     * Set the %7B@link ITextComponent%7D value%0A     * @param notifier The notifier instance%0A     * @param valueId The value id%0A     * @param value The value%0A     */%0A    public static void setValue(IValueNotifier notifier, int valueId, ITextComponent value) %7B%0A        CompoundNBT tag = new CompoundNBT();%0A        tag.putString(KEY, ITextComponent.Serializer.toJson(value));%0A        notifier.setValue(valueId, tag);%0A    %7D%0A%0A
     /**%0A     * g
@@ -2253,32 +2253,32 @@
 (tag != null) %7B%0A
-
             retu
@@ -2338,10 +2338,463 @@
 %0A    %7D%0A%0A
+    /**%0A     * Get the %7B@link ITextComponent%7D value%0A     * @param notifier The notifier instance%0A     * @param valueId The value id%0A     * @return The value%0A     */%0A    public static ITextComponent getValueTextComponent(IValueNotifier notifier, int valueId) %7B%0A        CompoundNBT tag = notifier.getValue(valueId);%0A        if(tag != null) %7B%0A            return ITextComponent.Serializer.fromJson(tag.getString(KEY));%0A        %7D%0A        return null;%0A    %7D%0A%0A
 %7D%0A

Allow ITextComponent to be passed via value notifiers