public static FoodNutritionProperties[] GetContentNutritionProperties(IWorldAccessor world, ItemSlot inSlot, ItemStack[] contentStacks, EntityAgent forEntity, bool mulWithStacksize = false, float nutritionMul = 1, float healthMul = 1) { List <FoodNutritionProperties> foodProps = new List <FoodNutritionProperties>(); if (contentStacks == null) { return(foodProps.ToArray()); } for (int i = 0; i < contentStacks.Length; i++) { if (contentStacks[i] == null) { continue; } CollectibleObject obj = contentStacks[i].Collectible; FoodNutritionProperties stackProps; if (obj.CombustibleProps != null && obj.CombustibleProps.SmeltedStack != null) { stackProps = obj.CombustibleProps.SmeltedStack.ResolvedItemstack.Collectible.GetNutritionProperties(world, obj.CombustibleProps.SmeltedStack.ResolvedItemstack, forEntity); } else { stackProps = obj.GetNutritionProperties(world, contentStacks[i], forEntity); } if (obj.Attributes?["nutritionPropsWhenInMeal"].Exists == true) { stackProps = obj.Attributes?["nutritionPropsWhenInMeal"].AsObject <FoodNutritionProperties>(); } if (stackProps == null) { continue; } float mul = mulWithStacksize ? contentStacks[i].StackSize : 1; FoodNutritionProperties props = stackProps.Clone(); DummySlot slot = new DummySlot(contentStacks[i], inSlot.Inventory); TransitionState state = contentStacks[i].Collectible.UpdateAndGetTransitionState(world, slot, EnumTransitionType.Perish); float spoilState = state != null ? state.TransitionLevel : 0; float satLossMul = GlobalConstants.FoodSpoilageSatLossMul(spoilState, slot.Itemstack, forEntity); float healthLoss = GlobalConstants.FoodSpoilageHealthLossMul(spoilState, slot.Itemstack, forEntity); props.Satiety *= satLossMul * nutritionMul * mul; props.Health *= healthLoss * healthMul * mul; foodProps.Add(props); } return(foodProps.ToArray()); }
public string GetContentNutritionFacts(IWorldAccessor world, ItemSlot inSlotorFirstSlot, ItemStack[] contentStacks, EntityAgent forEntity, bool mulWithStacksize = false) { FoodNutritionProperties[] props = GetContentNutritionProperties(world, inSlotorFirstSlot, contentStacks, forEntity); Dictionary <EnumFoodCategory, float> totalSaturation = new Dictionary <EnumFoodCategory, float>(); float totalHealth = 0; for (int i = 0; i < props.Length; i++) { FoodNutritionProperties prop = props[i]; if (prop == null) { continue; } float sat = 0; totalSaturation.TryGetValue(prop.FoodCategory, out sat); DummySlot slot = new DummySlot(contentStacks[i], inSlotorFirstSlot.Inventory); TransitionState state = contentStacks[i].Collectible.UpdateAndGetTransitionState(api.World, slot, EnumTransitionType.Perish); float spoilState = state != null ? state.TransitionLevel : 0; float mul = mulWithStacksize ? contentStacks[i].StackSize : 1; float satLossMul = GlobalConstants.FoodSpoilageSatLossMul(spoilState, slot.Itemstack, forEntity); float healthLossMul = GlobalConstants.FoodSpoilageHealthLossMul(spoilState, slot.Itemstack, forEntity); totalHealth += prop.Health * healthLossMul * mul; totalSaturation[prop.FoodCategory] = (sat + prop.Satiety * satLossMul) * mul; } StringBuilder sb = new StringBuilder(); sb.AppendLine(Lang.Get("Nutrition Facts")); foreach (var val in totalSaturation) { sb.AppendLine("- " + Lang.Get("" + val.Key) + ": " + Math.Round(val.Value) + " sat."); } if (totalHealth != 0) { sb.AppendLine("- " + Lang.Get("Health: {0}{1} hp", totalHealth > 0 ? "+" : "", totalHealth)); } return(sb.ToString()); }
public override float[] GetNutritionHealthMul(BlockPos pos, ItemSlot slot, EntityAgent forEntity) { float satLossMul = 1f; if (slot == null && pos != null) { BlockEntityPie bep = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityPie; slot = bep.Inventory[0]; } if (slot != null) { TransitionState state = slot.Itemstack.Collectible.UpdateAndGetTransitionState(api.World, slot, EnumTransitionType.Perish); float spoilState = state != null ? state.TransitionLevel : 0; satLossMul = GlobalConstants.FoodSpoilageSatLossMul(spoilState, slot.Itemstack, forEntity); } return(new float[] { Attributes["nutritionMul"].AsFloat(1) * satLossMul, satLossMul }); }