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:
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 ?