Search in sources :

Example 1 with GuiElementSlotMover

use of buildcraft.lib.gui.elem.GuiElementSlotMover in project BuildCraft by BuildCraft.

the class ElementTypeSlot method deserialize0.

// pos: the position of the slot
// slot: The slot to be moved
// index: If the slot was an InventorySlotHolder then this is the index of the slot in the list
// visible: If false then the slot won't be visible
@Override
protected IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    String slotName = json.properties.get("slot");
    IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
    Slot slot = gui.properties.get(slotName, Slot.class);
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    if (slot != null) {
        return new GuiElementSlotMover(gui, pos, visible, slot);
    }
    InventorySlotHolder holder = gui.properties.get(slotName, InventorySlotHolder.class);
    if (holder == null) {
        throw new JsonSyntaxException("Unknown slot '" + slotName + "'");
    }
    int index = resolveEquationInt(json, "index", ctx);
    if (index < 0 || index >= holder.slots.length) {
        throw new JsonSyntaxException("Invalid slot index! (" + index + ", min = 0, max = " + (holder.slots.length - 1) + ")");
    }
    return new GuiElementSlotMover(gui, pos, visible, holder.slots[index]);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Slot(net.minecraft.inventory.Slot) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) FunctionContext(buildcraft.lib.expression.FunctionContext) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition) GuiElementSlotMover(buildcraft.lib.gui.elem.GuiElementSlotMover)

Aggregations

FunctionContext (buildcraft.lib.expression.FunctionContext)1 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)1 GuiElementSlotMover (buildcraft.lib.gui.elem.GuiElementSlotMover)1 IGuiPosition (buildcraft.lib.gui.pos.IGuiPosition)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 Slot (net.minecraft.inventory.Slot)1