Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

LiquidBounce Forum

  1. Home
  2. ScriptAPI
  3. How to switch hotbar slots via script?

How to switch hotbar slots via script?

Scheduled Pinned Locked Moved Solved ScriptAPI
11 Posts 4 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ByGrafB ByGraf

    Is there a list of things like mc.gameSettings.keyBindUseItem.pressed where i can
    look up some things because i cant find anything on google and i dont always want to ask in the Forum.

    And i really want to become better at scripting but as already mentioned i cant find
    these things i want to look up . Any tips ?

    Ali00035A Offline
    Ali00035A Offline
    Ali00035
    wrote on last edited by Ali00035
    #2

    @bygraf said in How to switch hotbar slots via script?:

    Is there a list of things like mc.gameSettings.keyBindUseItem.pressed

    https://scriptapi.liquidbounce.net/net/minecraft/client/settings/GameSettings.html

    How to switch hotbar slots via scriptapi?

    mc.thePlayer.sendQueue.addToSendQueue(new C09PacketHeldItemChange(slot));

    ByGrafB 1 Reply Last reply
    0
    • Ali00035A Ali00035

      @bygraf said in How to switch hotbar slots via script?:

      Is there a list of things like mc.gameSettings.keyBindUseItem.pressed

      https://scriptapi.liquidbounce.net/net/minecraft/client/settings/GameSettings.html

      How to switch hotbar slots via scriptapi?

      mc.thePlayer.sendQueue.addToSendQueue(new C09PacketHeldItemChange(slot));

      ByGrafB Offline
      ByGrafB Offline
      ByGraf
      wrote on last edited by
      #3

      @ali00035 thank u

      Ali00035A 1 Reply Last reply
      0
      • ByGrafB ByGraf

        @ali00035 thank u

        Ali00035A Offline
        Ali00035A Offline
        Ali00035
        wrote on last edited by
        #4

        @bygraf no problem 😄

        ByGrafB 1 Reply Last reply
        0
        • ByGrafB ByGraf has marked this topic as solved on
        • ByGrafB ByGraf has marked this topic as unsolved on
        • Ali00035A Ali00035

          @bygraf no problem 😄

          ByGrafB Offline
          ByGrafB Offline
          ByGraf
          wrote on last edited by
          #5

          @ali00035 I tested it and it didnt switch the slot

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #6

            This:

            mc.thePlayer.inventory.currentItem = slot - 36
            

            switches slots client-side.

            This:

            mc.thePlayer.sendQueue.addToSendQueue(new C09PacketHeldItemChange(slot - 36))
            

            switches slots server-side.

            ByGrafB Ali00035A 2 Replies Last reply
            1
            • ? A Former User

              This:

              mc.thePlayer.inventory.currentItem = slot - 36
              

              switches slots client-side.

              This:

              mc.thePlayer.sendQueue.addToSendQueue(new C09PacketHeldItemChange(slot - 36))
              

              switches slots server-side.

              ByGrafB Offline
              ByGrafB Offline
              ByGraf
              wrote on last edited by
              #7

              @mems ty so much ur really helping me

              1 Reply Last reply
              0
              • ? A Former User

                This:

                mc.thePlayer.inventory.currentItem = slot - 36
                

                switches slots client-side.

                This:

                mc.thePlayer.sendQueue.addToSendQueue(new C09PacketHeldItemChange(slot - 36))
                

                switches slots server-side.

                Ali00035A Offline
                Ali00035A Offline
                Ali00035
                wrote on last edited by
                #8

                @mems Thanks, I didn't know that

                1 Reply Last reply
                0
                • ByGrafB ByGraf

                  Is there a list of things like mc.gameSettings.keyBindUseItem.pressed where i can
                  look up some things because i cant find anything on google and i dont always want to ask in the Forum.

                  And i really want to become better at scripting but as already mentioned i cant find
                  these things i want to look up . Any tips ?

                  CzechHekC Offline
                  CzechHekC Offline
                  CzechHek
                  wrote on last edited by CzechHek
                  #9

                  And this is how you should actually switch the slots on both sides.

                  mc.thePlayer.inventory.currentItem  = x;
                  mc.playerController.updateController();
                  

                  because updateController does this:

                      public void updateController()
                      {
                          this.syncCurrentPlayItem();
                  
                          if (this.netClientHandler.getNetworkManager().isChannelOpen())
                          {
                              this.netClientHandler.getNetworkManager().processReceivedPackets();
                          }
                          else
                          {
                              this.netClientHandler.getNetworkManager().checkDisconnected();
                          }
                      }
                  
                      private void syncCurrentPlayItem()
                      {
                          int i = this.mc.thePlayer.inventory.currentItem;
                  
                          if (i != this.currentPlayerItem)
                          {
                              this.currentPlayerItem = i;
                              this.netClientHandler.addToSendQueue(new C09PacketHeldItemChange(this.currentPlayerItem));
                          }
                      }
                  
                  1 Reply Last reply
                  2
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #10

                    Yeah, it has to be updated server-side too, because this: mc.thePlayer.inventory.currentItem only does it client-side.

                    1 Reply Last reply
                    0
                    • ByGrafB ByGraf has marked this topic as solved on
                    • ByGrafB Offline
                      ByGrafB Offline
                      ByGraf
                      wrote on last edited by
                      #11

                      @czechhek said in How to switch hotbar slots via script?:

                      mc.playerController.updateController();

                      Thank u guys so much

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      About
                      • Terms of Service
                      • Privacy Policy
                      • Status
                      • Contact Us
                      Downloads
                      • Releases
                      • Source code
                      • License
                      Docs
                      • Tutorials
                      • CustomHUD
                      • AutoSettings
                      • ScriptAPI
                      Community
                      • Forum
                      • Guilded
                      • YouTube
                      • Twitter
                      • D.Tube
                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups