Search in sources :

Example 6 with CompiledCard

use of mcjty.rftoolscontrol.logic.compiled.CompiledCard in project RFToolsControl by McJty.

the class ProcessorTileEntity method compileCards.

private void compileCards() {
    if (cardsDirty) {
        cardsDirty = false;
        for (int i = ProcessorContainer.SLOT_CARD; i < ProcessorContainer.SLOT_CARD + CARD_SLOTS; i++) {
            ItemStack cardStack = inventoryHelper.getStackInSlot(i);
            if (!cardStack.isEmpty()) {
                int cardIndex = i - ProcessorContainer.SLOT_CARD;
                if (cardInfo[cardIndex].getCompiledCard() == null) {
                    // @todo validation
                    CompiledCard compiled = CompiledCard.compile(ProgramCardInstance.parseInstance(cardStack));
                    cardInfo[cardIndex].setCompiledCard(compiled);
                }
            }
        }
    }
}
Also used : CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard) ItemStack(net.minecraft.item.ItemStack)

Example 7 with CompiledCard

use of mcjty.rftoolscontrol.logic.compiled.CompiledCard in project RFToolsControl by McJty.

the class ProcessorTileEntity method handleEvents.

private void handleEvents() {
    for (int i = 0; i < cardInfo.length; i++) {
        CardInfo info = cardInfo[i];
        CompiledCard compiledCard = info.getCompiledCard();
        if (compiledCard != null) {
            handleEventsRedstoneOn(i, compiledCard);
            handleEventsRedstoneOff(i, compiledCard);
            handleEventsTimer(i, compiledCard);
            handleEventsCraftResume(i, compiledCard);
        }
    }
}
Also used : CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard)

Example 8 with CompiledCard

use of mcjty.rftoolscontrol.logic.compiled.CompiledCard in project RFToolsControl by McJty.

the class ProcessorTileEntity method getCompiledCard.

public CompiledCard getCompiledCard(int index) {
    CardInfo info = getCardInfo(index);
    CompiledCard card = info.getCompiledCard();
    ItemStack cardStack = inventoryHelper.getStackInSlot(index + ProcessorContainer.SLOT_CARD);
    if (card == null && !cardStack.isEmpty()) {
        card = CompiledCard.compile(ProgramCardInstance.parseInstance(cardStack));
        cardInfo[index].setCompiledCard(card);
    }
    return card;
}
Also used : CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard) ItemStack(net.minecraft.item.ItemStack)

Example 9 with CompiledCard

use of mcjty.rftoolscontrol.logic.compiled.CompiledCard in project RFToolsControl by McJty.

the class ProcessorTileEntity method fireCraftEvent.

public void fireCraftEvent(String ticket, ItemStack stackToCraft) {
    for (int i = 0; i < cardInfo.length; i++) {
        CardInfo info = cardInfo[i];
        CompiledCard compiledCard = info.getCompiledCard();
        if (compiledCard != null) {
            for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_CRAFT)) {
                int index = event.getIndex();
                CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
                ItemStack stack = evaluateItemParameter(compiledOpcode, null, 0);
                Inventory inv = evaluateInventoryParameter(compiledOpcode, null, 1);
                if (!stack.isEmpty()) {
                    if (stack.isItemEqual(stackToCraft)) {
                        runOrQueueEvent(i, event, ticket, null);
                        return;
                    }
                } else if (inv != null) {
                    IItemHandler handler = getItemHandlerAt(inv);
                    ItemStack craftingCard = findCraftingCard(handler, stackToCraft);
                    if (!craftingCard.isEmpty()) {
                        runOrQueueEvent(i, event, ticket, null);
                        return;
                    }
                }
            }
        }
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard) ICompiledOpcode(mcjty.rftoolscontrol.api.code.ICompiledOpcode) CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent) ItemStack(net.minecraft.item.ItemStack) ISidedInventory(net.minecraft.inventory.ISidedInventory) IInventory(net.minecraft.inventory.IInventory) DefaultSidedInventory(mcjty.lib.container.DefaultSidedInventory)

Example 10 with CompiledCard

use of mcjty.rftoolscontrol.logic.compiled.CompiledCard in project RFToolsControl by McJty.

the class ProcessorTileEntity method getCraftableItems.

public void getCraftableItems(List<ItemStack> stacks) {
    try {
        for (CardInfo info : cardInfo) {
            CompiledCard compiledCard = info.getCompiledCard();
            if (compiledCard != null) {
                for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_CRAFT)) {
                    int index = event.getIndex();
                    CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
                    ItemStack stack = evaluateItemParameter(compiledOpcode, null, 0);
                    Inventory inv = evaluateInventoryParameter(compiledOpcode, null, 1);
                    if (!stack.isEmpty() && inv != null) {
                        throw new ProgException(EXCEPT_BADPARAMETERS);
                    }
                    if (stack.isEmpty() && inv == null) {
                        throw new ProgException(EXCEPT_BADPARAMETERS);
                    }
                    if (!stack.isEmpty()) {
                        stacks.add(stack);
                    } else {
                        // Find all crafting cards in the inventory
                        IItemHandler handler = getItemHandlerAt(inv);
                        for (int i = 0; i < handler.getSlots(); i++) {
                            ItemStack s = handler.getStackInSlot(i);
                            if (!s.isEmpty() && s.getItem() == ModItems.craftingCardItem) {
                                ItemStack result = CraftingCardItem.getResult(s);
                                if (!result.isEmpty()) {
                                    stacks.add(result);
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (ProgException e) {
        exception(e.getExceptionType(), null);
    }
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) IItemHandler(net.minecraftforge.items.IItemHandler) CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard) ICompiledOpcode(mcjty.rftoolscontrol.api.code.ICompiledOpcode) CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent) ItemStack(net.minecraft.item.ItemStack) ISidedInventory(net.minecraft.inventory.ISidedInventory) IInventory(net.minecraft.inventory.IInventory) DefaultSidedInventory(mcjty.lib.container.DefaultSidedInventory)

Aggregations

CompiledCard (mcjty.rftoolscontrol.logic.compiled.CompiledCard)12 CompiledEvent (mcjty.rftoolscontrol.logic.compiled.CompiledEvent)7 ICompiledOpcode (mcjty.rftoolscontrol.api.code.ICompiledOpcode)6 CompiledOpcode (mcjty.rftoolscontrol.logic.compiled.CompiledOpcode)6 ItemStack (net.minecraft.item.ItemStack)4 NBTTagString (net.minecraft.nbt.NBTTagString)4 DefaultSidedInventory (mcjty.lib.container.DefaultSidedInventory)2 ProgException (mcjty.rftoolscontrol.logic.running.ProgException)2 IInventory (net.minecraft.inventory.IInventory)2 ISidedInventory (net.minecraft.inventory.ISidedInventory)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 RunningProgram (mcjty.rftoolscontrol.logic.running.RunningProgram)1