Jump to content

How to click an item in chest menu?


Zappic3

Recommended Posts

Hello, I'm currently trying to create a client side mod for forge 1.18.2.

I want to quickly move an item from an open chest inventory to the player's inventory. (like shift + left click)

I found a method called "clicked". When I use that method, the item is moved, though it is only moved for the client. As soon as I interact with the item in my inventory, it disappears. It seems like the method only simulates a click for the client and doesn't apply/send the click to the world or server.

 

Here is my code:

Minecraft.getInstance().player.containerMenu.clicked(0, 0, ClickType.QUICK_MOVE, Minecraft.getInstance().player);

And here is a video showing the clicking that is done by this method:

https://youtu.be/B1O8fLzATXk

 

I hope someone can help me, thanks in advance.

Link to comment
Share on other sites

That will never work. Items moving between inventories needs to happen on the server.

All you are doing is creating "ghost" ItemStacks on the client.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

To do it on the client via the screen, it will depend upon the implementation. I have never tried to do this myself.

The "correct way" to do custom processing for a Screen is to use forge's ScreenEvent.InitScreenEvent to do something like add your own button.

That button would then do a network request (you write yourself) to do the processing on the server, e.g use the inventories' ItemHandlers to move the items.

 

I can tell you, you need to be on the render thread because these methods access opengl state, e.g. whether the shift key is down.

I would start by looking at AbstractContainerScreen.mouseClicked() (or its subclass override for the Screen if it has one) so you can see what other state it references beyond the parameters you are passing and what other methods you need to call.

 

 

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Thanks for your time warjort,

I found the solution by looking at the source code from the controllable mod.

For anyone that is interested, use the following method:

Minecraft.getInstance().gameMode.handleInventoryMouseClick(menu_id, slot_to_click, mouse_button, click_type, Minecraft.getInstance().player);

 

Edited by Zappic3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.