Beispiel #1
0
    public void OnOpenInventory()
    {
        bool newState = !MainControllerManager.InUI;

        this.inventoryGUI.SetActive(newState);
        MainControllerManager.InUI = newState;

        if (newState)
        {
            invUIPlayer.ReloadInventory();
        }

        this.invUIPlayer.ResetSelection();
        hotbar.SetActive(!newState);
        MouseLook.ToggleMouseCursor(newState);

        // If closing, refresh the hotbar
        if (newState == false)
        {
            playerEvents.DrawHotbar();
            playerEvents.DrawItemEntity(playerEvents.GetSlotStack());
        }
    }
Beispiel #2
0
    // Uses item in hand
    public void UseItem()
    {
        // If ain't aiming at anything
        if (!current.active)
        {
            return;
        }

        ItemStack its = playerEvents.GetSlotStack();

        // If is holding no items
        if (its == null)
        {
            return;
        }

        Item it = its.GetItem();

        // If is a placeable item
        if (it is IPlaceable)
        {
            IPlaceable itPlaceable = it as IPlaceable;
            // If block placement was successful in client
            if (this.PlaceBlock(itPlaceable.placeableBlockID))
            {
                PlayerRaycast.lastBlockPlaced = it.id;
                if (its.Decrement())
                {
                    playerEvents.hotbar.SetNull(PlayerEvents.hotbarSlot);
                    playerEvents.DestroyItemEntity();
                }
                playerEvents.DrawHotbarSlot(PlayerEvents.hotbarSlot);
                playerEvents.invUIPlayer.DrawSlot(1, PlayerEvents.hotbarSlot);
            }
        }
    }