Jump to content

[HELP] Custom mob's poop, disease doesn't work


Recommended Posts

I'm currently making a custom mob mod and I wanted it to release contaminated polluted water as poop. I tried looking at Puft's scripts, cuz it seems to have SlimeLung assign to it's poop also, but even that doesn't work in the actual game. It's very odd that you can assign diseasesID and amount at the poop but doesn't work, Is this a bug or is it intended? Is there a work around it?

PuftConfig.cs

BasePuftConfig.cs

Link to comment
Share on other sites

Oh yeah.
if I remember correctly, this error has been present since Ranching mk2 Upgrade.
several people reported in a bug tracker, "puft is marked as a source of germs, but produces germs-free slime", but this has not been fixed.
an error in the Diet.Info constructor, Klei forgot about the disease_per_kg_produced parameter and does not set the diseasePerKgProduced field.

123654.thumb.png.5d49425e8d5ac32403ff79dd97cc20b9.png

Link to comment
Share on other sites

These two look very similiar to me. Probably just the decompiler shifting things around. Anyway, you already found out exactly what the problem with the code is. So, problem solved.

Just in case it's not obvious to you, this is the code:

[HarmonyPatch(typeof(Diet.Info))]
[HarmonyPatch(new Type[] { })]
public class DietPatch
{
 	public static void Postfix(Diet.Info __instance, float disease_per_kg_produced, ref float ___diseasePerKgProduced)
    {
     	 ___diseasePerKgProduced = disease_per_kg_produced;
      	
      	//in case this does not work, you can also try to access diseasePerKgProduced via reflection
      	//  AccessTools.Property(typeof(Diet.Info), "diseasePerKgProduced").SetValue(__instance, disease_per_kg_produced);
    }
}

 

I didn't run this, because I am on the go. But you should get the idea. The info class forgot to retain the disease amount, which should have been stored. I am surprised Klei didn't fix this, if it was in a bug report... since you know, it's very easy to fix.

Link to comment
Share on other sites

I don't know if I'm doing this correctly, because I don't know much about harmony.
I tried patching it like this but it's restricted by the original code, I thought I could override it using this.

Maybe there's a different way to bypass this restriction?

I also tried making my own CustomDiet class by inheriting Diet class, but it just made my critter's diet not work at all.

patch.png

Link to comment
Share on other sites

The setter is private, so accessing it via __instance does not work. You need to use the triple underscore thing (___somePrivateField) which probably doesn't work with properties, or you need to use reflection, as in my example. Does it not work?

Link to comment
Share on other sites

this code will work
 

    [HarmonyPatch(typeof(Diet.Info), MethodType.Constructor)]
    [HarmonyPatch(new Type[] { typeof(HashSet<Tag>), typeof(Tag), typeof(float), typeof(float), typeof(string), typeof(float), typeof(bool), typeof(bool) } )]
    class Patch
    {
        static void Postfix (Diet.Info __instance, float disease_per_kg_produced)
        {
            Traverse.Create(__instance).Property("diseasePerKgProduced").SetValue(disease_per_kg_produced);
        }
    }

 

Link to comment
Share on other sites

4 hours ago, Candide said:

Ha, of course my harmony attribute was wrong. When you define MethodType.Constructor you probably don't even need to define the Type[], since there is only one constructor.

I tried what you said just now, but it caused an error. I think you might really need to define it, thank you anyway. :) 

Link to comment
Share on other sites

Archived

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...