I'm working on a mod that copies much of the SteamGeyser code to create oil gushers. The idea is that you build a pump jack on the gusher and then pawns can use the pump to produce barrels of oil.
This is the error:
Object reference not set to an instance of an object
This is the class throwing the error:
using Verse;
namespace BlackGold
{
public class PlaceWorker_OnOilGusher : PlaceWorker
{
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot)
{
Thing thing = Find.ThingGrid.ThingAt(loc, ThingDefOf.OilGusher);
if (thing == null)
{
return "Thing is null: " + thing.ToString();
}
if (thing.Position != loc)
{
return "MustPlaceOnOilGusher".Translate();
}
return true;
}
}
}
I believe that I have need to define some ThingDefs to make this work. Here is my ThingDefOf.cs:
using RimWorld;
using Verse;
namespace BlackGold
{
public static class ThingDefOf
{
public static ThingDef OilGusher;
public static void RebindDefs()
{
DefOfHelper.BindDefsFor<ThingDef>(typeof(ThingDefOf));
}
}
}
Defining a ThingDef in ThingDefOf did not fix the issue though.
Any thoughts?
Your RebindDefs() is never actually called.
You need to add [StaticConstructorAtStartup] to the class.
using RimWorld;
using Verse;
namespace BlackGold
{
[StaticConstructorOnStartup]
public static class ThingDefOf
{
public static ThingDef OilGusher;
public static void RebindDefs()
{
DefOfHelper.BindDefsFor<ThingDef>(typeof(ThingDefOf));
}
static ThingDefOf()
{
RebindDefs();
}
}
}
Thanks for your response, I'm getting build errors - am I missing something simple?
Severity Code Description Project File Line Column Suppression State
Error CS0246 The type or namespace name 'StaticConstructorAtStartupAttribute' could not be found (are you missing a using directive or an assembly reference?) BlackGold C:\Program Files (x86)\RimWorld\Mods\BlackGold\Source\BlackGold\ThingDefOf.cs 6 6 Active
Error CS0246 The type or namespace name 'StaticConstructorAtStartup' could not be found (are you missing a using directive or an assembly reference?) BlackGold C:\Program Files (x86)\RimWorld\Mods\BlackGold\Source\BlackGold\ThingDefOf.cs 6 6 Active
Whoops, it's [StaticConstructorOnStartup] - Sorry about that. :)
Thanks, that solved it.