Search in sources :

Example 11 with CompiledEvent

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

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

Example 13 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) {
    int redstoneOnMask = powerLevel & ~prevIn;
    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 || !side.hasNodeName()) {
                EnumFacing facing = side == null ? null : 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 14 with CompiledEvent

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

the class ProcessorTileEntity method signal.

@Override
public int signal(Tuple location) {
    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_GFX_SELECT)) {
                int index = event.getIndex();
                runOrQueueEvent(i, event, null, Parameter.builder().type(ParameterType.PAR_TUPLE).value(ParameterValue.constant(location)).build());
                cnt++;
            }
        }
    }
    return cnt;
}
Also used : CompiledCard(mcjty.rftoolscontrol.logic.compiled.CompiledCard) CompiledEvent(mcjty.rftoolscontrol.logic.compiled.CompiledEvent)

Example 15 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) {
    int redstoneOffMask = prevIn & ~powerLevel;
    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 || !side.hasNodeName()) {
                EnumFacing facing = side == null ? null : 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