Skip to content
Nightinggale edited this page Sep 15, 2018 · 1 revision

It's actually possible to clone something in xml and then only write the data you want to change. It's fairly simple. Say you want to add AdvancedWoodFiredGenerator. What you do is writing a Def:

<ThingDef ParentName="WoodFiredGenerator">
	<defName>AdvancedWoodFiredGenerator</defName>

This tells that whatever tag you haven't mentioned will use the value from WoodFiredGenerator. It works as long as the original looks like:

<ThingDef ParentName="BuildingBase" Name="WoodFiredGenerator">
    <defName>WoodFiredGenerator</defName>

The problem is that if you look in vanilla, you will see it looks like:

<ThingDef ParentName="BuildingBase">
    <defName>WoodFiredGenerator</defName>

In other words in order to clone WoodFiredGenerator, Name has to be added. It can be done by patching like this:

<Operation Class="PatchOperationAttributeAdd">
	<xpath>Defs/ThingDef[defName="WoodFiredGenerator"]</xpath>
	<attribute>Name</attribute>
	<value>WoodFiredGenerator</value>
</Operation>

This way there will be a name to set as parent. It works with Core and any other mod, though if you rely on other mods, you might want to look into making an included patchmod.

This works because while loading xml, the order is this:

  • load Defs
  • apply patches
  • resolve links (like looking up parents)

It really doesn't matter that the xml files are invalid when being read just as long as it works once they have been patched.

Clone this wiki locally