Ritzga Posted January 5 Report Share Posted January 5 (edited) 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 ? Edited January 5 by Ritzga Link to comment Share on other sites More sharing options...
DArkHekRoMaNT Posted January 7 Report Share Posted January 7 (edited) Room way is right. Didn't you add references? I don't remember exactly where the rooms are, maybe in VSEssentials Edited January 7 by DArkHekRoMaNT 1 Link to comment Share on other sites More sharing options...
Ritzga Posted January 7 Author Report Share Posted January 7 7 hours ago, DArkHekRoMaNT said: Room way is right. Didn't you add references? I don't remember exactly where the rooms are, maybe in VSEssentials *sigh* That was the problem, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts