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. Custom Script Help

Custom Script Help

Scheduled Pinned Locked Moved Solved ScriptAPI
9 Posts 2 Posters 707 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.
  • D Offline
    D Offline
    DeScrupter
    wrote on last edited by
    #1

    Hi Guys,

    i recently dived into custom scripts and i would like that the player drops the current main hand slot i have tried already multiple things from different forums and also tried to do my own research in this "fabric" (yarn) library and on the "documentation" of LB but i just cant figure it out if you could help me with that it would be very nice.

    Thank you in advance,
    DeScrupter

    1 Reply Last reply
    0
    • C Offline
      C Offline
      commandblock2
      wrote on last edited by commandblock2
      #7

      image.png

      To properly understand the api you will have to have the mod development setup up. Although inventory do have a dropItem() method it appears that it's clearly not what you are looking for. You should use mc.player.dropSelectedItem(false) or true to drop the entire stack, as that api sends PlayerActionC2SPacketPlayerActionC2SPacket to the server. (This one is tested to be working at my side). Also apologies for the previous confusion about the dropItem function (because I assumed that it would work by just looking at its name).

      If you would like to change the main hand of the player just use mc.player.inventory.selectedSlot = 1 or any number from 0 to 9. https://github.com/CCBlueX/LiquidBounce/blob/10977247fe5b6b36d5841a9b5f21b758e14f1eff/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleAntiAFK.kt#L111

      For further usage you will have to figure out on your own by cloning the LiquidBounce's git repo and run the gradle task of genSources to understand how Minecraft works, or, find out a example module in LB for how it works.

      This is as far as I am willing help you given the snippet you have given me. If you are able to provide a minimal full script for me for testing I might be able to do more.

      1 Reply Last reply
      undefined
      0
      • C Offline
        C Offline
        commandblock2
        wrote on last edited by
        #2

        It can be a bit difficult to figure this out if you are going to very new to Minecraft modding or scripting.
        Do you mind showing us what you have tried so far so we can try to help you fix what u have? It would be much easier for us to help if you can provide a sample code that fails to do the intended behavior or actual error message/log.
        Also you can refer to this page to try to debug your script by placing break points in and type in the debug console for quick attempts.

        If you are looking for deeper understanding to how scripting works I would recommend reading the source code of Minecraft/LiquidBounce, although that could take some time.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DeScrupter
          wrote on last edited by
          #3

          So i got this its not the complete script but the rest works i just need to drop the hotbar

          for (let i = 0; i < 9; i++) {
          let dropTask = new TimerTask({
          run: function() {

                var inventory = mc.thePlayer.getInventory();
                var itemStack = inventory.getStackInSlot(i);
          
                if (itemStack !== null) {
          
                  mc.thePlayer.dropItem(true, itemStack);
                  Client.displayChatMessage(`Dropped items from slot ${i + 1}`);
                } else {
                  Client.displayChatMessage(`Slot ${i + 1} is empty.`);
                }
              }
            });
          
            timer.schedule(dropTask, delay);
          }
          
          1 Reply Last reply
          0
          • C Offline
            C Offline
            commandblock2
            wrote on last edited by commandblock2
            #4

            It looks like that the naming you are using is from the legacy version yet you mentioned yarn previously, please confirm if you are using the nextgen or legacy version of LiquidBounce.

            If you are on nextgen(1.21.4), the api has changed to something like the following example, it no longer uses mc.thePlayer and uses mc.player instead

                inventory = mc.player.getInventory()
                itemStack = inventory.getStack(1)
                mc.player.dropItem(itemStack, false)
                // the previous line didn't work for me, either true or false doesn't work, not sure why yet
                // will look back at this once I got sometime to update my fork of LBNG project up-to-date
                // but the player swings if I ran this code
            

            and there is no TimerTask presented in the default global context , you might have to write your own, or just maybe use a counter on a event as well.

            If you are using legacy version(1.8.9) instead, please look for documentation about mcp instead of yarn and I am not sure if we even have a java doc for mcp if we don't setup the project.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DeScrupter
              wrote on last edited by
              #5

              so just a question what is this code snipped trying to archive

              should it drop the players mainhand or hotbar or inventory?

              and will it even work

              i am sorry but its a bit hard to understand

              i got this now and removed the timer

              run: function() {
              Client.displayChatMessage(Dropping Item);
              inventory = mc.player.getInventory()
              itemStack = inventory.getStack(1)
              mc.player.dropItem(itemStack, false)
              }

              1 Reply Last reply
              0
              • C Offline
                C Offline
                commandblock2
                wrote on last edited by
                #6

                No it is not going to work, I have no idea what the parameter mean(offhand or which slot), the only thing that I know is that the type of the parameter should look like snippet (if the dropItem really is what we need to call, as for actually dropping the item we are probably going to look at the source code of Minecraft or ModuleInventoryCleaner and figure out how that works.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  commandblock2
                  wrote on last edited by commandblock2
                  #7

                  image.png

                  To properly understand the api you will have to have the mod development setup up. Although inventory do have a dropItem() method it appears that it's clearly not what you are looking for. You should use mc.player.dropSelectedItem(false) or true to drop the entire stack, as that api sends PlayerActionC2SPacketPlayerActionC2SPacket to the server. (This one is tested to be working at my side). Also apologies for the previous confusion about the dropItem function (because I assumed that it would work by just looking at its name).

                  If you would like to change the main hand of the player just use mc.player.inventory.selectedSlot = 1 or any number from 0 to 9. https://github.com/CCBlueX/LiquidBounce/blob/10977247fe5b6b36d5841a9b5f21b758e14f1eff/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleAntiAFK.kt#L111

                  For further usage you will have to figure out on your own by cloning the LiquidBounce's git repo and run the gradle task of genSources to understand how Minecraft works, or, find out a example module in LB for how it works.

                  This is as far as I am willing help you given the snippet you have given me. If you are able to provide a minimal full script for me for testing I might be able to do more.

                  1 Reply Last reply
                  undefined
                  0
                  • D Offline
                    D Offline
                    DeScrupter
                    wrote on last edited by
                    #8

                    OMG i got it working with your help

                    The

                    mc.player.dropSelectedItem(false)
                    and
                    mc.player.inventory.selectedSlot = 1

                    when combining them with a for loop which goes from 0 to 8 will drop all slots in the hotbar

                    Thank you for helping me. I can now finally finish the script. Thank you very very much

                    Maybe someday i will write another help request (hopefully only maybe)

                    Again thank you very much for your help 😁

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      commandblock2
                      wrote on last edited by
                      #9

                      You are welcome and I am willing to accept further help requests, would appreciate a example error script or errors in the logs. 😁

                      1 Reply Last reply
                      0
                      • D DeScrupter has marked this topic as solved on
                      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