Search in sources :

Example 1 with ExceptionType

use of mcjty.rftoolscontrol.logic.running.ExceptionType in project RFToolsControl by McJty.

the class ParameterTypeTools method writeToNBTInternal.

private static void writeToNBTInternal(NBTTagCompound tag, ParameterType type, Object value) {
    switch(type) {
        case PAR_STRING:
            tag.setString("v", (String) value);
            break;
        case PAR_INTEGER:
            tag.setInteger("v", (Integer) value);
            break;
        case PAR_LONG:
            tag.setLong("v", (Long) value);
            break;
        case PAR_FLOAT:
            tag.setFloat("v", (Float) value);
            break;
        case PAR_NUMBER:
            if (value instanceof Integer) {
                tag.setInteger("v", (Integer) value);
            } else if (value instanceof Long) {
                tag.setLong("l", (Long) value);
            } else if (value instanceof Float) {
                tag.setFloat("f", (Float) value);
            } else if (value instanceof Double) {
                tag.setDouble("d", (Double) value);
            }
            break;
        case PAR_SIDE:
            BlockSide side = (BlockSide) value;
            tag.setInteger("v", side.getSide() == null ? -1 : side.getSide().ordinal());
            tag.setString("node", side.getNodeName() == null ? "" : side.getNodeName());
            break;
        case PAR_BOOLEAN:
            tag.setBoolean("v", (Boolean) value);
            break;
        case PAR_INVENTORY:
            Inventory inv = (Inventory) value;
            if (inv.getNodeName() != null) {
                tag.setString("nodeName", inv.getNodeName());
            }
            tag.setInteger("side", inv.getSide().ordinal());
            if (inv.getIntSide() != null) {
                tag.setInteger("intSide", inv.getIntSide().ordinal());
            }
            break;
        case PAR_ITEM:
            ItemStack itemStack = (ItemStack) value;
            NBTTagCompound tc = new NBTTagCompound();
            itemStack.writeToNBT(tc);
            tag.setTag("item", tc);
            break;
        case PAR_FLUID:
            FluidStack fluidStack = (FluidStack) value;
            NBTTagCompound fluidTc = new NBTTagCompound();
            fluidStack.writeToNBT(fluidTc);
            tag.setTag("fluid", fluidTc);
            break;
        case PAR_EXCEPTION:
            ExceptionType exception = (ExceptionType) value;
            tag.setString("code", exception.getCode());
            break;
        case PAR_TUPLE:
            tag.setInteger("x", ((Tuple) value).getX());
            tag.setInteger("y", ((Tuple) value).getY());
            break;
        case PAR_VECTOR:
            List<Parameter> vector = (List<Parameter>) value;
            NBTTagList list = new NBTTagList();
            for (Parameter p : vector) {
                list.appendTag(ParameterTools.writeToNBT(p));
            }
            tag.setTag("vector", list);
            break;
    }
}
Also used : ExceptionType(mcjty.rftoolscontrol.logic.running.ExceptionType) FluidStack(net.minecraftforge.fluids.FluidStack) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagList(net.minecraft.nbt.NBTTagList) ArrayList(java.util.ArrayList) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ExceptionType

use of mcjty.rftoolscontrol.logic.running.ExceptionType in project RFToolsControl by McJty.

the class ExceptionEditor method build.

@Override
public void build(Minecraft mc, Gui gui, Panel panel, ParameterEditorCallback callback) {
    Panel constantPanel = new Panel(mc, gui).setLayout(new HorizontalLayout());
    label = new ChoiceLabel(mc, gui).setDesiredWidth(160);
    label.addChoices("*");
    for (ExceptionType exception : ExceptionType.values()) {
        label.addChoices(exception.getCode());
    }
    label.addChoiceEvent((parent, newChoice) -> callback.valueChanged(readValue()));
    constantPanel.addChild(label);
    createEditorPanel(mc, gui, panel, callback, constantPanel, ParameterType.PAR_EXCEPTION);
}
Also used : Panel(mcjty.lib.gui.widgets.Panel) ExceptionType(mcjty.rftoolscontrol.logic.running.ExceptionType) ChoiceLabel(mcjty.lib.gui.widgets.ChoiceLabel) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout)

Example 3 with ExceptionType

use of mcjty.rftoolscontrol.logic.running.ExceptionType in project RFToolsControl by McJty.

the class ExceptionEditor method writeConstantValue.

@Override
protected void writeConstantValue(ParameterValue value) {
    if (value == null || value.getValue() == null) {
        label.setChoice("*");
    } else {
        ExceptionType exception = (ExceptionType) value.getValue();
        label.setChoice(exception.getCode());
    }
}
Also used : ExceptionType(mcjty.rftoolscontrol.logic.running.ExceptionType)

Example 4 with ExceptionType

use of mcjty.rftoolscontrol.logic.running.ExceptionType in project RFToolsControl by McJty.

the class ParameterTypeTools method writeToJsonInternal.

private static void writeToJsonInternal(JsonObject object, ParameterType type, Object value) {
    switch(type) {
        case PAR_STRING:
            object.add("v", new JsonPrimitive((String) value));
            break;
        case PAR_INTEGER:
            object.add("v", new JsonPrimitive((Integer) value));
            break;
        case PAR_LONG:
            object.add("v", new JsonPrimitive((Long) value));
            break;
        case PAR_FLOAT:
            object.add("v", new JsonPrimitive((Float) value));
            break;
        case PAR_NUMBER:
            if (value instanceof Integer) {
                object.add("v", new JsonPrimitive((Integer) value));
            } else if (value instanceof Long) {
                object.add("l", new JsonPrimitive((Long) value));
            } else if (value instanceof Float) {
                object.add("f", new JsonPrimitive((Float) value));
            } else if (value instanceof Double) {
                object.add("d", new JsonPrimitive((Double) value));
            }
            break;
        case PAR_SIDE:
            BlockSide side = (BlockSide) value;
            if (side.getSide() != null) {
                object.add("side", new JsonPrimitive(side.getSide().getName()));
            }
            if (side.getNodeName() != null) {
                object.add("node", new JsonPrimitive(side.getNodeName()));
            }
            break;
        case PAR_BOOLEAN:
            object.add("v", new JsonPrimitive((Boolean) value));
            break;
        case PAR_INVENTORY:
            Inventory inv = (Inventory) value;
            object.add("side", new JsonPrimitive(inv.getSide().getName()));
            if (inv.getIntSide() != null) {
                object.add("intside", new JsonPrimitive(inv.getIntSide().getName()));
            }
            if (inv.getNodeName() != null) {
                object.add("node", new JsonPrimitive(inv.getNodeName()));
            }
            break;
        case PAR_ITEM:
            ItemStack item = (ItemStack) value;
            object.add("item", new JsonPrimitive(item.getItem().getRegistryName().toString()));
            if (item.getCount() != 1) {
                object.add("amount", new JsonPrimitive(item.getCount()));
            }
            object.add("meta", new JsonPrimitive(item.getItemDamage()));
            if (item.hasTagCompound()) {
                String string = item.getTagCompound().toString();
                object.add("nbt", new JsonPrimitive(string));
            }
            break;
        case PAR_FLUID:
            FluidStack fluidStack = (FluidStack) value;
            object.add("fluid", new JsonPrimitive(fluidStack.getFluid().getName()));
            object.add("amount", new JsonPrimitive(fluidStack.amount));
            if (fluidStack.tag != null) {
                object.add("nbt", new JsonPrimitive(fluidStack.tag.toString()));
            }
            break;
        case PAR_EXCEPTION:
            ExceptionType exception = (ExceptionType) value;
            object.add("code", new JsonPrimitive(exception.getCode()));
            break;
        case PAR_TUPLE:
            object.add("x", new JsonPrimitive(((Tuple) value).getX()));
            object.add("y", new JsonPrimitive(((Tuple) value).getY()));
            break;
        case PAR_VECTOR:
            List<Parameter> vector = (List<Parameter>) value;
            JsonArray array = new JsonArray();
            for (Parameter p : vector) {
                array.add(ParameterTools.getJsonElement(p));
            }
            object.add("vector", array);
            break;
    }
}
Also used : ExceptionType(mcjty.rftoolscontrol.logic.running.ExceptionType) JsonPrimitive(com.google.gson.JsonPrimitive) FluidStack(net.minecraftforge.fluids.FluidStack) JsonArray(com.google.gson.JsonArray) ArrayList(java.util.ArrayList) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ExceptionType (mcjty.rftoolscontrol.logic.running.ExceptionType)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 JsonArray (com.google.gson.JsonArray)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)1 ChoiceLabel (mcjty.lib.gui.widgets.ChoiceLabel)1 Panel (mcjty.lib.gui.widgets.Panel)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1