Search in sources :

Example 6 with CompiledOpcode

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

the class Commands method showCurrent.

private static void showCurrent(ProcessorTileEntity processor, int i, RunningProgram program) {
    CompiledOpcode currentOpcode = program.getCurrentOpcode(processor);
    int x = currentOpcode.getGridX();
    int y = currentOpcode.getGridY();
    String id = currentOpcode.getOpcode().getId();
    processor.log("Core " + i + ": [" + x + "," + y + "] " + id);
    if (program.getLock() != null) {
        processor.log(TextFormatting.YELLOW + "[LOCKED on " + program.getLock() + "]!");
    }
}
Also used : CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode)

Example 7 with CompiledOpcode

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

the class ProcessorTileEntity method handleEventsRedstoneOn.

private void handleEventsRedstoneOn(int i, CompiledCard compiledCard, String node, int prevMask, int newMask) {
    int redstoneOnMask = newMask & ~prevMask;
    if (redstoneOnMask != 0) {
        for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_REDSTONE_ON)) {
            int index = event.getIndex();
            CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
            BlockSide side = evaluateSideParameter(compiledOpcode, null, 0);
            if (side != null && node.equals(side.getNodeName())) {
                EnumFacing facing = side.getSide();
                if (facing == null || ((redstoneOnMask >> facing.ordinal()) & 1) == 1) {
                    runOrQueueEvent(i, event, null, null);
                }
            }
        }
    }
}
Also used : ICompiledOpcode(mcjty.rftoolscontrol.api.code.ICompiledOpcode) CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode) EnumFacing(net.minecraft.util.EnumFacing) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent)

Example 8 with CompiledOpcode

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

the class ProcessorTileEntity method handleEventsCraftResume.

private void handleEventsCraftResume(int cardIndex, CompiledCard compiledCard) {
    for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_CRAFTRESUME)) {
        int index = event.getIndex();
        CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
        int ticks = evaluateIntParameter(compiledOpcode, null, 0);
        if (ticks > 0 && tickCount % ticks == 0) {
            if (!waitingForItems.isEmpty()) {
                WaitForItem found = null;
                int foundIdx = -1;
                for (int i = 0; i < waitingForItems.size(); i++) {
                    WaitForItem wfi = waitingForItems.get(i);
                    if (wfi.getInventory() == null || wfi.getItemStack().isEmpty()) {
                        foundIdx = i;
                        found = wfi;
                        break;
                    } else {
                        IItemHandler handler = getItemHandlerAt(wfi.getInventory());
                        int cnt = countItemInHandler(wfi.getItemStack(), handler);
                        if (cnt >= wfi.getItemStack().getCount()) {
                            foundIdx = i;
                            found = wfi;
                            break;
                        }
                    }
                }
                if (found != null) {
                    waitingForItems.remove(foundIdx);
                    runOrQueueEvent(cardIndex, event, found.getTicket(), null);
                }
            }
        }
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) ICompiledOpcode(mcjty.rftoolscontrol.api.code.ICompiledOpcode) CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent)

Example 9 with CompiledOpcode

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

the class ProcessorTileEntity method handleEventsRedstoneOff.

private void handleEventsRedstoneOff(int i, CompiledCard compiledCard, String node, int prevMask, int newMask) {
    int redstoneOffMask = prevMask & ~newMask;
    if (redstoneOffMask != 0) {
        for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_REDSTONE_OFF)) {
            int index = event.getIndex();
            CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
            BlockSide side = evaluateSideParameter(compiledOpcode, null, 0);
            if (side != null && node.equals(side.getNodeName())) {
                EnumFacing facing = side.getSide();
                if (facing == null || ((redstoneOffMask >> facing.ordinal()) & 1) == 1) {
                    runOrQueueEvent(i, event, null, null);
                }
            }
        }
    }
}
Also used : ICompiledOpcode(mcjty.rftoolscontrol.api.code.ICompiledOpcode) CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode) EnumFacing(net.minecraft.util.EnumFacing) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent)

Example 10 with CompiledOpcode

use of mcjty.rftoolscontrol.logic.compiled.CompiledOpcode 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)

Aggregations

CompiledOpcode (mcjty.rftoolscontrol.logic.compiled.CompiledOpcode)14 ICompiledOpcode (mcjty.rftoolscontrol.api.code.ICompiledOpcode)12 CompiledEvent (mcjty.rftoolscontrol.logic.compiled.CompiledEvent)12 CompiledCard (mcjty.rftoolscontrol.logic.compiled.CompiledCard)6 NBTTagString (net.minecraft.nbt.NBTTagString)4 EnumFacing (net.minecraft.util.EnumFacing)4 IItemHandler (net.minecraftforge.items.IItemHandler)3 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 ItemStack (net.minecraft.item.ItemStack)2 IOpcodeRunnable (mcjty.rftoolscontrol.api.code.IOpcodeRunnable)1 RunningProgram (mcjty.rftoolscontrol.logic.running.RunningProgram)1