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;
}
}
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);
}
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());
}
}
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;
}
}
Aggregations