Custom Script Help
-
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 -
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 usemc.player.dropSelectedItem(false)
or true to drop the entire stack, as that api sendsPlayerActionC2SPacketPlayerActionC2SPacket
to the server. (This one is tested to be working at my side). Also apologies for the previous confusion about thedropItem
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#L111For 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.
-
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.
-
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); }
-
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 usesmc.player
insteadinventory = 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.
-
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)
} -
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.
-
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 usemc.player.dropSelectedItem(false)
or true to drop the entire stack, as that api sendsPlayerActionC2SPacketPlayerActionC2SPacket
to the server. (This one is tested to be working at my side). Also apologies for the previous confusion about thedropItem
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#L111For 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.
-
OMG i got it working with your help
The
mc.player.dropSelectedItem(false)
and
mc.player.inventory.selectedSlot = 1when 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
-
You are welcome and I am willing to accept further help requests, would appreciate a example error script or errors in the logs.
-