Search in sources :

Example 1 with Inventory

use of mcjty.rftoolscontrol.api.parameters.Inventory in project RFToolsControl by McJty.

the class CraftingStationTileEntity method craftOk.

public ItemStack craftOk(ProcessorTileEntity processor, String ticket, ItemStack stack) {
    CraftingRequest foundRequest = null;
    for (CraftingRequest request : activeCraftingRequests) {
        if (ticket.equals(request.getTicket())) {
            foundRequest = request;
            break;
        }
    }
    if (foundRequest != null) {
        markDirty();
        foundRequest.decrTodo();
        if (foundRequest.getTodo() <= 0) {
            foundRequest.setOk(System.currentTimeMillis() + 1000);
        } else {
            processor.fireCraftEvent(ticket, foundRequest.getStack());
        }
        if (!stack.isEmpty()) {
            Inventory inventory = getInventoryFromTicket(ticket);
            if (inventory != null) {
                IItemHandler handlerAt = processor.getItemHandlerAt(inventory);
                if (handlerAt == null) {
                    throw new ProgException(ExceptionType.EXCEPT_INVALIDINVENTORY);
                }
                return ItemHandlerHelper.insertItem(handlerAt, stack, false);
            } else {
                return ItemHandlerHelper.insertItem(getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null), stack, false);
            }
        }
    }
    return stack;
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) IItemHandler(net.minecraftforge.items.IItemHandler) Inventory(mcjty.rftoolscontrol.api.parameters.Inventory) DefaultSidedInventory(mcjty.lib.container.DefaultSidedInventory)

Example 2 with Inventory

use of mcjty.rftoolscontrol.api.parameters.Inventory in project RFToolsControl by McJty.

the class InventoryEditor method build.

@Override
public void build(Minecraft mc, Gui gui, Panel panel, ParameterEditorCallback callback) {
    Panel constantPanel = new Panel(mc, gui).setLayout(new VerticalLayout());
    nameLabel = new TextField(mc, gui).addTextEvent((o, text) -> callback.valueChanged(readValue())).addTextEnterEvent((parent, newText) -> closeWindow()).setDesiredWidth(50).setDesiredHeight(14);
    constantPanel.addChild(createLabeledPanel(mc, gui, "Node name:", nameLabel, "Optional name of a node in the network"));
    sideLabel = new ChoiceLabel(mc, gui).addChoices("*", "Down", "Up", "North", "South", "West", "East").addChoiceEvent((parent, newChoice) -> callback.valueChanged(readValue())).setDesiredWidth(60);
    constantPanel.addChild(createLabeledPanel(mc, gui, "Side:", sideLabel, "Side relative to processor or node", "for the desired inventory"));
    intSideLabel = new ChoiceLabel(mc, gui).addChoices("*", "Down", "Up", "North", "South", "West", "East").addChoiceEvent((parent, newChoice) -> callback.valueChanged(readValue())).setDesiredWidth(60);
    constantPanel.addChild(createLabeledPanel(mc, gui, "Access:", intSideLabel, "Optional side from which we want to", "access the given inventory"));
    createEditorPanel(mc, gui, panel, callback, constantPanel, ParameterType.PAR_INVENTORY);
}
Also used : Window(mcjty.lib.gui.Window) ParameterType(mcjty.rftoolscontrol.api.parameters.ParameterType) TextField(mcjty.lib.gui.widgets.TextField) Gui(net.minecraft.client.gui.Gui) Panel(mcjty.lib.gui.widgets.Panel) ParameterValue(mcjty.rftoolscontrol.api.parameters.ParameterValue) Minecraft(net.minecraft.client.Minecraft) EnumFacing(net.minecraft.util.EnumFacing) ChoiceLabel(mcjty.lib.gui.widgets.ChoiceLabel) VerticalLayout(mcjty.lib.gui.layout.VerticalLayout) StringUtils(org.apache.commons.lang3.StringUtils) Inventory(mcjty.rftoolscontrol.api.parameters.Inventory) Panel(mcjty.lib.gui.widgets.Panel) ChoiceLabel(mcjty.lib.gui.widgets.ChoiceLabel) VerticalLayout(mcjty.lib.gui.layout.VerticalLayout) TextField(mcjty.lib.gui.widgets.TextField)

Example 3 with Inventory

use of mcjty.rftoolscontrol.api.parameters.Inventory in project RFToolsControl by McJty.

the class InventoryTools method inventoryFromString.

@Nullable
public static Inventory inventoryFromString(String s) {
    if (s == null) {
        return null;
    }
    int indexOf = s.lastIndexOf('/');
    if (indexOf == -1) {
        return null;
    }
    if (s.length() <= indexOf + 1) {
        return null;
    }
    EnumFacing side = getSideFromChar(s.charAt(indexOf - 1));
    if (side == null) {
        // Side == null is invalid for Inventory
        return null;
    }
    EnumFacing intSide = getSideFromChar(s.charAt(indexOf + 1));
    int indexSpace = s.lastIndexOf(' ');
    if (indexSpace <= 0) {
        return new Inventory(null, side, intSide);
    }
    return new Inventory(s.substring(0, indexSpace), side, intSide);
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Inventory(mcjty.rftoolscontrol.api.parameters.Inventory) Nullable(javax.annotation.Nullable)

Example 4 with Inventory

use of mcjty.rftoolscontrol.api.parameters.Inventory in project RFToolsControl by McJty.

the class InventoryEditor method parseInventorySafe.

private static Inventory parseInventorySafe(String name, String sideS, String intSideS) {
    EnumFacing side;
    if ("*".equals(sideS)) {
        return null;
    } else {
        side = EnumFacing.byName(StringUtils.lowerCase(sideS));
    }
    EnumFacing intSide;
    if ("*".equals(intSideS)) {
        intSide = null;
    } else {
        intSide = EnumFacing.byName(StringUtils.lowerCase(intSideS));
    }
    return new Inventory(name, side, intSide);
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Inventory(mcjty.rftoolscontrol.api.parameters.Inventory)

Example 5 with Inventory

use of mcjty.rftoolscontrol.api.parameters.Inventory in project RFToolsControl by McJty.

the class InventoryEditor method writeConstantValue.

@Override
protected void writeConstantValue(ParameterValue value) {
    if (value == null || value.getValue() == null) {
        sideLabel.setChoice("*");
    } else {
        Inventory inv = (Inventory) value.getValue();
        nameLabel.setText(inv.getNodeName() == null ? "" : inv.getNodeName());
        sideLabel.setChoice(StringUtils.capitalize(inv.getSide().toString()));
        if (inv.getIntSide() == null) {
            intSideLabel.setChoice("*");
        } else {
            intSideLabel.setChoice(StringUtils.capitalize(inv.getIntSide().toString()));
        }
    }
}
Also used : Inventory(mcjty.rftoolscontrol.api.parameters.Inventory)

Aggregations

Inventory (mcjty.rftoolscontrol.api.parameters.Inventory)7 EnumFacing (net.minecraft.util.EnumFacing)5 Nullable (javax.annotation.Nullable)1 DefaultSidedInventory (mcjty.lib.container.DefaultSidedInventory)1 Window (mcjty.lib.gui.Window)1 VerticalLayout (mcjty.lib.gui.layout.VerticalLayout)1 ChoiceLabel (mcjty.lib.gui.widgets.ChoiceLabel)1 Panel (mcjty.lib.gui.widgets.Panel)1 TextField (mcjty.lib.gui.widgets.TextField)1 ParameterType (mcjty.rftoolscontrol.api.parameters.ParameterType)1 ParameterValue (mcjty.rftoolscontrol.api.parameters.ParameterValue)1 ProgException (mcjty.rftoolscontrol.logic.running.ProgException)1 Minecraft (net.minecraft.client.Minecraft)1 Gui (net.minecraft.client.gui.Gui)1 IItemHandler (net.minecraftforge.items.IItemHandler)1 StringUtils (org.apache.commons.lang3.StringUtils)1