Search in sources :

Example 1 with CompiledOpcode

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

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

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

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

Example 5 with CompiledOpcode

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

the class ProcessorTileEntity method handleEventsTimer.

private void handleEventsTimer(int i, CompiledCard compiledCard) {
    for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_TIMER)) {
        int index = event.getIndex();
        CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
        int ticks = evaluateIntParameter(compiledOpcode, null, 0);
        if (ticks > 0 && tickCount % ticks == 0) {
            runOrDropEvent(i, event, null, null);
        }
    }
}
Also used : ICompiledOpcode(mcjty.rftoolscontrol.api.code.ICompiledOpcode) CompiledOpcode(mcjty.rftoolscontrol.logic.compiled.CompiledOpcode) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent)

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