Esempio n. 1
0
        public override bool OnActivated(MouseOverObject moo, EntityPlayerSp clicked)
        {
            if (moo.sideHit != FaceSides.Up ||
                !(clicked.World.GetTileEntity(moo.blockPos) is TileEntityCraftingGrid tecg))
            {
                return(false);
            }

            //var wasEmpty = tecg.IsEmpty();

            tecg.OnRightClicked(clicked.World, moo.hitVec, clicked.GetEquippedItemStack(), clicked);

            //if (wasEmpty)
            //return true;

            return(false);
        }
Esempio n. 2
0
        private void GameLoop()
        {
            if (GuiScreen == null && !Focused)
            {
                OpenGuiScreen(new GuiScreenIngameMenu());
            }

            if (Player != null)
            {
                if (GameTicks % 5 == 0)
                {
                    SoundEngine.PlaySound($"block/grass/walk{MathUtil.NextInt(1, 6)}");
                }

                if (AllowIngameInput())
                {
                    if (World?.GetChunk(new BlockPos(Player.Pos).ChunkPos()) == null)
                    {
                        Player.Motion = Vector3.Zero;
                    }

                    bool lmb = _mouseButtonsDown.Contains(MouseButton.Left);
                    bool rmb = _mouseButtonsDown.Contains(MouseButton.Right);

                    if (lmb || rmb)
                    {
                        _interactionTickCounter++;

                        BlockPos lastPos = _lastMouseOverObject.blockPos;

                        if (lmb && _lastMouseOverObject.hit == HitType.Block)
                        {
                            if (Player.GameMode == GameMode.Creative)
                            {
                                Player.BreakBlock();
                            }
                            else
                            {
                                ParticleRenderer.SpawnDiggingParticle(_lastMouseOverObject);

                                if (_lastMouseOverObject.hit == MouseOverObject.hit &&
                                    lastPos == MouseOverObject.blockPos)
                                {
                                    if (!DestroyProgresses.TryGetValue(lastPos, out DestroyProgress progress))
                                    {
                                        if (World?.GetBlockState(lastPos).Block.Hardness != -1)
                                        {
                                            DestroyProgresses.TryAdd(lastPos,
                                                                     progress = new DestroyProgress(lastPos, Player));
                                            progress.Progress = 0;
                                        }
                                    }
                                    else
                                    {
                                        progress.Progress +=
                                            Player.GetEquippedItemStack() is ItemStack st && !st.IsEmpty
                                                ? st.Item.GetMiningSpeed(World?.GetBlockState(lastPos).Block.Material)
                                                : 1;
                                    }

                                    if (progress.Destroyed)
                                    {
                                        DestroyProgresses.TryRemove(progress.Pos, out DestroyProgress removed);
                                    }
                                }
                                else
                                {
                                    ResetDestroyProgress(Player);
                                }
                            }
                        }

                        _lastMouseOverObject = MouseOverObject;

                        if (_interactionTickCounter % 4 == 0)
                        {
                            GetMouseOverObject();

                            if (rmb)
                            {
                                Player.OnClick(MouseButton.Right);
                            }
                        }
                    }
                    else
                    {
                        _interactionTickCounter = 0;
                        ResetDestroyProgress(Player);
                    }
                }
                else
                {
                    ResetDestroyProgress(Player);
                }

                World?.Update(Player.Pos, WorldRenderer.RenderDistance);
            }

            WorldRenderer?.Update();
            SkyboxRenderer?.Update();
            ParticleRenderer?.TickParticles();

            GameTicks++;
        }