Mistake patching BenchBase?

Started by AileTheAlien, July 02, 2018, 04:11:14 PM

Previous topic - Next topic

AileTheAlien

I'm making a mod with portable camping stoves, and need to make normal stoves (and other benches, for balance) weigh a lot more. (Otherwise, they're too easy to take on caravans.) I followed the guide on patching, but it doesn't seem to affect any of the things which are sub-classing BenchBase. Anyone know what I'm doing wrong?

<?xml version="1.0" encoding="utf-8" ?>
<Defs>
    <!--
    Override the base-game's BenchBase class, so that normal stoves (and benches) are too heavy to take on caravans.
    -->
    <Patch>
        <Operation Class="PatchOperationReplace">
            <xpath>/ThingDefs/ThingDef[Name="BenchBase"]/statBases/Mass</xpath>
            <value>
                <Mass>150</Mass>
            </value>
        </Operation>
    </Patch>
</Defs>


The rest of my mod works just fine. My stoves show up with placeholder art, can cook simple meals, and are craftable at machining tables. Just not sure what's up with this patch! :)

EDIT:
I also tried patching the FueledStove and ElectricStove directly, but those don't have masses defined (it's in the BenchBase), so that's probably why those didn't work?

<Defs>
    <Patch>
        <Operation Class="PatchOperationReplace">
            <xpath>/ThingDefs/ThingDef[defName="FueledStove"]/statBases/Mass</xpath>
            <value>
                <Mass>150</Mass>
            </value>
        </Operation>
    </Patch>
</Defs>

Mehni

#1

The XML structure for RimWorld changed since the guide you're following was written: nowadays all root nodes are Defs.

For example:
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
  <ThingDef ParentName="BuildingBase">
    <defName>CraftingSpot</defName>


The xpath for that would be /Defs/ThingDef[defName="CraftingSpot"]. Root, first childnode, childnode with that specific defName. If you want to target by attribute, such as Name="BenchBase", you use @Name="BenchBase". The @ is one of the many special symbols in xpath; in this case it targets attributes. * would be a wildcard.

Quote from: https://rimworldwiki.com/wiki/Modding_Tutorials/PatchOperationsHere's a simple example of replacing the texture path for deep water:

<?xml version="1.0" encoding="utf-8" ?>
<Patch>
  <Operation Class="PatchOperationReplace">
    <xpath>*/TerrainDef[defName="WaterDeep"]/texturePath</xpath>
    <value>
      <texturePath>Your/Texture/Path/Here</texturePath>
    </value>
  </Operation>
</Patch>

This xml file simply goes inside YourMod/Patches/ and you're done.

Edit: You might wanna read up on xml/xpath in general:
https://www.w3schools.com/xml/
https://www.w3schools.com/xml/xpath_intro.asp

AileTheAlien