Hello, I've recently been messing around with modding in an attempt to create a new geothermal power plant and a new steam geyser. Those are both working as expected however the PlaceWorker I'm trying to use to limit my geothermal power plants placement is not, I would like it so that it can only be placed on my new steam geyser. I was wondering if someone could review my code to check that it is correct.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewSteamGeyser
{
public class PlaceWorker_OnSteamGeyser2 : PlaceWorker
{
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot)
{
var Restrictions = checkingDef.RestrictedPlacement_Properties();
#if DEBUG
if( Restrictions == null )
{
CCL_Log.Error( "PlaceWorker_OnSteamGeyser2 unable to get properties!", checkingDef.defName );
return AcceptanceReport.WasRejected;
}
#endif
foreach (Thing t in loc.GetThingList())
{
if (Restrictions.RestrictedThing.Contains(t.def))
{
return AcceptanceReport.WasAccepted;
}
}
return (AcceptanceReport)("Place On SteamGeyser2".Translate());
}
public override bool ForceAllowPlaceOver(BuildableDef other)
{
// SteamGeyser2
return (other == ThingDefOf.SteamGeyser2);
}
}
}
EDIT: I've since revised it and now have this though it's still not working:
using System;
using Verse;
namespace NewSteamGeyser
{
public class PlaceWorker_OnlyOnSteamGeyser2 : PlaceWorker
{
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null)
{
Thing thing = map.thingGrid.ThingAt(loc, ThingDef.Named("SteamGeyser2"));
if (thing == null || thing.Position != loc)
{
return "MustPlaceOnSteamGeyser2".Translate();
}
return true;
}
public override bool ForceAllowPlaceOver(BuildableDef otherDef)
{
return otherDef == ThingDef.Named("SteamGeyser2");
}
}
}
Thanks, PleccyMM
Please reformat using code formatting to make this easier to read :(
Like this
Ok have done, sorry for how messy it looked before I'm a bit new to the forums.