/// <summary>
        /// Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
        /// </summary>
        public virtual void SmeltItem()
        {
            if (!CanSmelt())
            {
                return;
            }

            ItemStack itemstack = FurnaceRecipes.Smelting().GetSmeltingResult(FurnaceItemStacks[0].GetItem().ShiftedIndex);

            if (FurnaceItemStacks[2] == null)
            {
                FurnaceItemStacks[2] = itemstack.Copy();
            }
            else if (FurnaceItemStacks[2].ItemID == itemstack.ItemID)
            {
                FurnaceItemStacks[2].StackSize++;
            }

            FurnaceItemStacks[0].StackSize--;

            if (FurnaceItemStacks[0].StackSize <= 0)
            {
                FurnaceItemStacks[0] = null;
            }
        }
        /// <summary>
        /// Called to transfer a stack from one inventory to the other eg. when shift clicking.
        /// </summary>
        public override ItemStack TransferStackInSlot(int par1)
        {
            ItemStack itemstack = null;
            Slot      slot      = (Slot)InventorySlots[par1];

            if (slot != null && slot.GetHasStack())
            {
                ItemStack itemstack1 = slot.GetStack();
                itemstack = itemstack1.Copy();

                if (par1 < NumRows * 9)
                {
                    if (!MergeItemStack(itemstack1, NumRows * 9, InventorySlots.Count, true))
                    {
                        return(null);
                    }
                }
                else if (!MergeItemStack(itemstack1, 0, NumRows * 9, false))
                {
                    return(null);
                }

                if (itemstack1.StackSize == 0)
                {
                    slot.PutStack(null);
                }
                else
                {
                    slot.OnSlotChanged();
                }
            }

            return(itemstack);
        }
Exemple #3
0
        /// <summary>
        /// Called to transfer a stack from one inventory to the other eg. when shift clicking.
        /// </summary>
        public override ItemStack TransferStackInSlot(int par1)
        {
            ItemStack itemstack = null;
            Slot      slot      = (Slot)InventorySlots[par1];

            if (slot != null && slot.GetHasStack())
            {
                ItemStack itemstack1 = slot.GetStack();
                itemstack = itemstack1.Copy();

                if (par1 == 0)
                {
                    if (!MergeItemStack(itemstack1, 9, 45, true))
                    {
                        return(null);
                    }

                    slot.Func_48433_a(itemstack1, itemstack);
                }
                else if (par1 >= 9 && par1 < 36)
                {
                    if (!MergeItemStack(itemstack1, 36, 45, false))
                    {
                        return(null);
                    }
                }
                else if (par1 >= 36 && par1 < 45)
                {
                    if (!MergeItemStack(itemstack1, 9, 36, false))
                    {
                        return(null);
                    }
                }
                else if (!MergeItemStack(itemstack1, 9, 45, false))
                {
                    return(null);
                }

                if (itemstack1.StackSize == 0)
                {
                    slot.PutStack(null);
                }
                else
                {
                    slot.OnSlotChanged();
                }

                if (itemstack1.StackSize != itemstack.StackSize)
                {
                    slot.OnPickupFromSlot(itemstack1);
                }
                else
                {
                    return(null);
                }
            }

            return(itemstack);
        }
        public void OnRightClicked(World world, Vector3 hitVec, ItemStack with, EntityPlayerSp clicked)
        {
            if (clicked.IsSneaking && _product != null)
            {
                ClearGrid();
                Save();

                var pos = new Vector3(_pos.X + 0.5f, hitVec.Y, _pos.Z + 0.5f);

                world.AddEntity(new EntityItem(world, pos, Vector3.UnitY * 0.25f, _product));
                _product = null;

                return;
            }

            if (IsEmpty() && clicked.IsSneaking)
            {
                return;
            }

            var gap  = 1 / 16f;
            var slot = 1 / 4f;

            var localPos = new Vector2(hitVec.X, hitVec.Z) - new Vector2(_pos.X, _pos.Z);

            localPos.X %= 1.0f;
            localPos.Y %= 1.0f;

            var indexX = (int)(localPos.X / (slot + 4 * gap / 3));
            var indexY = (int)(localPos.Y / (slot + 4 * gap / 3));

            if (_placeDelay[indexX, indexY] > 0)
            {
                return;
            }

            _placeDelay[indexX, indexY] = 6;

            var item = _grid[indexX, indexY];

            var stackEmpty = with == null || with.IsEmpty;

            if (item != null)
            {
                SetGridElement(indexX, indexY, null);
                world?.AddEntity(new EntityItem(world, hitVec + Vector3.UnitY * 0.25f, Vector3.UnitY * 0.1f, item, true));

                //TODO - maybe make the items swap?
            }
            else
            {
                if (!stackEmpty)
                {
                    SetGridElement(indexX, indexY, with.Copy(1));
                    with.Count--;
                }
            }
        }
        protected override void ButtonClicked(GuiButton btn, MouseButton button)
        {
            if (btn is GuiItemSlot slot)
            {
                if (SharpCraft.Instance.KeyboardState.IsKeyDown(Key.LShift))
                {
                    SharpCraft.Instance.Player.FastMoveStack(slot.ID);
                }
                else if ((_draggedStack == null || _draggedStack.IsEmpty) && slot.Stack != null && !slot.Stack.IsEmpty) //when not holding anything and clicked a non-empty stack in the inventory
                {
                    int toTake = slot.Stack.Count;

                    if (button == MouseButton.Right)
                    {
                        toTake /= 2;
                        toTake  = toTake == 0 ? 1 : toTake;
                    }

                    _draggedStack = slot.Stack.Copy(toTake);

                    slot.Stack.Count -= toTake;
                }
                else
                {
                    if (slot.Stack == null || slot.Stack.IsEmpty) // when holding a non-empty stack and clicking an empty slot
                    {
                        if (button == MouseButton.Right && _draggedStack != null)
                        {
                            SharpCraft.Instance.Player.SetItemStackInInventory(btn.ID, _draggedStack.Copy(1));

                            _draggedStack.Count--;
                        }
                        else
                        {
                            SharpCraft.Instance.Player.SetItemStackInInventory(btn.ID, _draggedStack);

                            _draggedStack = null;
                        }
                    }
                    else if (_draggedStack != null && slot.Stack.ItemSame(_draggedStack))
                    {
                        int ammountToMove = button == MouseButton.Right ? 1 : Math.Min(slot.Stack.Item.GetMaxStackSize() - slot.Stack.Count, _draggedStack.Count);

                        slot.Stack.Count    += ammountToMove;
                        _draggedStack.Count -= ammountToMove;
                    }
                    else if (_draggedStack != null && !_draggedStack.IsEmpty)
                    {
                        ItemStack stackInSlot = SharpCraft.Instance.Player.GetItemStackInInventory(btn.ID);
                        SharpCraft.Instance.Player.SetItemStackInInventory(btn.ID, _draggedStack.Copy());

                        _draggedStack = stackInSlot.Copy();
                    }
                }
            }
        }
        public void ThrowStack(ItemStack stack, int count)
        {
            if (stack == null || stack.IsEmpty)
            {
                return;
            }

            int ammountToThrow = Math.Min(count, stack.Count);

            ItemStack toThrow = stack.Copy(1);

            toThrow.Count = ammountToThrow;

            World?.AddEntity(new EntityItem(World, SharpCraft.Instance.Camera.pos - Vector3.UnitY * 0.35f,
                                            SharpCraft.Instance.Camera.GetLookVec() * 0.75f + Vector3.UnitY * 0.1f, toThrow));

            stack.Count -= ammountToThrow;
        }
Exemple #7
0
 public void CopyFrom(ItemStack from)
 {
     data = (ItemStack)from.Copy();
 }
        /// <summary>
        /// Called to transfer a stack from one inventory to the other eg. when shift clicking.
        /// </summary>
        public override ItemStack TransferStackInSlot(int par1)
        {
            ItemStack itemstack = null;
            Slot      slot      = (Slot)InventorySlots[par1];

            if (slot != null && slot.GetHasStack())
            {
                ItemStack itemstack1 = slot.GetStack();
                itemstack = itemstack1.Copy();

                if (par1 == 2)
                {
                    if (!MergeItemStack(itemstack1, 3, 39, true))
                    {
                        return(null);
                    }

                    slot.Func_48433_a(itemstack1, itemstack);
                }
                else if (par1 == 1 || par1 == 0)
                {
                    if (!MergeItemStack(itemstack1, 3, 39, false))
                    {
                        return(null);
                    }
                }
                else if (FurnaceRecipes.Smelting().GetSmeltingResult(itemstack1.GetItem().ShiftedIndex) != null)
                {
                    if (!MergeItemStack(itemstack1, 0, 1, false))
                    {
                        return(null);
                    }
                }
                else if (TileEntityFurnace.Func_52005_b(itemstack1))
                {
                    if (!MergeItemStack(itemstack1, 1, 2, false))
                    {
                        return(null);
                    }
                }
                else if (par1 >= 3 && par1 < 30)
                {
                    if (!MergeItemStack(itemstack1, 30, 39, false))
                    {
                        return(null);
                    }
                }
                else if (par1 >= 30 && par1 < 39 && !MergeItemStack(itemstack1, 3, 30, false))
                {
                    return(null);
                }

                if (itemstack1.StackSize == 0)
                {
                    slot.PutStack(null);
                }
                else
                {
                    slot.OnSlotChanged();
                }

                if (itemstack1.StackSize != itemstack.StackSize)
                {
                    slot.OnPickupFromSlot(itemstack1);
                }
                else
                {
                    return(null);
                }
            }

            return(itemstack);
        }
        public bool OnPickup(ItemStack dropped)
        {
            int inventorySize = Hotbar.Length + Inventory.Length;

            int lastKnownEmpty = -1;

            // Check Hotbar first
            for (int i = 0; i < Hotbar.Length; i++)
            {
                ItemStack stack = GetItemStackInInventory(i);
                if (stack == null || stack.IsEmpty || !stack.ItemSame(dropped))
                {
                    continue;
                }

                if (dropped.ItemSame(stack) && stack.Count <= stack.Item.GetMaxStackSize())
                {
                    int toPickUp = Math.Min(stack.Item.GetMaxStackSize() - stack.Count, dropped.Count);

                    stack.Count   += toPickUp;
                    dropped.Count -= toPickUp;
                }

                // return if fully combined
                if (dropped.IsEmpty)
                {
                    return(true);
                }
            }

            for (int i = inventorySize - 1; i >= 0; i--)
            {
                ItemStack stack = GetItemStackInInventory(i);

                if (stack == null || stack.IsEmpty)
                {
                    lastKnownEmpty = i;
                    continue;
                }

                // Continue as already looked at Hotbar
                if (i < Hotbar.Length)
                {
                    continue;
                }

                if (dropped.ItemSame(stack) && stack.Count <= stack.Item.GetMaxStackSize())
                {
                    int toPickUp = Math.Min(stack.Item.GetMaxStackSize() - stack.Count, dropped.Count);

                    stack.Count   += toPickUp;
                    dropped.Count -= toPickUp;
                }

                if (dropped.IsEmpty)
                {
                    break;
                }
            }

            if (lastKnownEmpty != -1)
            {
                SetItemStackInInventory(lastKnownEmpty, dropped.Copy());
                dropped.Count = 0;
            }

            return(dropped.IsEmpty);
        }