Jump to content

Better way to detect rooms and new Behavior


Recommended Posts

Hello! I need some help for the development of an class mod: https://mods.vintagestory.at/minerz

The idea is that the hunger rate should be lowered if you are in closed rooms/underground. I used the body temperature behaviour because I have no access to the Rooms-Class (or idk how to access it).

Just like this:

screen.png.82ed71e413f8161b5db4448687c72ff9.png

This is how I do it at the moment but its very ineffective and may needs too much. I would like to create a own behaviour to detect if the player is in a room (or just detect the sun light) and trigger the change. How do I add a new behaviour to the registry ?

    [HarmonyPrefix]
    [HarmonyPatch(typeof(EntityBehaviorBodyTemperature), "OnGameTick")]
    public static void OnBodyTemperatureTickBefore(ref bool ___inEnclosedRoom, ref EntityAgent ___eagent, ref ICoreAPI ___api, ref float ___slowaccum)
    {
        if (___slowaccum > 2)
        {
            if (___inEnclosedRoom && ___api.ModLoader.GetModSystem<CharacterSystem>()
                    .HasTrait((___eagent as EntityPlayer)?.Player, "lovesUnderground"))
            {
                ___eagent.Stats.Set("hungerrate", "minerstat", (float)-hungerrate);
            }
        }
    }
    
    [HarmonyPostfix]
    [HarmonyPatch(typeof(EntityBehaviorBodyTemperature), "OnGameTick")]
    public static void OnBodyTemperatureTickAfter(ref bool ___inEnclosedRoom, ref EntityAgent ___eagent, ref ICoreAPI ___api, ref float ___slowaccum)
    {
        if (___slowaccum > 2)
        {
            if (___inEnclosedRoom && !___inEnclosedRoom && ___inEnclosedRoom && ___api.ModLoader
                    .GetModSystem<CharacterSystem>()
                    .HasTrait((___eagent as EntityPlayer)?.Player, "lovesUnderground"))
            {
                ___eagent.Stats.Set("hungerrate", "minerstat", 0.0f);
            }
        }
    }

Did someone know how to do it in a better way ? Or give me an advice ?

 

Edited by Ritzga
Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.