Search in sources :

Example 16 with ProgException

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

the class ProcessorTileEntity method getAdjacentPosition.

private BlockPos getAdjacentPosition(@Nonnull BlockSide side) {
    BlockPos p;
    if (side.getNodeName() != null && !side.getNodeName().isEmpty()) {
        p = networkNodes.get(side.getNodeName());
        if (p == null) {
            throw new ProgException(EXCEPT_MISSINGNODE);
        }
        TileEntity te = getWorld().getTileEntity(p);
        if (!(te instanceof NodeTileEntity)) {
            throw new ProgException(EXCEPT_MISSINGNODE);
        }
    } else {
        p = pos;
    }
    return p;
}
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) NodeTileEntity(mcjty.rftoolscontrol.blocks.node.NodeTileEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 17 with ProgException

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

the class ProcessorTileEntity method sendMessage.

@Override
public void sendMessage(IProgram program, int idSlot, String messageName, @Nullable Integer variableSlot) {
    if (!hasNetworkCard()) {
        throw new ProgException(EXCEPT_MISSINGNETWORKCARD);
    }
    if (hasNetworkCard != NetworkCardItem.TIER_ADVANCED) {
        throw new ProgException(EXCEPT_NEEDSADVANCEDNETWORK);
    }
    CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
    int realIdSlot = info.getRealSlot(idSlot);
    Integer realVariable = info.getRealVar(variableSlot);
    IItemHandler handler = getItemHandler();
    ItemStack idCard = handler.getStackInSlot(realIdSlot);
    if (idCard.isEmpty() || !(idCard.getItem() instanceof NetworkIdentifierItem)) {
        throw new ProgException(EXCEPT_NOTANIDENTIFIER);
    }
    NBTTagCompound tagCompound = idCard.getTagCompound();
    if (tagCompound == null || !tagCompound.hasKey("monitorx")) {
        throw new ProgException(EXCEPT_INVALIDDESTINATION);
    }
    int monitordim = tagCompound.getInteger("monitordim");
    int monitorx = tagCompound.getInteger("monitorx");
    int monitory = tagCompound.getInteger("monitory");
    int monitorz = tagCompound.getInteger("monitorz");
    WorldServer world = DimensionManager.getWorld(monitordim);
    BlockPos dest = new BlockPos(monitorx, monitory, monitorz);
    if (!WorldTools.chunkLoaded(world, dest)) {
        throw new ProgException(EXCEPT_INVALIDDESTINATION);
    }
    TileEntity te = world.getTileEntity(dest);
    if (!(te instanceof ProcessorTileEntity)) {
        throw new ProgException(EXCEPT_INVALIDDESTINATION);
    }
    ProcessorTileEntity destTE = (ProcessorTileEntity) te;
    destTE.receiveMessage(messageName, realVariable == null ? null : getVariableArray()[realVariable]);
}
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) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 18 with ProgException

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

the class ProcessorTileEntity method fetchItems.

public int fetchItems(IProgram program, Inventory inv, Integer slot, ItemStack itemMatcher, boolean routable, boolean oredict, @Nullable Integer amount, int virtualSlot) {
    if (amount != null && amount == 0) {
        throw new ProgException(EXCEPT_BADPARAMETERS);
    }
    IStorageScanner scanner = getScannerForInv(inv);
    IItemHandler handler = getHandlerForInv(inv);
    CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
    int realSlot = info.getRealSlot(virtualSlot);
    ItemStack stack = InventoryTools.tryExtractItem(handler, scanner, amount, routable, oredict, itemMatcher, slot);
    if (stack.isEmpty()) {
        // Nothing to do
        return 0;
    }
    IItemHandler capability = getItemHandler();
    if (!capability.insertItem(realSlot, stack, true).isEmpty()) {
        // Not enough room. Do nothing
        return 0;
    }
    // All seems ok. Do the real thing now.
    stack = InventoryTools.extractItem(handler, scanner, amount, routable, oredict, false, itemMatcher, slot);
    capability.insertItem(realSlot, stack, false);
    return stack.getCount();
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) IItemHandler(net.minecraftforge.items.IItemHandler) IStorageScanner(mcjty.rftools.api.storage.IStorageScanner) ItemStack(net.minecraft.item.ItemStack)

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