There are two official optional rulesets for crafting
Both are optional and require that you work with your DM as to if they're an option and how they'd work. In either place that these rules appear, they are optional variants to the base rules.
Dungeon Master's Guide
The first official optional rules released appear in the Dungeon Master's Guide in chapter 6 as part of the "Downtime Activities" section:
Crafting a Magic Item
Magic items are the DM’s purview, so you decide how they fall into the party’s possession. As an option, you can allow player characters to craft magic items.
Within these rules, there are the following requirements:
- a formula that describes the construction of the item
- the character must also be a spellcaster with spell slots and must be able to cast any spells that the item can produce (and expends the relevant spell cost each day during crafting)
- the character must meet a level minimum determined by the item’s rarity
- a required gold and time cost to craft the item during downtime (consumable cost half as much as other magic items)
\begin{array}{c|c|c}
\text{Rarity}&\text{Cost}&\text{Minimum Level}\\
\hline \text{Common}&\text{100 gp}&\text{3}\\
\text{Uncommon}&\text{500 gp}&\text{3}\\
\text{Rare}&\text{5,000 gp}&\text{6}\\
\text{Very Rare}&\text{50,000 gp}&\text{11}\\
\text{Legendary}&\text{500,000 gp}&\text{17}\\
\end{array}
Xanathar's Guide to Everything
An alternative ruleset is part of the optional variant to downtime as a whole (and one I personally think is more fleshed out) that appears in the supplement Xanathar's Guide to Everything in the "Downtime Revisited" section of chapter 2:
Crafting Magic Items. Creating a magic item requires more than just time, effort, and materials. It is a long-term process that involves one or more adventures to track down rare materials and the lore needed to create the item.
Within these rules, there are the following requirements:
- a formula for a magic item in order to create it
- an exotic material to complete it. This material can range from the skin of a yeti to a vial of water taken from a whirlpool on the Elemental Plane of Water. Finding that material should take place as part of an adventure. (the suggested challenge rating of the creature to face, though not necessarily harvest the material from, appears in the table below)
- whatever tool proficiency is appropriate, as for crafting a nonmagical object, or proficiency in the Arcana skill.
- a required gold and time cost to craft the item during downtime (consumable cost half as much as other magic items). Do note that downtime rules as a whole are revised when using the Xanathar's Guide to Everything rules
\begin{array}{c|c|c|c}
\text{Rarity}&\text{Challenge Rating}&\text{Time}&\text{Cost}\\
\hline \text{Common}&\text{1-3}&\text{1 workweek}&\text{50 gp}\\
\text{Uncommon}&\text{4-8}&\text{2 workweeks}&\text{200 gp}\\
\text{Rare}&\text{9-12}&\text{10 workweeks}&\text{2,000 gp}\\
\text{Very Rare}&\text{13-18}&\text{25 workweeks}&\text{20,000 gp}\\
\text{Legendary}&\text{19+}&\text{50 workweeks}&\text{100,000 gp}\\
\end{array}
No effect directly, explicitly, and exactly duplicates an object instantaneously
The game doesn't want this to happen because it then expects the user of such an effect to go around duplicating +5 vorpal scimitars and stuff. Even were such an effect limited to mundane items, duplicating wealth like coins, gems, art objects, and trade goods quickly becomes an issue.
The nearest spell is the 0-level Sor/Wiz spell amanuensis [trans] (Spell Compendium 9), but even that spell remains problematic despite the fact that the "spell copies only nonmagical text, not illustrations or magical writings" because raw text exists that has value beyond the page on which its stored rather than its price as a work of art possessing intrinsic value.
Anyway, there are workarounds, but they require very careful consideration.
Rather than duplicating exactly, making the same thing repeatedly can be done using the 5th-level Sor/Wiz spell fabricate [trans] (PH 229). The magic item Murlynd's hat (Dragon #359 73-4) (72,000 gp; 0 lbs.), in addition to other effects, grants the wearer 3/day the ability to use an effect like the spell fabricate. A plot could be constructed around the painter being beholden to a fellow who occasionally lends the painter such a hat, with the lender seeking revenge after the PCs disrupt his income.
Alternatively, a rejkar (Monster Manual III 140) can use at will as a spell-like fabricate as a level 5 caster.
It can fabricate at will, and it's a genius. Don't judge.
According to the Planar Handbook a caster could substitute the rejkar for another creature on his list of creatures available for the spell summon monster V [conj] (PH 286, 287), but as the rejkar has only 5 Hit Dice it can also be bound using the 5th-level Sor/Wiz spell lesser planar binding [conj] (PH 261-2). Note that a rejkar normally has the Craft skills armorsmithing, carpentry, and weaponsmithing, but a generous DM may allow that to be changed as a house rule either by a skilled caster (e.g. a Knowledge (the planes) skill check (DC 25)) or a caster with an appropriate feat (e.g. Fiendish Summoning Specialist (PlH 39)). Even if it lacks the skill ranks, an untrained rejkar can take 10 on a Craft skill to hit DC 15. (A typical rejkar has an Intelligence score of 20. I'm not even kidding.)
Alternatively, a rejkar could be using the painter instead of vice versa. It's a crafty devil ram with abilities that make it, with some modification, an interesting low-level boss monster. (It's also easier for the DM to justify non-standard skills for a custom rejkar.)
As a spell-like ability fabricate has no material components, making it even more powerful and even more liable to break a campaign's economy casually than typical uses of the spell. Be careful.
The 6th-level corrupt spell consume likeness [necro] (Book of Vile Darkness 89) lends itself to a great many plots. Depending on the DM's interpretation of the spell's duplication of the consumed creature's equipment, the painter may not have even created the painting himself, instead having killed the original artist and cast the spell consume likeness on the original artist's corpse which had on its person at the time the painting that is now so popular and valuable. When the painter needs to sell another, he secretly assumes the likeness of the dead original painter, drops the painting, then assumes his own form once more, painting remaining intact.
This sets an incredibly dangerous precedent, but a manageable one if the spell's kept sufficiently obscure. In addition, the spell's also evil (presumably because cannibalism), and its effect is fragile. (The spell's permanent duration means an effect like dispel magic et al. ends the ersatz painter's consume likeness effect.)
To commit such a plot, a level 2 NPC could've purchased a single scroll of consume likeness (6th-level spell at caster level 11) (1,650 gp; 0 lbs.), committed the murder, and after deciphering the scroll gotten only marginally lucky on the caster level check (DC 12) to cast the spell. Thereafter, he'd likely avoid any possibility of exposure to an effect like the spell dispel magic, maybe even going so far as becoming mysterious recluse (or just buying a ring of counterspells (DMG 230) (4,000 gp; 0 lbs.) or adding his magic weapon the magic weapon special ability spellblade (PG 120) (6,000 gp; 0 lbs.)).
That said, any effect allowing duplicating items of value will be difficult to reign in once introduced. Weigh the ramifications carefully, and be sure to have a backup plan if things start going south, even if that plan is something as dumb as Asmodeus eradicating all the rejkars.
Best Answer
Your main tool is the 2nd level Ritual Spell, Magic Mouth
I'm going to borrow the basics from The Arcane Programmer Guide, but I highly recommend reading the whole thing if you want some properly comprehensive rules on this subject.
The essence of how Arcane Programming works, RAW, in 5th edition D&D, is that the spell Magic Mouth has the following very important properties:
Using these principles, we can build logic gates.
A Basic Example
For example, to build a Remote Alarm:
We've created an alarm system that also has a safety switch: if you want to allow someone through, you push the lever down, let them through, and then raise the lever again.
A Clock
We can improve. For example, create two Magic Mouths. Instruct one to, when it hears "I", say "O", and the other, upon hearing "O", say "I". Then, speak in the same tone used to create the second one, "I", and now, both mouths will alternate between saying "I" and "O" over and over, indefinitely. You now have a clock.
So the alarm system mentioned earlier? Scatter monitoring mouths around the base, and put clocks in range of them. Then, their trigger is
So now the alarm will trigger indefinitely, unless shut off. No more 10 minute time limit!
Logic Gates
Magical Defenses
Glyph of Warding spells are one-time-use only, but if there's an intruder inside the base, that's probably the situation they're called for. Glyph of Warding spells are also able to take complex instructions, so long as they're still primed to react to someone, so for example:
So like with the Alarm example, set up a magic mouth (or several...) to repeat, while a lever is up, the letter "D", and only stop while the lever is down. You now have a Glyph of Warding that will only trigger so long as the safety is off.
Conclusion
The limitation on this spell pretty much comes down to the physical limitations of the spell (which can be easily circumvented) and your own personal creativity. So experiment and read the guide I linked above, and figure out what you can do.