public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel != null) { BlockEntityBarrel beba = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBarrel; var liqslot = beba?.Inventory[1]; if (beba != null && !liqslot.Empty) { if (liqslot.Itemstack.Item?.Code?.Path == "cottagecheeseportion") { var props = BlockLiquidContainerBase.GetContainableProps(liqslot.Itemstack); float curLitres = liqslot.Itemstack.StackSize / props.ItemsPerLitre; if (curLitres < 25) { (api as ICoreClientAPI)?.TriggerIngameError(this, "notenough", Lang.Get("Need at least 25 litres to create a roll of cheese")); handHandling = EnumHandHandling.PreventDefault; return; } if (api.World.Side == EnumAppSide.Server) { ItemStack ccStack = beba.Inventory[1].TakeOut((int)(25 * props.ItemsPerLitre)); BlockCheeseCurdsBundle block = api.World.GetBlock(new AssetLocation("curdbundle")) as BlockCheeseCurdsBundle; ItemStack bundleStack = new ItemStack(block); block.SetContents(bundleStack, ccStack); slot.TakeOut(1); slot.MarkDirty(); beba.MarkDirty(true); if (!byEntity.TryGiveItemStack(bundleStack)) { api.World.SpawnItemEntity(bundleStack, byEntity.Pos.XYZ.AddCopy(0, 0.5, 0)); } } handHandling = EnumHandHandling.PreventDefault; return; } } } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel?.Position == null) { base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); return; } Block block = api.World.BlockAccessor.GetBlock(blockSel.Position); if (block?.Attributes?.IsTrue("mealContainer") == true) { ServeIntoBowl(block, blockSel.Position, slot, byEntity.World); handHandling = EnumHandHandling.PreventDefault; return; } if (block is BlockCookingContainer && slot.Itemstack.Attributes.HasAttribute("recipeCode")) { handHandling = EnumHandHandling.PreventDefault; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); string recipeCode = slot.Itemstack.Attributes.GetString("recipeCode"); float quantityServings = (float)slot.Itemstack.Attributes.GetDecimal("quantityServings"); float movedServings = (block as BlockCookingContainer).PutMeal(blockSel.Position, GetNonEmptyContents(api.World, slot.Itemstack), recipeCode, quantityServings); quantityServings -= movedServings; if (quantityServings > 0) { slot.Itemstack.Attributes.SetFloat("quantityServings", quantityServings); } else { slot.Itemstack.Attributes.RemoveAttribute("recipeCode"); slot.Itemstack.Attributes.RemoveAttribute("quantityServings"); slot.Itemstack.Attributes.RemoveAttribute("contents"); } return; } if (block is BlockBarrel) { BlockEntityBarrel bebarrel = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBarrel; if (bebarrel != null) { ItemStack stack = bebarrel.inventory[0].Itemstack; ItemStack[] ownContentStacks = GetNonEmptyContents(api.World, slot.Itemstack); if (ownContentStacks == null || ownContentStacks.Length == 0) { if (stack != null && stack.Collectible.Attributes?.IsTrue("crockable") == true) { SetContents(null, slot.Itemstack, new ItemStack[] { bebarrel.inventory[0].TakeOut(4) }, 1); bebarrel.MarkDirty(true); slot.MarkDirty(); } } // non-meal items (eg. pickled vegetables) can be placed from a crock INTO a barrel - this is useful eg. for cheese-making else if (ownContentStacks.Length == 1 && slot.Itemstack.Attributes.GetString("recipeCode") == null) { new DummySlot(ownContentStacks[0]).TryPutInto(api.World, bebarrel.inventory[0], ownContentStacks[0].StackSize); if (ownContentStacks[0].StackSize <= 0) { SetContents(slot.Itemstack, new ItemStack[0]); } bebarrel.MarkDirty(true); slot.MarkDirty(); } } handHandling = EnumHandHandling.PreventDefault; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); return; } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel?.Position == null) { base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); return; } Block block = api.World.BlockAccessor.GetBlock(blockSel.Position); float quantityServings = (float)slot.Itemstack.Attributes.GetDecimal("quantityServings"); if (block?.Attributes?.IsTrue("mealContainer") == true) { if (!byEntity.Controls.Sneak) { return; } if (quantityServings > 0) { ServeIntoBowl(block, blockSel.Position, slot, byEntity.World); } handHandling = EnumHandHandling.PreventDefault; return; } if (block is BlockGroundStorage) { if (!byEntity.Controls.Sneak) { return; } var begs = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityGroundStorage; ItemSlot gsslot = begs.GetSlotAt(blockSel); if (gsslot == null || gsslot.Empty) { return; } if (gsslot.Itemstack.ItemAttributes?.IsTrue("mealContainer") == true) { if (quantityServings > 0) { ServeIntoStack(gsslot, slot, byEntity.World); gsslot.MarkDirty(); begs.updateMeshes(); begs.MarkDirty(true); } handHandling = EnumHandHandling.PreventDefault; return; } } if (block is BlockCookingContainer && slot.Itemstack.Attributes.HasAttribute("recipeCode")) { handHandling = EnumHandHandling.PreventDefault; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); string recipeCode = slot.Itemstack.Attributes.GetString("recipeCode"); float movedServings = (block as BlockCookingContainer).PutMeal(blockSel.Position, GetNonEmptyContents(api.World, slot.Itemstack), recipeCode, quantityServings); quantityServings -= movedServings; if (quantityServings > 0) { slot.Itemstack.Attributes.SetFloat("quantityServings", quantityServings); } else { slot.Itemstack.Attributes.RemoveAttribute("recipeCode"); slot.Itemstack.Attributes.RemoveAttribute("quantityServings"); slot.Itemstack.Attributes.RemoveAttribute("contents"); } return; } if (block is BlockBarrel) { BlockEntityBarrel bebarrel = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBarrel; if (bebarrel != null) { ItemStack stack = bebarrel.Inventory[0].Itemstack; ItemStack[] ownContentStacks = GetNonEmptyContents(api.World, slot.Itemstack); if (ownContentStacks == null || ownContentStacks.Length == 0) { if (stack != null && stack.Collectible.Attributes?.IsTrue("crockable") == true) { float servingCapacity = slot.Itemstack.Block.Attributes["servingCapacity"].AsFloat(1); var foodstack = bebarrel.Inventory[0].TakeOut((int)servingCapacity * 4); float servingSize = foodstack.StackSize / 4f; foodstack.StackSize = Math.Max(0, foodstack.StackSize / 4); SetContents(null, slot.Itemstack, new ItemStack[] { foodstack }, servingSize); bebarrel.MarkDirty(true); slot.MarkDirty(); } } // non-meal items (eg. pickled vegetables) can be placed from a crock INTO a barrel - this is useful eg. for cheese-making else if (ownContentStacks.Length == 1 && slot.Itemstack.Attributes.GetString("recipeCode") == null) { var foodstack = ownContentStacks[0].Clone(); foodstack.StackSize = (int)(foodstack.StackSize * quantityServings); new DummySlot(foodstack).TryPutInto(api.World, bebarrel.Inventory[0], foodstack.StackSize); foodstack.StackSize = (int)(foodstack.StackSize / quantityServings); if (foodstack.StackSize <= 0) { SetContents(slot.Itemstack, new ItemStack[0]); } else { SetContents(slot.Itemstack, new ItemStack[] { foodstack }); } bebarrel.MarkDirty(true); slot.MarkDirty(); } } handHandling = EnumHandHandling.PreventDefault; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); return; } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { if (blockSel.Position == null) { base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); return; } Block block = api.World.BlockAccessor.GetBlock(blockSel.Position); if (block?.Attributes?["mealcontainer"]?.AsBool() == true) { ServeIntoBowl(block, blockSel.Position, slot, byEntity.World); handHandling = EnumHandHandling.PreventDefault; return; } if (block is BlockCookingContainer && slot.Itemstack.Attributes.HasAttribute("recipeCode")) { handHandling = EnumHandHandling.PreventDefault; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); string recipeCode = slot.Itemstack.Attributes.GetString("recipeCode"); int quantityServings = slot.Itemstack.Attributes.GetInt("quantityServings"); int movedServings = (block as BlockCookingContainer).PutMeal(blockSel.Position, GetContents(api.World, slot.Itemstack), recipeCode, quantityServings); quantityServings -= movedServings; if (quantityServings > 0) { slot.Itemstack.Attributes.SetInt("quantityServings", quantityServings); } else { slot.Itemstack.Attributes.RemoveAttribute("recipeCode"); slot.Itemstack.Attributes.RemoveAttribute("quantityServings"); slot.Itemstack.Attributes.RemoveAttribute("contents"); } return; } if (block is BlockBarrel) { BlockEntityBarrel bebarrel = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBarrel; ItemStack stack = bebarrel.inventory[0].Itemstack; ItemStack[] ownContentStacks = GetNonEmptyContents(api.World, slot.Itemstack); if (ownContentStacks == null || ownContentStacks.Length == 0) { if (stack != null && stack.Collectible.Attributes["crockable"].AsBool() == true) { SetContents(slot.Itemstack, new ItemStack[] { bebarrel.inventory[0].TakeOut(4) }); bebarrel.MarkDirty(true); } } else { if (stack != null) { new DummySlot(ownContentStacks[0]).TryPutInto(api.World, bebarrel.inventory[0], ownContentStacks[0].StackSize); if (ownContentStacks[0].StackSize <= 0) { SetContents(slot.Itemstack, new ItemStack[0]); } bebarrel.MarkDirty(true); slot.MarkDirty(); } } handHandling = EnumHandHandling.PreventDefault; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); return; } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling); }