Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-126861

Some buttons in GUIs can be activated with any mouse button

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.12.2, Minecraft 18w10b, Minecraft 18w10c, Minecraft 18w10d, Minecraft 18w22c, Minecraft 1.13, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 19w12b, Minecraft 19w13b, 1.15.2, 1.16 Release Candidate 1, 1.16, 1.17.1, 1.19.3, 24w46a
    • Confirmed
    • UI

      Basic Issue Description

      Some buttons in guis can be pressed with any mouse button, not just the left mouse button. Buttons should only be pressable with the left mouse button.

      Detailed Description

      Note: For the purposes of this ticket I will be using the community made mappings for the names of classes, fields, and methods.

      An IGuiListEntry is an element on the screen that is scrolled when a scrollbar is moved.

      Some (but not all) subclasses of IGuiListEntry do not implement the mousePressed method correctly. This allows them to be interacted with using any mouse button, including any extra mouse buttons a user's mouse may have, such as the scroll wheel button, MB4, MB5, etc.

      A few good examples of this are in the world selection gui and the video settings gui.

      Notice that if you click a world in the world selection screen or any button/horizontal scrollbar in the video settings screen with any button other than the left mouse button, it still presses the button.

      Some instances of IGuiListEntry are implemented correctly. Notice that clicking any mouse button other than the left mouse button in the Language Selection screen, Controls screen, or the resource pack selection screen does not cause the button(s) to be pressed.

      Code Analysis & Patches

      Notice that the code below (from GuiListWorldSelectionEntry) never checks which mouse button is pressed.

          /**
           * Called when the mouse is clicked within this entry. Returning true means that something within this entry was
           * clicked and the list should not be dragged.
           */
          public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY)
          {
              this.containingListSel.selectWorld(slotIndex);
      
              if (relativeX <= 32 && relativeX < 32)
              {
                  this.joinWorld();
                  return true;
              }
              else if (Minecraft.getSystemTime() - this.lastClickTime < 250L)
              {
                  this.joinWorld();
                  return true;
              }
              else
              {
                  this.lastClickTime = Minecraft.getSystemTime();
                  return false;
              }
          }
      

      A simple one patch would fix this issue in this case:

          public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY)
          {
              if(mouseEvent != 0){
                  return false;
              }
              this.containingListSel.selectWorld(slotIndex);
      
              if (relativeX <= 32 && relativeX < 32)
              {
                  this.joinWorld();
                  return true;
              }
              else if (Minecraft.getSystemTime() - this.lastClickTime < 250L)
              {
                  this.joinWorld();
                  return true;
              }
              else
              {
                  this.lastClickTime = Minecraft.getSystemTime();
                  return false;
              }
          }
      

            Unassigned Unassigned
            sof sofia
            Votes:
            4 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              CHK: