Search in sources :

Example 1 with ProgException

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

the class ProcessorTileEntity method getEnergyLong.

@Override
public long getEnergyLong(Inventory side) {
    TileEntity te = getTileEntityAt(side);
    EnergyTools.EnergyLevelMulti level = EnergyTools.getEnergyLevelMulti(te);
    if (level.getMaxEnergy() >= 0) {
        throw new ProgException(EXCEPT_NORF);
    }
    return level.getEnergy();
}
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 2 with ProgException

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

the class ProcessorTileEntity method craftFail.

public void craftFail(IProgram program) {
    if (!program.hasCraftTicket()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTTICKET);
    }
    String ticket = program.getCraftTicket();
    for (BlockPos p : craftingStations) {
        TileEntity te = getWorld().getTileEntity(p);
        if (te instanceof CraftingStationTileEntity) {
            CraftingStationTileEntity craftingStation = (CraftingStationTileEntity) te;
            craftingStation.craftFail(ticket);
        }
    }
}
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)

Example 3 with ProgException

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

the class ProcessorTileEntity method getStorageScanner.

private IStorageScanner getStorageScanner() {
    int card = getStorageCard();
    if (card == -1) {
        throw new ProgException(EXCEPT_MISSINGSTORAGECARD);
    }
    ItemStack storageStack = getStackInSlot(card);
    if (!storageStack.hasTagCompound()) {
        throw new ProgException(EXCEPT_MISSINGSTORAGECARD);
    }
    NBTTagCompound tagCompound = storageStack.getTagCompound();
    BlockPos c = new BlockPos(tagCompound.getInteger("monitorx"), tagCompound.getInteger("monitory"), tagCompound.getInteger("monitorz"));
    int dim = tagCompound.getInteger("monitordim");
    World world = DimensionManager.getWorld(dim);
    if (world == null) {
        throw new ProgException(EXCEPT_MISSINGSTORAGE);
    }
    if (!WorldTools.chunkLoaded(world, c)) {
        throw new ProgException(EXCEPT_MISSINGSTORAGE);
    }
    TileEntity te = world.getTileEntity(c);
    if (te == null) {
        throw new ProgException(EXCEPT_MISSINGSTORAGE);
    }
    if (!(te instanceof IStorageScanner)) {
        throw new ProgException(EXCEPT_MISSINGSTORAGE);
    }
    return (IStorageScanner) te;
}
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) IStorageScanner(mcjty.rftools.api.storage.IStorageScanner) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World)

Example 4 with ProgException

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

the class ProcessorTileEntity method getIngredientsSmart.

public int getIngredientsSmart(IProgram program, Inventory inv, @Nonnull Inventory cardInv, ItemStack item, int slot1, int slot2, @Nonnull Inventory destInv) {
    IStorageScanner scanner = getScannerForInv(inv);
    IItemHandler handler = getHandlerForInv(inv);
    if (item.isEmpty()) {
        item = getCraftResult(program);
    }
    if (item.isEmpty()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTRESULT);
    }
    IItemHandler destHandler = getHandlerForInv(destInv);
    if (destHandler == null) {
        throw new ProgException(EXCEPT_INVALIDINVENTORY);
    }
    IItemHandler cardHandler = getItemHandlerAt(cardInv);
    ItemStack card = findCraftingCard(cardHandler, item);
    if (card.isEmpty()) {
        throw new ProgException(EXCEPT_MISSINGCRAFTINGCARD);
    }
    CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
    List<ItemStack> ingredients;
    if (CraftingCardItem.fitsGrid(card) && (slot2 - slot1 >= 8)) {
        // We have something that fits a crafting grid and we have enough room for a 3x3 grid
        ingredients = CraftingCardItem.getIngredientsGrid(card);
    } else {
        ingredients = CraftingCardItem.getIngredients(card);
    }
    boolean strictnbt = CraftingCardItem.isStrictNBT(card);
    List<ItemStack> needed = combineIngredients(ingredients);
    int requested = checkAvailableItemsAndRequestMissing(destInv, scanner, handler, needed);
    if (requested != 0) {
        return requested;
    }
    // We got everything;
    IItemHandler itemHandler = getItemHandler();
    int slot = slot1;
    for (ItemStack ingredient : ingredients) {
        int realSlot = info.getRealSlot(slot);
        if (!ingredient.isEmpty()) {
            ItemStack stack = InventoryTools.extractItem(handler, scanner, ingredient.getCount(), true, false, strictnbt, ingredient, null);
            if (!stack.isEmpty()) {
                itemHandler.insertItem(realSlot, stack, false);
            }
        }
        slot++;
    }
    return 0;
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) IItemHandler(net.minecraftforge.items.IItemHandler) IStorageScanner(mcjty.rftools.api.storage.IStorageScanner) ItemStack(net.minecraft.item.ItemStack)

Example 5 with ProgException

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

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