public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer) { BlockEntityPie bep = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityPie; if (bep?.Inventory == null || bep.Inventory.Count < 1 || bep.Inventory.Empty) { return(""); } BlockMeal mealblock = api.World.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal; ItemStack pieStack = bep.Inventory[0].Itemstack; ItemStack[] stacks = GetContents(api.World, pieStack); StringBuilder sb = new StringBuilder(); TransitionableProperties[] propsm = pieStack.Collectible.GetTransitionableProperties(api.World, pieStack, null); if (propsm != null && propsm.Length > 0) { pieStack.Collectible.AppendPerishableInfoText(bep.Inventory[0], sb, api.World); } float servingsLeft = GetQuantityServings(world, bep.Inventory[0].Itemstack); if (!bep.Inventory[0].Itemstack.Attributes.HasAttribute("quantityServings")) { servingsLeft = bep.SlicesLeft / 4f; } float[] nmul = GetNutritionHealthMul(pos, null, forPlayer.Entity); sb.AppendLine(mealblock.GetContentNutritionFacts(api.World, bep.Inventory[0], stacks, null, true, nmul[0] * servingsLeft, nmul[1] * servingsLeft)); return(sb.ToString()); }
public void TryPlacePie(EntityAgent byEntity, BlockSelection blockSel) { IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot; var pieprops = hotbarSlot.Itemstack.ItemAttributes["inPieProperties"]?.AsObject <InPieProperties>(); if (pieprops == null || pieprops.PartType != EnumPiePartType.Crust) { return; } BlockPos abovePos = blockSel.Position.UpCopy(); Block atBlock = api.World.BlockAccessor.GetBlock(abovePos); if (atBlock.Replaceable < 6000) { return; } api.World.BlockAccessor.SetBlock(Id, abovePos); BlockEntityPie bepie = api.World.BlockAccessor.GetBlockEntity(abovePos) as BlockEntityPie; bepie.OnPlaced(byPlayer); }
public override string GetPlacedBlockName(IWorldAccessor world, BlockPos pos) { BlockEntityPie bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityPie; if (bec?.Inventory[0]?.Itemstack != null) { return(GetHeldItemName(bec.Inventory[0].Itemstack)); } return(base.GetPlacedBlockName(world, pos)); }
public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos) { BlockEntityPie bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityPie; if (bec?.Inventory[0]?.Itemstack != null) { return(bec.Inventory[0].Itemstack.Clone()); } return(base.OnPickBlock(world, pos)); }
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 }); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { BlockEntityPie bep = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityPie; return(bep.OnInteract(byPlayer)); }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); InteractionHelpYOffset = 0.375f; interactions = ObjectCacheUtil.GetOrCreate(api, "pieInteractions-", () => { List <ItemStack> knifeStacks = new List <ItemStack>(); List <ItemStack> fillStacks = new List <ItemStack>(); List <ItemStack> doughStacks = new List <ItemStack>(); foreach (CollectibleObject obj in api.World.Collectibles) { if (obj.Tool == EnumTool.Knife || obj.Tool == EnumTool.Sword) { knifeStacks.Add(new ItemStack(obj)); } if (obj is ItemDough) { doughStacks.Add(new ItemStack(obj, 2)); } var pieProps = obj.Attributes?["inPieProperties"]?.AsObject <InPieProperties>(null, obj.Code.Domain); if (pieProps != null && !(obj is ItemDough)) { fillStacks.Add(new ItemStack(obj, 2)); } } return(new WorldInteraction[] { new WorldInteraction() { ActionLangCode = "blockhelp-pie-cut", MouseButton = EnumMouseButton.Right, Itemstacks = knifeStacks.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityPie bec = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityPie; if (bec?.Inventory[0]?.Itemstack != null && (bec.Inventory[0].Itemstack.Collectible as BlockPie).State != "raw" && bec.SlicesLeft > 1) { return wi.Itemstacks; } return null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-pie-addfilling", MouseButton = EnumMouseButton.Right, Itemstacks = fillStacks.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityPie bec = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityPie; if (bec?.Inventory[0]?.Itemstack != null && (bec.Inventory[0].Itemstack.Collectible as BlockPie).State == "raw" && !bec.HasAllFilling) { return wi.Itemstacks; } return null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-pie-addcrust", MouseButton = EnumMouseButton.Right, Itemstacks = doughStacks.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityPie bec = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityPie; if (bec?.Inventory[0]?.Itemstack != null && (bec.Inventory[0].Itemstack.Collectible as BlockPie).State == "raw" && bec.HasAllFilling && !bec.HasCrust) { return wi.Itemstacks; } return null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-pie-changecruststyle", MouseButton = EnumMouseButton.Right, Itemstacks = knifeStacks.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityPie bec = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityPie; if (bec?.Inventory[0]?.Itemstack != null && (bec.Inventory[0].Itemstack.Collectible as BlockPie).State == "raw" && bec.HasCrust) { return wi.Itemstacks; } return null; } } }); }); ms = api.ModLoader.GetModSystem <MealMeshCache>(); displayContentsInfo = false; /*foreach (var val in api.World.Collectibles) * { * if (val.Attributes?["inPieProperties"].Exists == true) * { * var pieprops = val.Attributes["inPieProperties"]?.AsObject<InPieProperties>(); * if (pieprops.PartType == EnumPiePartType.Filling) * { * Console.WriteLine(string.Format("\"pie-single-{0}\": \"{1} pie\",", val.Code.Path, new ItemStack(val).GetName())); * } * } * }*/ }