Exemplo n.º 1
0
        public void PickBlocks(bool cooldown, bool left, bool middle, bool right)
        {
            DateTime now   = DateTime.UtcNow;
            double   delta = (now - lastClick).TotalMilliseconds;

            if (cooldown && delta < 250)
            {
                return;                                      // 4 times per second
            }
            lastClick = now;
            Inventory inv = game.Inventory;

            if (game.Server.UsingPlayerClick && !game.Gui.ActiveScreen.HandlesAllInput)
            {
                input.pickingId = -1;
                input.ButtonStateChanged(MouseButton.Left, left);
                input.ButtonStateChanged(MouseButton.Right, right);
                input.ButtonStateChanged(MouseButton.Middle, middle);
            }

            if (game.Gui.ActiveScreen.HandlesAllInput || !inv.CanPick)
            {
                return;
            }

            if (left)
            {
                if (game.Mode.PickingLeft())
                {
                    return;
                }
                Vector3I pos = game.SelectedPos.BlockPos;
                if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old = game.World.GetBlock(pos);
                if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old])
                {
                    return;
                }
                game.Mode.PickLeft(old);
            }
            else if (right)
            {
                if (game.Mode.PickingRight())
                {
                    return;
                }
                Vector3I pos = game.SelectedPos.TranslatedPos;
                if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old   = game.World.GetBlock(pos);
                BlockID block = inv.Selected;
                if (game.AutoRotate)
                {
                    block = AutoRotate.RotateBlock(game, block);
                }

                if (game.CanPick(old) || !BlockInfo.CanPlace[block])
                {
                    return;
                }
                // air-ish blocks can only replace over other air-ish blocks
                if (BlockInfo.Draw[block] == DrawType.Gas && BlockInfo.Draw[old] != DrawType.Gas)
                {
                    return;
                }

                if (!PickingHandler.CheckIsFree(game, block))
                {
                    return;
                }
                game.Mode.PickRight(old, block);
            }
            else if (middle)
            {
                Vector3I pos = game.SelectedPos.BlockPos;
                if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old = game.World.GetBlock(pos);
                game.Mode.PickMiddle(old);
            }
        }
Exemplo n.º 2
0
        public void PickBlocks(bool cooldown, bool left, bool middle, bool right)
        {
            DateTime now   = DateTime.UtcNow;
            double   delta = (now - lastClick).TotalMilliseconds;

            if (cooldown && delta < 250)
            {
                return;                                      // 4 times per second
            }
            lastClick = now;
            Inventory inv = game.Inventory;

            if (game.Server.UsingPlayerClick && !game.Gui.ActiveScreen.HandlesAllInput)
            {
                input.pickingId = -1;
                input.ButtonStateChanged(MouseButton.Left, left);
                input.ButtonStateChanged(MouseButton.Right, right);
                input.ButtonStateChanged(MouseButton.Middle, middle);
            }

            if (game.Gui.ActiveScreen.HandlesAllInput || !inv.CanPick)
            {
                return;
            }

            if (left)
            {
                // always play delete animations, even if we aren't picking a block.
                game.HeldBlockRenderer.ClickAnim(true);

                Vector3I pos = game.SelectedPos.BlockPos;
                if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old = game.World.GetBlock(pos);
                if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old])
                {
                    return;
                }

                game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air);
                game.UserEvents.RaiseBlockChanged(pos, old, Block.Air);
            }
            else if (right)
            {
                Vector3I pos = game.SelectedPos.TranslatedPos;
                if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old   = game.World.GetBlock(pos);
                BlockID block = inv.Selected;
                if (game.AutoRotate)
                {
                    block = AutoRotate.RotateBlock(game, block);
                }

                if (game.CanPick(old) || !BlockInfo.CanPlace[block])
                {
                    return;
                }
                // air-ish blocks can only replace over other air-ish blocks
                if (BlockInfo.Draw[block] == DrawType.Gas && BlockInfo.Draw[old] != DrawType.Gas)
                {
                    return;
                }

                if (!PickingHandler.CheckIsFree(game, block))
                {
                    return;
                }
                game.UpdateBlock(pos.X, pos.Y, pos.Z, block);
                game.UserEvents.RaiseBlockChanged(pos, old, block);
            }
            else if (middle)
            {
                Vector3I pos = game.SelectedPos.BlockPos;
                if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos))
                {
                    return;
                }
                BlockID cur = game.World.GetBlock(pos);

                if (BlockInfo.Draw[cur] == DrawType.Gas)
                {
                    return;
                }
                if (!(BlockInfo.CanPlace[cur] || BlockInfo.CanDelete[cur]))
                {
                    return;
                }
                if (!inv.CanChangeSelected() || inv.Selected == cur)
                {
                    return;
                }

                // Is the currently selected block an empty slot
                if (inv[inv.SelectedIndex] == Block.Air)
                {
                    inv.Selected = cur; return;
                }
                // Try to replace same block
                for (int i = 0; i < Inventory.BlocksPerRow; i++)
                {
                    if (inv[i] != cur)
                    {
                        continue;
                    }
                    inv.SelectedIndex = i; return;
                }
                // Try to replace empty slots
                for (int i = 0; i < Inventory.BlocksPerRow; i++)
                {
                    if (inv[i] != Block.Air)
                    {
                        continue;
                    }
                    inv[i]            = cur;
                    inv.SelectedIndex = i; return;
                }
                // Finally, replace the currently selected block.
                inv.Selected = cur;
            }
        }
Exemplo n.º 3
0
        public void PickBlocks(bool cooldown, bool left, bool middle, bool right)
        {
            DateTime now   = DateTime.UtcNow;
            double   delta = (now - lastClick).TotalMilliseconds;

            if (cooldown && delta < 250)
            {
                return;                                      // 4 times per second
            }
            lastClick = now;
            Inventory inv = game.Inventory;

            if (game.Server.UsingPlayerClick && !game.Gui.ActiveScreen.HandlesAllInput)
            {
                input.pickingId = -1;
                input.ButtonStateChanged(MouseButton.Left, left);
                input.ButtonStateChanged(MouseButton.Right, right);
                input.ButtonStateChanged(MouseButton.Middle, middle);
            }

            int btns = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0);

            if (btns > 1 || game.Gui.ActiveScreen.HandlesAllInput || inv.Selected == Block.Invalid)
            {
                return;
            }

            // always play delete animations, even if we aren't picking a block.
            if (left)
            {
                game.HeldBlockRenderer.anim.SetClickAnim(true);
                byte id = game.Entities.GetClosetPlayer(game.LocalPlayer);
                if (id != EntityList.SelfID && game.Mode.PickEntity(id))
                {
                    return;
                }
            }
            if (!game.SelectedPos.Valid)
            {
                return;
            }

            if (middle)
            {
                Vector3I pos = game.SelectedPos.BlockPos;
                if (!game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old = game.World.GetBlock(pos);
                game.Mode.PickMiddle(old);
            }
            else if (left)
            {
                Vector3I pos = game.SelectedPos.BlockPos;
                if (!game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old = game.World.GetBlock(pos);
                if (game.BlockInfo.Draw[old] == DrawType.Gas || !inv.CanDelete[old])
                {
                    return;
                }
                game.Mode.PickLeft(old);
            }
            else if (right)
            {
                Vector3I pos = game.SelectedPos.TranslatedPos;
                if (!game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old   = game.World.GetBlock(pos);
                BlockID block = inv.Selected;
                block = AutoRotate.RotateBlock(game, block);

                if (game.CanPick(old))
                {
                    return;
                }
                if (!inv.CanPlace[block] && game.SelectedPos.Block != Block.Chest1 && game.SelectedPos.Block != Block.Chest2 && game.SelectedPos.Block != Block.Chest3 && game.SelectedPos.Block != Block.Chest4)
                {
                    return;
                }
                if (!PickingHandler.CheckIsFree(game, block))
                {
                    return;
                }
                game.Mode.PickRight(old, block);
            }
        }