Ejemplo n.º 1
0
        public override ItemStack TakeOut(int quantity)
        {
            ItemStack split = Itemstack.GetEmptyClone();

            split.StackSize = quantity;
            return(split);
        }
Ejemplo n.º 2
0
        public override void Initialize(EntityProperties properties, ICoreAPI api, long chunkindex3d)
        {
            base.Initialize(properties, api, chunkindex3d);

            if (Itemstack == null || !Itemstack.ResolveBlockOrItem(World))
            {
                Die();
                this.Itemstack = null;
                return;
            }

            // If attribute was modified and resent to client, make sure we still have the resolved thing in memory
            WatchedAttributes.RegisterModifiedListener("itemstack", () => {
                if (Itemstack != null && Itemstack.Collectible == null)
                {
                    Itemstack.ResolveBlockOrItem(World);
                }
                Slot.Itemstack = Itemstack;
            });


            itemSpawnedMilliseconds = World.ElapsedMilliseconds;
            Swimming = FeetInLiquid = World.BlockAccessor.GetBlock(Pos.AsBlockPos).IsLiquid();

            tmpPos.Set(Pos.XInt, Pos.YInt, Pos.ZInt);
            windLoss = World.BlockAccessor.GetDistanceToRainFall(tmpPos) / 4f;
        }
Ejemplo n.º 3
0
        protected override void FlipWith(ItemSlot withslot)
        {
            ItemStack returnedStack = Itemstack.Clone();

            if (withslot.Itemstack != null && withslot.Itemstack.Equals(Itemstack))
            {
                returnedStack.StackSize += withslot.Itemstack.StackSize;
            }

            withslot.Itemstack = returnedStack;
        }
Ejemplo n.º 4
0
        protected override void ActivateSlotMiddleClick(ItemSlot sinkSlot, ref ItemStackMoveOperation op)
        {
            if (Empty)
            {
                return;
            }

            sinkSlot.Itemstack           = Itemstack.Clone();
            sinkSlot.Itemstack.StackSize = Itemstack.Collectible.MaxStackSize;
            op.MovedQuantity             = Itemstack.Collectible.MaxStackSize;
            sinkSlot.OnItemSlotModified(sinkSlot.Itemstack);
        }
Ejemplo n.º 5
0
        public override int TryPutInto(ItemSlot sinkSlot, ref ItemStackMoveOperation op)
        {
            if (!sinkSlot.CanTakeFrom(this) || !CanTake() || Itemstack == null)
            {
                return(0);
            }

            // Fill up sink slot
            if (op.ShiftDown)
            {
                if (Empty)
                {
                    return(0);
                }

                int maxstacksize = Itemstack.Collectible.MaxStackSize;

                if (sinkSlot.Itemstack == null)
                {
                    op.RequestedQuantity = maxstacksize;
                }
                else
                {
                    op.RequestedQuantity = maxstacksize - sinkSlot.StackSize;
                }
            }

            // Fill the destination slot with as many items as we can
            if (sinkSlot.Itemstack == null)
            {
                sinkSlot.Itemstack = TakeOut(op.RequestedQuantity);
                sinkSlot.OnItemSlotModified(sinkSlot.Itemstack);
                op.MovedQuantity = sinkSlot.StackSize;
                return(op.MovedQuantity);
            }

            ItemStack ownStack = Itemstack.Clone();

            ItemStackMergeOperation mergeop = op.ToMergeOperation(sinkSlot, this);

            op = mergeop;

            sinkSlot.Itemstack.Collectible.TryMergeStacks(mergeop);

            // Ignore any changes made to our slot
            Itemstack = ownStack;

            sinkSlot.OnItemSlotModified(sinkSlot.Itemstack);

            return(op.MovedQuantity);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Activates the middle click functions of the given slot.
        /// </summary>
        /// <param name="sinkSlot"></param>
        /// <param name="op"></param>
        protected virtual void ActivateSlotMiddleClick(ItemSlot sinkSlot, ref ItemStackMoveOperation op)
        {
            if (Empty)
            {
                return;
            }

            if (op.ActingPlayer?.WorldData?.CurrentGameMode == EnumGameMode.Creative)
            {
                sinkSlot.Itemstack = Itemstack.Clone();
                op.MovedQuantity   = Itemstack.StackSize;
                sinkSlot.OnItemSlotModified(sinkSlot.Itemstack);
            }
        }
Ejemplo n.º 7
0
        public override bool TryFlipWith(ItemSlot itemSlot)
        {
            bool canHoldHis   = itemSlot.Empty || CanHold(itemSlot);
            bool canIExchange = canHoldHis && (Empty || CanTake());

            bool canHoldMine   = Empty || itemSlot.CanHold(this);
            bool canHeExchange = canHoldMine && (itemSlot.Empty || itemSlot.CanTake());

            if (canIExchange && canHeExchange)
            {
                itemSlot.Itemstack = Itemstack.Clone();
                itemSlot.OnItemSlotModified(itemSlot.Itemstack);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        protected override void ActivateSlotLeftClick(ItemSlot sinkSlot, ref ItemStackMoveOperation op)
        {
            // 1. Current slot empty: Remove items
            if (Empty)
            {
                sinkSlot.TakeOutWhole();
                return;
            }

            // 2. Current slot non empty, source slot empty: Put items
            if (sinkSlot.Empty)
            {
                op.RequestedQuantity = StackSize;
                TryPutInto(sinkSlot, ref op);
                return;
            }

            // 3. Both slots not empty, and they are stackable: Fill source slot
            int maxq = Itemstack.Collectible.GetMergableQuantity(sinkSlot.Itemstack, Itemstack, op.CurrentPriority);

            if (maxq > 0)
            {
                op.RequestedQuantity = 1;
                ItemStackMergeOperation mergeop = op.ToMergeOperation(sinkSlot, this);
                op = mergeop;

                ItemStack ownStack = Itemstack.Clone();

                sinkSlot.Itemstack.Collectible.TryMergeStacks(mergeop);

                // Ignore any changes made to our slot
                Itemstack = ownStack;

                return;
            }

            // 4. Both slots not empty and not stackable: Remove items
            sinkSlot.TakeOutWhole();
        }
Ejemplo n.º 9
0
        protected override void ActivateSlotLeftClick(ItemSlot sinkSlot, ref ItemStackMoveOperation op)
        {
            // 1. Current slot empty: Remove items
            if (Empty)
            {
                sinkSlot.TakeOutWhole();
                return;
            }

            // 2. Current slot non empty, source slot empty: Put items
            if (sinkSlot.Empty)
            {
                op.RequestedQuantity = StackSize;
                TryPutInto(sinkSlot, ref op);
                return;
            }

            // 3. Both slots not empty, and they are the same: Fill source slot
            if (sinkSlot.Itemstack.Equals(op.World, Itemstack, GlobalConstants.IgnoredStackAttributes))
            {
                op.RequestedQuantity = 1;
                ItemStackMergeOperation mergeop = op.ToMergeOperation(sinkSlot, this);
                op = mergeop;

                ItemStack ownStack = Itemstack.Clone();

                sinkSlot.Itemstack.Collectible.TryMergeStacks(mergeop);

                // Ignore any changes made to our slot
                Itemstack = ownStack;

                return;
            }

            // 4. Both slots not empty and not stackable: Remove items
            sinkSlot.TakeOutWhole();
        }
Ejemplo n.º 10
0
        public override ItemStack TakeOutWhole()
        {
            ItemStack stack = Itemstack.Clone();

            return(stack);
        }
Ejemplo n.º 11
0
        public override int TryPutInto(ItemSlot sinkSlot, ref ItemStackMoveOperation op)
        {
            if (!sinkSlot.CanTakeFrom(this) || !CanTake() || Itemstack == null)
            {
                return(0);
            }

            if (sinkSlot.Inventory?.CanContain(sinkSlot, this) == false)
            {
                return(0);
            }

            // Fill up sink slot
            if (op.ShiftDown)
            {
                if (Empty)
                {
                    return(0);
                }

                int maxstacksize = Itemstack.Collectible.MaxStackSize;

                if (sinkSlot.Itemstack == null)
                {
                    op.RequestedQuantity = maxstacksize;
                }
                else
                {
                    op.RequestedQuantity = maxstacksize - sinkSlot.StackSize;
                }
            }

            // Fill the destination slot with as many items as we can
            if (sinkSlot.Itemstack == null)
            {
                int q = Math.Min(sinkSlot.GetRemainingSlotSpace(itemstack), op.RequestedQuantity);

                sinkSlot.Itemstack = TakeOut(q);
                sinkSlot.OnItemSlotModified(sinkSlot.Itemstack);
                op.MovedQuantity = sinkSlot.StackSize;
                return(op.MovedQuantity);
            }

            ItemStack ownStack = Itemstack.Clone();

            ItemStackMergeOperation mergeop = op.ToMergeOperation(sinkSlot, this);

            op = mergeop;
            int origRequestedQuantity = op.RequestedQuantity;

            op.RequestedQuantity = Math.Min(sinkSlot.GetRemainingSlotSpace(itemstack), op.RequestedQuantity);

            sinkSlot.Itemstack.Collectible.TryMergeStacks(mergeop);

            // Ignore any changes made to our slot
            Itemstack = ownStack;

            if (mergeop.MovedQuantity > 0)
            {
                sinkSlot.OnItemSlotModified(sinkSlot.Itemstack);
            }

            op.RequestedQuantity = origRequestedQuantity; //ensures op.NotMovedQuantity will be correct in calling code if used with slots with limited slot maxStackSize, e.g. InventorySmelting with a cooking container has slots with maxStackSize == 6
            return(op.MovedQuantity);
        }