Search in sources :

Example 1 with CompiledCard

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

the class ProcessorTileEntity method redstoneNodeChange.

public void redstoneNodeChange(int previousMask, int newMask, String node) {
    for (int i = 0; i < cardInfo.length; i++) {
        CardInfo info = cardInfo[i];
        CompiledCard compiledCard = info.getCompiledCard();
        if (compiledCard != null) {
            handleEventsRedstoneOn(i, compiledCard, node, previousMask, newMask);
            handleEventsRedstoneOff(i, compiledCard, node, previousMask, newMask);
        }
    }
}
Also used : CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard)

Example 2 with CompiledCard

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

the class ProcessorTileEntity method exception.

public void exception(ExceptionType exception, @Nullable RunningProgram program) {
    // For too many events exception we don't want to queue another event for obvious reasons
    if (exception != EXCEPT_TOOMANYEVENTS) {
        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_EXCEPTION)) {
                    int index = event.getIndex();
                    CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
                    String code = evaluateStringParameter(compiledOpcode, null, 0);
                    if (exception.getCode().equals(code)) {
                        runOrQueueEvent(i, event, program == null ? null : program.getCraftTicket(), null);
                        return;
                    }
                }
            }
        }
    }
    String message;
    if (program != null) {
        CompiledCard card = getCompiledCard(program.getCardIndex());
        if (card == null) {
            message = TextFormatting.RED + "INTERNAL: " + exception.getDescription();
        } else {
            CompiledOpcode opcode = program.getCurrentOpcode(this);
            int gridX = opcode.getGridX();
            int gridY = opcode.getGridY();
            message = TextFormatting.RED + "[" + gridX + "," + gridY + "] " + exception.getDescription();
        }
    } else {
        message = TextFormatting.RED + exception.getDescription();
    }
    lastException = message;
    lastExceptionTime = System.currentTimeMillis();
    log(message);
}
Also used : CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard) ICompiledOpcode(mcjty.rftoolscontrol.api.code.ICompiledOpcode) CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 3 with CompiledCard

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

the class ProcessorTileEntity method signal.

@Override
public int signal(String signal) {
    int cnt = 0;
    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_SIGNAL)) {
                int index = event.getIndex();
                CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
                String sig = evaluateStringParameter(compiledOpcode, null, 0);
                if (signal.equals(sig)) {
                    runOrQueueEvent(i, event, null, null);
                    cnt++;
                }
            }
        }
    }
    return cnt;
}
Also used : CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard) ICompiledOpcode(mcjty.rftoolscontrol.api.code.ICompiledOpcode) CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 4 with CompiledCard

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

the class ProcessorTileEntity method handleCall.

public void handleCall(IProgram program, String signal) {
    RunningProgram p = (RunningProgram) program;
    CardInfo info = this.cardInfo[p.getCardIndex()];
    CompiledCard compiledCard = info.getCompiledCard();
    if (compiledCard != null) {
        for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_SIGNAL)) {
            int index = event.getIndex();
            CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
            String sig = evaluateStringParameter(compiledOpcode, null, 0);
            if (signal.equals(sig)) {
                p.pushCall(p.getCurrentOpcode(this).getPrimaryIndex());
                p.setCurrent(event.getIndex());
                return;
            }
        }
    }
    throw new ProgException(EXCEPT_MISSINGSIGNAL);
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard) ICompiledOpcode(mcjty.rftoolscontrol.api.code.ICompiledOpcode) CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent) RunningProgram(mcjty.rftoolscontrol.logic.running.RunningProgram) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 5 with CompiledCard

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

the class ProcessorTileEntity method receiveMessage.

public void receiveMessage(String name, @Nullable Parameter value) {
    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_MESSAGE)) {
                int index = event.getIndex();
                CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
                String messageName = evaluateStringParameter(compiledOpcode, null, 0);
                if (name.equals(messageName)) {
                    runOrQueueEvent(i, event, null, value);
                }
            }
        }
    }
}
Also used : CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard) ICompiledOpcode(mcjty.rftoolscontrol.api.code.ICompiledOpcode) CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent) NBTTagString(net.minecraft.nbt.NBTTagString)

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