Bringing a Stardew Valley Content Patcher mod up to date
I needed a distraction recently so I worked on an unofficial update to someone else's Content Patcher mod. I'm not including the entire mod here because I don't have permission (I just edited their code to match 1.6 for my own game). It might be useful for someone else who needs to alter a similar mod.
(Technically the 1.5 version should work? There was just one minor change that I made in the actual code by deleting 2 characters.)
In their very simplest form, mods that use Content Patcher (like mine) to patch content have at least 2 files: content.json and manifest.json. Manifest.json is used to tell SMAPI about your mod; who made it, the general description, what version it is, where you can find updates, and what other mods it depends on. Content.json is where you actually tell the system what you're changing.
I took a mod called "use gems to craft prismatic shards", which is a 1.5 mod that just uses Content Patcher to add an extra crafting recipe for an item specifically in the game: namely, the prismatic shard. This isn't needed as much anymore as later features make it a bit easier to get without modifications, but still, it's kind of fun if you have a few extra gems.
Before I get into the technical stuff, I thought I'd explain Item IDs. Item IDs are how the game identifies all the objects in the game. Up until recently (1.6, possibly as early as 1.5), all Item IDs were numerical values, and some conflicted with each other (for example, you could have a wallpaper #74 and an object #74). This caused a lot of hilarity, especially since it doesn't look like ConcernedApe quite expected his game too get quite so popular. If you ever see someone playing with a farmer, pet, or animal named [74] or similar, that is taking advantage of a glitch with Item IDs that has been allowed to remain for most platforms. This also allowed players in earlier versions of the game to get one of the best weapons in the game by hauling themselves to a certain location in the game with the right wallpaper, and create a certain hilarious clothing item by using a staircase. This has been fixed somewhat in 1.6 but you can still get away with a lot of exploits using item ID.
Here's the lines I modified:
content.json, line 1: "Format": "2.4.0",
content.json, line 8: "Prismatic Ascent": "60 1 62 1 64 1 66 1 68 1 70 1 72 1/Home/74/false/Mining 7/",
In case you're wondering, here's what the changes break down to:
line 1 specifies the Content Patcher version or later this mod should work with. The current version as I write this is 2.4.4; 2.4.0 is the current major version. I don't know if this was required to make the mod work but I figured it didn't hurt.
line 8 is the meat of the change. It patches an additional crafting recipe into the game, and breaks down like this:
* This recipe is called "Prismatic Ascent" (this is the name the mod creator gave it, and since all I'm doing is fixing things I'm not changing that).
* The items needed are 1 each of Item ID 60, 62, 64, 66, 68, 70, and 72. In this case, a rainbow of gems that you can get from the mines. 1.6 keeps a lot of the same format for Item IDs in its game files as 1.5, therefore I did as well.
* The next item, "home", is not used but it didn't need to be changed, so I left it in.
* The next item, "74", is the item ID for the Prismatic Shard in the game files. 1.6 introduced new ways of referring to a lot of item IDs but the game's data still uses the older versions, so I'm keeping this the same.
* After that is whether the item is a Big Craftable (such as a machine, but as I discovered on a different mod, Big Craftable covers many, many things!) - in this case, it is not, so false.
* The last entry (there's an optional one, but the original mod author ignored it and so am I) is the trigger conditions - in this case, the player needs to be at Mining skill level 7. There was a slight change in how craftable non-food objects are handled in 1.6, so instead of the original mod author's "s Mining 7" I just have "Mining 7" to bring it in line with the canon data.
You can alter existing recipes as well with the same mechanics - suppose I wanted to change the ingredients for Explosive Ammo from 1 iron bar and 2 coal to 5 iron ore and 3 coal (still basically the same ingredients, but more easily craftable in places like the Skull Caverns where there's plenty of iron ore but a lack of iron bars). I would just change the lines from this:
"Explosive Ammo": "335 1 382 2/Home/441 5/false/Combat 8/",
to this:
"Explosive Ammo": "380 5 382 1/Home/441 5/false/Combat 8/",
If I had the item ID, I could also sub in 1 quartz for 1-2 of the coals! It's very flexible.
(Technically the 1.5 version should work? There was just one minor change that I made in the actual code by deleting 2 characters.)
In their very simplest form, mods that use Content Patcher (like mine) to patch content have at least 2 files: content.json and manifest.json. Manifest.json is used to tell SMAPI about your mod; who made it, the general description, what version it is, where you can find updates, and what other mods it depends on. Content.json is where you actually tell the system what you're changing.
I took a mod called "use gems to craft prismatic shards", which is a 1.5 mod that just uses Content Patcher to add an extra crafting recipe for an item specifically in the game: namely, the prismatic shard. This isn't needed as much anymore as later features make it a bit easier to get without modifications, but still, it's kind of fun if you have a few extra gems.
Before I get into the technical stuff, I thought I'd explain Item IDs. Item IDs are how the game identifies all the objects in the game. Up until recently (1.6, possibly as early as 1.5), all Item IDs were numerical values, and some conflicted with each other (for example, you could have a wallpaper #74 and an object #74). This caused a lot of hilarity, especially since it doesn't look like ConcernedApe quite expected his game too get quite so popular. If you ever see someone playing with a farmer, pet, or animal named [74] or similar, that is taking advantage of a glitch with Item IDs that has been allowed to remain for most platforms. This also allowed players in earlier versions of the game to get one of the best weapons in the game by hauling themselves to a certain location in the game with the right wallpaper, and create a certain hilarious clothing item by using a staircase. This has been fixed somewhat in 1.6 but you can still get away with a lot of exploits using item ID.
Here's the lines I modified:
content.json, line 1: "Format": "2.4.0",
content.json, line 8: "Prismatic Ascent": "60 1 62 1 64 1 66 1 68 1 70 1 72 1/Home/74/false/Mining 7/",
In case you're wondering, here's what the changes break down to:
line 1 specifies the Content Patcher version or later this mod should work with. The current version as I write this is 2.4.4; 2.4.0 is the current major version. I don't know if this was required to make the mod work but I figured it didn't hurt.
line 8 is the meat of the change. It patches an additional crafting recipe into the game, and breaks down like this:
* This recipe is called "Prismatic Ascent" (this is the name the mod creator gave it, and since all I'm doing is fixing things I'm not changing that).
* The items needed are 1 each of Item ID 60, 62, 64, 66, 68, 70, and 72. In this case, a rainbow of gems that you can get from the mines. 1.6 keeps a lot of the same format for Item IDs in its game files as 1.5, therefore I did as well.
* The next item, "home", is not used but it didn't need to be changed, so I left it in.
* The next item, "74", is the item ID for the Prismatic Shard in the game files. 1.6 introduced new ways of referring to a lot of item IDs but the game's data still uses the older versions, so I'm keeping this the same.
* After that is whether the item is a Big Craftable (such as a machine, but as I discovered on a different mod, Big Craftable covers many, many things!) - in this case, it is not, so false.
* The last entry (there's an optional one, but the original mod author ignored it and so am I) is the trigger conditions - in this case, the player needs to be at Mining skill level 7. There was a slight change in how craftable non-food objects are handled in 1.6, so instead of the original mod author's "s Mining 7" I just have "Mining 7" to bring it in line with the canon data.
You can alter existing recipes as well with the same mechanics - suppose I wanted to change the ingredients for Explosive Ammo from 1 iron bar and 2 coal to 5 iron ore and 3 coal (still basically the same ingredients, but more easily craftable in places like the Skull Caverns where there's plenty of iron ore but a lack of iron bars). I would just change the lines from this:
"Explosive Ammo": "335 1 382 2/Home/441 5/false/Combat 8/",
to this:
"Explosive Ammo": "380 5 382 1/Home/441 5/false/Combat 8/",
If I had the item ID, I could also sub in 1 quartz for 1-2 of the coals! It's very flexible.