Search in sources :

Example 11 with ProgException

use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.

the class ProcessorTileEntity method craftOk.

public void craftOk(IProgram program, @Nullable Integer slot) {
    if (!program.hasCraftTicket()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTTICKET);
    }
    String ticket = program.getCraftTicket();
    CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
    Integer realSlot = info.getRealSlot(slot);
    ItemStack craftedItem = ItemStack.EMPTY;
    if (realSlot != null) {
        craftedItem = getItemHandler().getStackInSlot(realSlot);
    }
    for (BlockPos p : craftingStations) {
        TileEntity te = getWorld().getTileEntity(p);
        if (te instanceof CraftingStationTileEntity) {
            CraftingStationTileEntity craftingStation = (CraftingStationTileEntity) te;
            craftedItem = craftingStation.craftOk(this, ticket, craftedItem);
        }
    }
    if (realSlot != null) {
        // Put back what could not be accepted
        getInventoryHelper().setStackInSlot(realSlot, craftedItem);
    }
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) CraftingStationTileEntity(mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity) WorkbenchTileEntity(mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity) NodeTileEntity(mcjty.rftoolscontrol.blocks.node.NodeTileEntity) MultiTankTileEntity(mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) CraftingStationTileEntity(mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity) BlockPos(net.minecraft.util.math.BlockPos) NBTTagString(net.minecraft.nbt.NBTTagString) ItemStack(net.minecraft.item.ItemStack)

Example 12 with ProgException

use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.

the class ProcessorTileEntity method getParameterFromToken.

@Nullable
public Parameter getParameterFromToken(IProgram program, int slot) {
    CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
    int realSlot = info.getRealSlot(slot);
    ItemStack stack = getItemHandler().getStackInSlot(realSlot);
    if (stack.isEmpty() || !(stack.getItem() instanceof TokenItem)) {
        throw new ProgException(EXCEPT_NOTATOKEN);
    }
    if (!stack.hasTagCompound()) {
        return null;
    }
    NBTTagCompound tag = stack.getTagCompound().getCompoundTag("parameter");
    if (tag.hasNoTags()) {
        return null;
    }
    return ParameterTools.readFromNBT(tag);
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 13 with ProgException

use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.

the class ProcessorTileEntity method getMaxEnergyLong.

@Override
public long getMaxEnergyLong(Inventory side) {
    TileEntity te = getTileEntityAt(side);
    EnergyTools.EnergyLevelMulti level = EnergyTools.getEnergyLevelMulti(te);
    if (level.getMaxEnergy() >= 0) {
        throw new ProgException(EXCEPT_NORF);
    }
    return level.getMaxEnergy();
}
Also used : GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) CraftingStationTileEntity(mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity) WorkbenchTileEntity(mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity) NodeTileEntity(mcjty.rftoolscontrol.blocks.node.NodeTileEntity) MultiTankTileEntity(mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ProgException(mcjty.rftoolscontrol.logic.running.ProgException) EnergyTools(mcjty.lib.varia.EnergyTools)

Example 14 with ProgException

use of mcjty.rftoolscontrol.logic.running.ProgException 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 15 with ProgException

use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.

the class ProcessorTileEntity method pushItemsWorkbench.

public boolean pushItemsWorkbench(IProgram program, @Nonnull BlockSide workbench, ItemStack item, int slot1, int slot2) {
    if (item.isEmpty()) {
        item = getCraftResult(program);
    }
    if (item.isEmpty()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTRESULT);
    }
    TileEntity te = getTileEntityAt(workbench);
    if (!(te instanceof WorkbenchTileEntity)) {
        throw new ProgException(EXCEPT_NOTAWORKBENCH);
    }
    IItemHandler cardHandler = getItemHandlerAt(te, EnumFacing.EAST);
    ItemStack card = findCraftingCard(cardHandler, item);
    if (card.isEmpty()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTINGCARD);
    }
    if (!CraftingCardItem.fitsGrid(card)) {
        throw new ProgException(EXCEPT_NOTAGRID);
    }
    CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
    IItemHandler itemHandler = getItemHandler();
    IItemHandler gridHandler = getItemHandlerAt(te, EnumFacing.UP);
    List<ItemStack> ingredients = CraftingCardItem.getIngredientsGrid(card);
    boolean success = true;
    for (int i = 0; i < 9; i++) {
        ItemStack stackInWorkbench = gridHandler.getStackInSlot(i);
        ItemStack stackInIngredient = ingredients.get(i);
        if (!stackInWorkbench.isEmpty() && stackInIngredient.isEmpty()) {
            // Can't work. There is already something in the workbench that doesn't belong
            success = false;
        } else if (stackInWorkbench.isEmpty() && !stackInIngredient.isEmpty()) {
            // Let's see if we can find the needed ingredient
            boolean found = false;
            for (int slot = slot1; slot <= slot2; slot++) {
                int realSlot = info.getRealSlot(slot);
                ItemStack localStack = itemHandler.getStackInSlot(realSlot);
                if (stackInIngredient.isItemEqual(localStack)) {
                    localStack = itemHandler.extractItem(realSlot, stackInIngredient.getCount(), false);
                    gridHandler.insertItem(i, localStack, false);
                    found = true;
                    break;
                }
            }
            if (!found) {
                success = false;
            }
        } else if (!stackInWorkbench.isEmpty() && !stackInIngredient.isEmpty()) {
            // See if the item matches and we have enough
            if (!stackInIngredient.isItemEqual(stackInWorkbench)) {
                success = false;
            } else if (stackInIngredient.getCount() > stackInWorkbench.getCount()) {
                success = false;
            }
        }
    }
    return success;
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) CraftingStationTileEntity(mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity) WorkbenchTileEntity(mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity) NodeTileEntity(mcjty.rftoolscontrol.blocks.node.NodeTileEntity) MultiTankTileEntity(mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) WorkbenchTileEntity(mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity)

Aggregations

ProgException (mcjty.rftoolscontrol.logic.running.ProgException)18 ItemStack (net.minecraft.item.ItemStack)12 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)8 CraftingStationTileEntity (mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity)8 MultiTankTileEntity (mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity)8 NodeTileEntity (mcjty.rftoolscontrol.blocks.node.NodeTileEntity)8 WorkbenchTileEntity (mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 IItemHandler (net.minecraftforge.items.IItemHandler)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 BlockPos (net.minecraft.util.math.BlockPos)5 IStorageScanner (mcjty.rftools.api.storage.IStorageScanner)4 NBTTagString (net.minecraft.nbt.NBTTagString)3 DefaultSidedInventory (mcjty.lib.container.DefaultSidedInventory)2 EnergyTools (mcjty.lib.varia.EnergyTools)2 ICompiledOpcode (mcjty.rftoolscontrol.api.code.ICompiledOpcode)2 CompiledCard (mcjty.rftoolscontrol.logic.compiled.CompiledCard)2 CompiledEvent (mcjty.rftoolscontrol.logic.compiled.CompiledEvent)2 CompiledOpcode (mcjty.rftoolscontrol.logic.compiled.CompiledOpcode)2 Nullable (javax.annotation.Nullable)1