Jump to content

[Help Request][Mod] Sink Disposal

Recommended Posts

Hey all!

I'm relatively new to modding (but I do have loads of software engineering experience), and I've set out to build my first ONI mod.

I want to be able to empty bottles into sinks (both from a dual purpose perspective, and from a bottle-to-pipe perspective).

I dabbled a bit in (and plan to go back to) modding Don't Starve Together, which is largely done in Lua, and has a pretty composable structure. I was expecting (hoping?) ONI to be the same. After a couple late nights, I'm relatively cognizant of how Harmony and C# patching works.

I got my first mod loaded and running, but I'm running into an issue. The way I configured the mod has the sink just dumping it's storage onto the ground.

I started just by patching the ConfigureBuildingTemplate for the WashSink adding the `TreeFilterable` component and the `BottleEmptier` component.

After exploring some of the base code, it looks like BottleEmptier reaches up to its "master" object, pulls from its (one and only) storage component, and "Emit"s onto the tile in front of it (depending on its orientation). I can't figure out a way to add a secondary storage component "Storage storage = go.AddOrGet<Storage>();" without crashing the game. My thought was that if I could give the sink a second storage, and then patch the BottleEmptier to use that, it might work.

My next idea is to actually create a new class, something like "BottleDumper", and have that extend "BottleEmptier" (Ok, seriously KLEI, we need inline code tags please), while creating it's own "internal" storage to use, and then to push the contents to the connected output pipe.

Any guidance/suggestions would be greatly appreciated! Thanks so much!!

I'm attaching the mod so far, if that helps! :)

Here is the BottleEmptierConfig.cs

  public override void ConfigureBuildingTemplate(GameObject go, Tag prefab_tag)
    Storage storage = go.AddOrGet<Storage>();
    storage.storageFilters = STORAGEFILTERS.LIQUIDS;
    storage.showInUI = true;
    storage.showDescriptor = true;
    storage.capacityKg = 200f;

Here is the BottleEmptier.cs#Emit method

    public void Emit(float dt)
      PrimaryElement firstPrimaryElement = this.GetFirstPrimaryElement();
      if ((UnityEngine.Object) firstPrimaryElement == (UnityEngine.Object) null)
      Storage component = this.GetComponent<Storage>();
      float num1 = Mathf.Min(firstPrimaryElement.Mass, this.master.emptyRate * dt);
      if ((double) num1 <= 0.0)
      Tag prefabTag = firstPrimaryElement.GetComponent<KPrefabID>().PrefabTag;
      SimUtil.DiseaseInfo disease_info;
      float aggregate_temperature;
      component.ConsumeAndGetDisease(prefabTag, num1, out disease_info, out aggregate_temperature);
      Vector3 position = this.transform.GetPosition();
      position.y += 1.8f;
      bool flag = this.GetComponent<Rotatable>().GetOrientation() == Orientation.FlipH;
      position.x += flag ? -0.2f : 0.2f;
      int num2 = Grid.PosToCell(position) + (flag ? -1 : 1);
      if (Grid.Solid[num2])
        num2 += flag ? 1 : -1;
      Element element = firstPrimaryElement.Element;
      byte idx = element.idx;
      if (element.IsLiquid)
        FallingWater.instance.AddParticle(num2, idx, num1, aggregate_temperature, disease_info.idx, disease_info.count, true);
        SimMessages.ModifyCell(num2, (int) idx, aggregate_temperature, num1, disease_info.idx, disease_info.count);


Kitchen Sink.zip

Link to comment
Share on other sites

You should take a look at the Fliud Shipping mod I think. To me it looks like it does what you want to do, so it may guide the way forward.

There is no link to the source code, but if you go look in the mod folder (Documents\Klei\OxygenNotIncluded\mods\Steam\1794548334 on Windows), you can disassemble the DLL with ILSpy.

I have no experience with modding buildings, so I don't have anything in particular to suggest.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

  • Create New...