Search in sources :

Example 6 with CompiledEvent

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

Example 7 with CompiledEvent

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

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

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

the class ProcessorTileEntity method readEventQueue.

private void readEventQueue(NBTTagCompound tagCompound) {
    eventQueue.clear();
    NBTTagList eventQueueList = tagCompound.getTagList("events", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < eventQueueList.tagCount(); i++) {
        NBTTagCompound tag = eventQueueList.getCompoundTagAt(i);
        int card = tag.getInteger("card");
        int index = tag.getInteger("index");
        boolean single = tag.getBoolean("single");
        String ticket = tag.hasKey("ticket") ? tag.getString("ticket") : null;
        Parameter parameter = null;
        if (tag.hasKey("parameter")) {
            parameter = ParameterTools.readFromNBT(tag.getCompoundTag("parameter"));
        }
        eventQueue.add(new QueuedEvent(card, new CompiledEvent(index, single), ticket, parameter));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 10 with CompiledEvent

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

Aggregations

CompiledEvent (mcjty.rftoolscontrol.logic.compiled.CompiledEvent)15 ICompiledOpcode (mcjty.rftoolscontrol.api.code.ICompiledOpcode)12 CompiledOpcode (mcjty.rftoolscontrol.logic.compiled.CompiledOpcode)12 CompiledCard (mcjty.rftoolscontrol.logic.compiled.CompiledCard)7 NBTTagString (net.minecraft.nbt.NBTTagString)5 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 RunningProgram (mcjty.rftoolscontrol.logic.running.RunningProgram)2 IInventory (net.minecraft.inventory.IInventory)2 ISidedInventory (net.minecraft.inventory.ISidedInventory)2 ItemStack (net.minecraft.item.ItemStack)2 CpuCore (mcjty.rftoolscontrol.logic.running.CpuCore)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1