public override TransitionState[] UpdateAndGetTransitionStates(IWorldAccessor world, ItemSlot inslot) { TransitionState[] states = base.UpdateAndGetTransitionStates(world, inslot); ItemStack[] stacks = GetNonEmptyContents(world, inslot.Itemstack); if (MealMeshCache.ContentsRotten(stacks)) { inslot.Itemstack.Attributes?.RemoveAttribute("recipeCode"); inslot.Itemstack.Attributes?.RemoveAttribute("quantityServings"); } if (stacks == null || stacks.Length == 0) { inslot.Itemstack.Attributes?.RemoveAttribute("recipeCode"); inslot.Itemstack.Attributes?.RemoveAttribute("quantityServings"); } string eaten = Attributes["eatenBlock"].AsString(); if ((stacks == null || stacks.Length == 0) && eaten != null) { Block block = world.GetBlock(new AssetLocation(eaten)); if (block != null) { inslot.Itemstack = new ItemStack(block); inslot.MarkDirty(); } } return(states); }
public override void OnGroundIdle(EntityItem entityItem) { base.OnGroundIdle(entityItem); IWorldAccessor world = entityItem.World; if (world.Side != EnumAppSide.Server) { return; } if (entityItem.Swimming && world.Rand.NextDouble() < 0.01) { ItemStack[] stacks = GetContents(world, entityItem.Itemstack); if (MealMeshCache.ContentsRotten(stacks)) { for (int i = 0; i < stacks.Length; i++) { if (stacks[i] != null && stacks[i].StackSize > 0 && stacks[i].Collectible.Code.Path == "rot") { world.SpawnItemEntity(stacks[i], entityItem.ServerPos.XYZ); } } entityItem.Itemstack.Attributes.RemoveAttribute("recipeCode"); entityItem.Itemstack.Attributes.RemoveAttribute("quantityServings"); entityItem.Itemstack.Attributes.RemoveAttribute("contents"); } } }
public override void OnGroundIdle(EntityItem entityItem) { base.OnGroundIdle(entityItem); IWorldAccessor world = entityItem.World; if (world.Side != EnumAppSide.Server) { return; } if (entityItem.Swimming && world.Rand.NextDouble() < 0.01) { ItemStack[] stacks = GetContents(world, entityItem.Itemstack); if (MealMeshCache.ContentsRotten(stacks)) { for (int i = 0; i < stacks.Length; i++) { if (stacks[i] != null && stacks[i].StackSize > 0 && stacks[i].Collectible.Code.Path == "rot") { world.SpawnItemEntity(stacks[i], entityItem.ServerPos.XYZ); } } Block block = world.GetBlock(new AssetLocation(Attributes["eatenBlock"].AsString())); entityItem.Itemstack = new ItemStack(block); entityItem.WatchedAttributes.MarkPathDirty("itemstack"); } } }
public override void OnGroundIdle(EntityItem entityItem) { base.OnGroundIdle(entityItem); IWorldAccessor world = entityItem.World; if (world.Side != EnumAppSide.Server) { return; } if (entityItem.Swimming && world.Rand.NextDouble() < 0.03) { TryFillFromBlock(entityItem, entityItem.SidedPos.AsBlockPos); } if (entityItem.Swimming && world.Rand.NextDouble() < 0.01) { ItemStack[] stacks = GetContents(world, entityItem.Itemstack); if (MealMeshCache.ContentsRotten(stacks)) { for (int i = 0; i < stacks.Length; i++) { if (stacks[i] != null && stacks[i].StackSize > 0 && stacks[i].Collectible.Code.Path == "rot") { world.SpawnItemEntity(stacks[i], entityItem.ServerPos.XYZ); } } SetContent(entityItem.Itemstack, null); } } }
public override string GetHeldItemName(ItemStack itemStack) { ItemStack[] contentStacks = GetContents(api.World, itemStack); if (MealMeshCache.ContentsRotten(contentStacks)) { return(Lang.Get("Bowl of rotten food")); } return(base.GetHeldItemName(itemStack)); }
public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo) { float temp = GetTemperature(world, inSlot.Itemstack); if (temp > 20) { dsc.AppendLine(Lang.Get("Temperature: {0}°C", (int)temp)); } CookingRecipe recipe = GetCookingRecipe(world, inSlot.Itemstack); ItemStack[] stacks = GetNonEmptyContents(world, inSlot.Itemstack); ItemSlot slot = BlockCrock.GetDummySlotForFirstPerishableStack(world, stacks, null, inSlot.Inventory); slot.Itemstack?.Collectible.AppendPerishableInfoText(slot, dsc, world); float servings = GetQuantityServings(world, inSlot.Itemstack); if (recipe != null) { if (Math.Round(servings, 1) < 0.05) { dsc.AppendLine(Lang.Get("{1}% serving of {0}", recipe.GetOutputName(world, stacks).UcFirst(), Math.Round(servings * 100, 0))); } else { dsc.AppendLine(Lang.Get("{0} serving of {1}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks).UcFirst())); } } else { if (inSlot.Itemstack.Attributes.HasAttribute("quantityServings")) { dsc.AppendLine(Lang.Get("{0} servings left", Math.Round(servings, 1))); } else if (displayContentsInfo) { dsc.AppendLine(Lang.Get("Contents:")); if (stacks != null && stacks.Length > 0) { dsc.AppendLine(stacks[0].StackSize + "x " + stacks[0].GetName()); } } } if (!MealMeshCache.ContentsRotten(stacks)) { string facts = GetContentNutritionFacts(world, inSlot, null, recipe == null); if (facts != null) { dsc.Append(facts); } } }
public override void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc) { bool isRotten = MealMeshCache.ContentsRotten(inv); if (isRotten) { dsc.Append(Lang.Get("Rotten")); } else { dsc.Append(BlockEntityShelf.PerishableInfoCompact(Api, inv[0], 0, false)); } }
public override string GetHeldItemName(ItemStack itemStack) { ItemStack[] cStacks = GetContents(api.World, itemStack); if (cStacks.Length <= 1) { return(Lang.Get("pie-empty")); } ItemStack cstack = cStacks[1]; if (cstack == null) { return(Lang.Get("pie-empty")); } bool equal = true; for (int i = 2; equal && i < cStacks.Length - 1; i++) { if (cStacks[i] == null) { continue; } equal &= cstack.Equals(api.World, cStacks[i], GlobalConstants.IgnoredStackAttributes); cstack = cStacks[i]; } string state = Variant["state"]; if (MealMeshCache.ContentsRotten(cStacks)) { return(Lang.Get("pie-single-rotten")); } if (equal) { return(Lang.Get("pie-single-" + cstack.Collectible.Code.ToShortString() + "-" + state)); } else { EnumFoodCategory fillingFoodCat = cStacks[1].Collectible.NutritionProps?.FoodCategory ?? cStacks[1].ItemAttributes?["nutritionPropsWhenInMeal"]?.AsObject <FoodNutritionProperties>()?.FoodCategory ?? EnumFoodCategory.Vegetable ; return(Lang.Get("pie-mixed-" + fillingFoodCat.ToString().ToLowerInvariant() + "-" + state)); } }
public override TransitionState[] UpdateAndGetTransitionStates(IWorldAccessor world, ItemSlot inslot) { TransitionState[] states = base.UpdateAndGetTransitionStates(world, inslot); ItemStack[] stacks = GetNonEmptyContents(world, inslot.Itemstack); if (MealMeshCache.ContentsRotten(stacks)) { inslot.Itemstack.Attributes.RemoveAttribute("recipeCode"); inslot.Itemstack.Attributes?.RemoveAttribute("quantityServings"); } if (stacks == null || stacks.Length == 0) { inslot.Itemstack.Attributes.RemoveAttribute("recipeCode"); inslot.Itemstack.Attributes?.RemoveAttribute("quantityServings"); } return(states); }