How do I add things? [Solved]

Started by A_Steam_User, May 29, 2017, 09:43:57 PM

Previous topic - Next topic

A_Steam_User

I want to mod my game. I would like to know how to add recipes and items. I tried to do this by copy/pasting a recipe in D:\Steam\steamapps\common\RimWorld\Mods\Core\Defs\RecipeDefs to make a new one an edited it. I received a few errors when loading the game and I could not find the recipe. Please let me know if I'm doing this wrong and/or a better way to do it.

Thirite

Your surest bet is finding the simplest mod you can which does something similar to what you're looking to achieve. Then open up the mod folder and observe how its constructed and written. From that point it's easy enough to imitate and make your own changes.

jamaicancastle

Keep in mind that you can't modify the Core files directly (well, you can, but the game doesn't like it). You'll want to make your own mod folder to put your changed code in.

I definitely recommend that you take another mod as a starting point, if only for the file structure of the mod itself. The About folder is especially important to get right, and really the easiest way to do it is to copy somebody else's.

Once you have your own mod up and running, try copying and pasting the file you want to modify, then deleting all of the defs (blocks of code separated by blank lines) that you don't want. Important: never delete the first two lines, or the last line, of any given XML file; they're how the game keeps track of what's what. Also, make sure you delete defs completely (from one tag <[something]Def> to the closing tag </[something]Def>); if there's any bits left over the parser goes all squibbly and it throws errors.

Another tip: every def that you want to add to the game, you have to change its defName attribute so that it's unique. If it's the same as a defName in the core or another mod, it will overwrite that one instead of being added alongside it. (The label, what actually shows up in-game, can be the same if you want.)

If you're still having trouble, can you post the errors that you receive?

A_Steam_User

I'm trying to make a mod that adds a recipe to turn plants into silver. I tired looking at other mods and the core mod. Nothing I do shows up in the game accept the about folder. The errors I'm getting are "Could not resolve cross-reference to Verse.ThingDef named PlantFoodRaw" and "Cannot call ItemFromXmlFile with resolveCrossRefs=true while loading is already in progress". What do these mean?

Jaxxa

Feel free to have a look at my OmniGel mod. Sounds like it does what you want.
I have not uploaded the A17 Update yet, but it is mostly the same.

https://github.com/jaxxa/ED-OmniGel

jamaicancastle

Quote from: A_Steam_User on May 30, 2017, 03:33:15 PM
I'm trying to make a mod that adds a recipe to turn plants into silver. I tired looking at other mods and the core mod. Nothing I do shows up in the game accept the about folder. The errors I'm getting are "Could not resolve cross-reference to Verse.ThingDef named PlantFoodRaw" and "Cannot call ItemFromXmlFile with resolveCrossRefs=true while loading is already in progress". What do these mean?

These two errors are related. All the second error means is that because of the first error, it couldn't load data properly.

The first error is that it's looking for a thingDef (a definition for a "thing", or in-game object like a plant, building, or item) named "PlantFoodRaw". There is no such thingDef, so it can't find it.

What you probably mean to be calling is the thingCategory named "PlantFoodRaw", which isn't any one specific item but rather a category holding all of the raw foods' thingDefs. The two are referred to differently in recipes.

  <ingredients>
    <li>
      <filter>
      <thingDefs>
        <li>PlantFoodRaw</li>
      </thingDefs>
      </filter>
      <count>0.5</count>
    </li>
  </ingredients>

will look up one specific item called "PlantFoodRaw", which will throw an error because there isn't such an item.

  <ingredients>
    <li>
      <filter>
      <categories>
        <li>PlantFoodRaw</li>
      </categories>
      </filter>
      <count>0.5</count>
    </li>
  </ingredients>

will look up a category of items called "PlantFoodRaw", which should work.

A_Steam_User

I'm still getting the same error after changing it. Please tell me if anything is wrong with this

<RecipeDef>
    <defName>MakeSilverFromStuff</defName>
    <label>make some silver</label>
    <description>Use chemistry and magic to make silver!</description>
    <jobString>Smelting metal from slag.</jobString>
    <workAmount>50</workAmount>
    <workSpeedStat>SmeltingSpeed</workSpeedStat>
    <effectWorking>Smelt</effectWorking>
    <soundWorking>Recipe_Smelt</soundWorking>
  <ingredients>
    <li>
      <filter>
      <categories>
        <li>PlantFoodRaw</li>
      </categories>
      </filter>
      <count>0.5</count>
    </li>
  </ingredients>
    <products>
      <Silver>10</Silver>
    </products>
    <fixedIngredientFilter>
      <thingDefs>
        <li>PlantFoodRaw</li>
      </thingDefs>
    </fixedIngredientFilter>
  </RecipeDef>

A_Steam_User

Nevermind. I just realized that I didn't change the fixedingrediantfilter to category. How do I know where this recipe is in the game, like what station? I am no longer getting an error.

jamaicancastle

It won't appear at any production structure unless you do one of two things. You can either instruct the recipe to find a structure and add itself, or copy the structure and add the recipe to it explicitly.

The first method looks like this:
  <recipeUsers>
    <li>FueledStove</li>
    <li>ElectricStove</li>
  </recipeUsers>

and goes in the recipe def (right before the final </RecipeDef> is fine.

The second method looks like this:
    <recipes>
      <li>CookMealSimple</li>
      <li>CookMealFine</li>
      <li>CookMealLavish</li>
      <li>CookMealSurvival</li>
      <li>MakePemmican</li>
      <li>[ the name of your new recipe def here ]</li>
    </recipes>

and is a change to the existing code in ThingDefs_Buildings -> Buildings_Production -> the FueledStove and ElectricStove defs.

They both have the exact same effect.

kaptain_kavern

Just to add a bit to the already great explanation from Jamaicancastle :

IIRC Using the first method is recommended (with <recipeUsers> in the item code) because it's more compatible.

Using the 2nd method may cause problem if another mod is also overwriting the same producing bench

A_Steam_User

Thanks everyone! Because of you I have created my first mod. It doesn't do much but at least its a mod. ;D