Exemple #1
0
        /// <summary>
        /// Attempts to get a matching ingredient stack for the given input.
        /// </summary>
        /// <param name="inputStack"></param>
        /// <returns></returns>
        public CookingRecipeStack GetMatchingStack(ItemStack inputStack)
        {
            if (inputStack == null)
            {
                return(null);
            }

            for (int i = 0; i < ValidStacks.Length; i++)
            {
                bool isWildCard = ValidStacks[i].Code.Path.Contains("*");
                bool found      =
                    (isWildCard && inputStack.Collectible.WildCardMatch(ValidStacks[i].Code)) ||
                    (!isWildCard && inputStack.Equals(world, ValidStacks[i].ResolvedItemstack, GlobalConstants.IgnoredStackAttributes)) ||
                    (ValidStacks[i].CookedStack?.ResolvedItemstack != null && inputStack.Equals(world, ValidStacks[i].CookedStack.ResolvedItemstack, GlobalConstants.IgnoredStackAttributes))
                ;

                if (found)
                {
                    return(ValidStacks[i]);
                }
            }


            return(null);
        }
        protected override void ActivateSlotRightClick(ItemSlot sourceSlot, ref ItemStackMoveOperation op)
        {
            ItemSlotLiquidOnly liquidSlot = inventory[1] as ItemSlotLiquidOnly;
            IWorldAccessor     world      = inventory.Api.World;

            if (sourceSlot?.Itemstack?.Collectible is ILiquidSink sink && !liquidSlot.Empty && sink.AllowHeldLiquidTransfer)
            {
                ItemStack liqSlotStack         = liquidSlot.Itemstack;
                var       curTargetLiquidStack = sink.GetContent(sourceSlot.Itemstack);

                bool liquidstackable = curTargetLiquidStack == null || liqSlotStack.Equals(world, curTargetLiquidStack, GlobalConstants.IgnoredStackAttributes);

                if (liquidstackable)
                {
                    var lprops = BlockLiquidContainerBase.GetContainableProps(liqSlotStack);

                    float curSourceLitres = liqSlotStack.StackSize / lprops.ItemsPerLitre;
                    float curTargetLitres = sink.GetCurrentLitres(sourceSlot.Itemstack);

                    float toMoveLitres = op.CtrlDown ? sink.TransferSizeLitres : (sink.CapacityLitres - curTargetLitres);

                    toMoveLitres *= sourceSlot.StackSize;
                    toMoveLitres  = Math.Min(curSourceLitres, toMoveLitres);

                    if (toMoveLitres > 0)
                    {
                        op.MovedQuantity = sink.TryPutLiquid(sourceSlot.Itemstack, liqSlotStack, toMoveLitres / sourceSlot.StackSize);

                        liquidSlot.Itemstack.StackSize -= op.MovedQuantity * sourceSlot.StackSize;
                        if (liquidSlot.Itemstack.StackSize <= 0)
                        {
                            liquidSlot.Itemstack = null;
                        }
                        liquidSlot.MarkDirty();
                        sourceSlot.MarkDirty();

                        var pos = op.ActingPlayer?.Entity?.Pos;
                        if (pos != null)
                        {
                            op.World.PlaySoundAt(lprops.PourSound, pos.X, pos.Y, pos.Z);
                        }
                    }
                }

                return;
            }

            base.ActivateSlotRightClick(sourceSlot, ref op);
        }
        /// <summary>
        /// Creates a collection of slots from a tree.
        /// </summary>
        /// <param name="tree">The tree to build slots from</param>
        /// <param name="slots">pre-existing slots. (default: null)</param>
        /// <param name="modifiedSlots">Pre-modified slots. (default: null)</param>
        /// <returns></returns>
        public virtual ItemSlot[] SlotsFromTreeAttributes(ITreeAttribute tree, ItemSlot[] slots = null, List <ItemSlot> modifiedSlots = null)
        {
            if (tree == null)
            {
                return(slots);
            }

            if (slots == null || slots.Length != tree.GetInt("qslots"))
            {
                slots = new ItemSlot[tree.GetInt("qslots")];
                for (int i = 0; i < slots.Length; i++)
                {
                    slots[i] = NewSlot(i);
                }
            }

            for (int slotId = 0; slotId < slots.Length; slotId++)
            {
                ItemStack newstack = tree.GetTreeAttribute("slots")?.GetItemstack("" + slotId);
                ItemStack oldstack = slots[slotId].Itemstack;

                if (Api?.World == null)
                {
                    slots[slotId].Itemstack = newstack;
                    continue;
                }

                newstack?.ResolveBlockOrItem(Api.World);

                bool a = (newstack != null && !newstack.Equals(Api.World, oldstack));
                bool b = (oldstack != null && !oldstack.Equals(Api.World, newstack));

                bool didModify = a || b;

                slots[slotId].Itemstack = newstack;

                if (didModify && modifiedSlots != null)
                {
                    modifiedSlots.Add(slots[slotId]);
                }
            }



            return(slots);
        }
Exemple #4
0
 public bool Matches(IWorldAccessor worldForResolve, ItemStack inputStack)
 {
     return(ResolvedItemstack.Equals(worldForResolve, inputStack, GlobalConstants.IgnoredStackAttributes));
 }