Jump to content

Recommended Posts

Posted

How do I move an item in inventory from cell X to cell Y?
How do I move an item from Inventory X to Box Y of an open chest?
I'm thinking of using the Robot class, i.e. Simulate clicking the mouse buttons, but then you need to know the coordinates of the cells. I do not know how to get them.

I tried to understand the source code of the Inventory Tweaks mod, but I did not understand how it works. It seems, too, with the help of simulation

Posted

Please clarify: What exactly are you trying to acheive. What do you mean by "move an item in inventory". Are you making a custom inventory, an addon for inventory tweaks or perhaps even something totally different?

Posted

Example:
I have potatoes in the inventory in cell X.
My task is to move the potatoes from cell X to cell Y.
The inventory is standard, you just need to move items in it. From one cell to another.

 

It is important that all actions should take place only on the client side

 

Posted

get the stack in slot X with inventory#getStackInSlot(X);

COPY THE STACK

set the stack with inventory#setStackInSlot(Y, copyOfX);

clear the old stack in slot X with inventory#setStackInSlot(X, ItemStack.EMPTY.copy())

 

Make sure to do additional checking king to make sure the itemstack can fit/is allowed to be in that slot etc.

Take a look at Container#transferStackInSlot

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

You don't need to clone the empty stack.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
2 minutes ago, Draco18s said:

You don't need to clone the empty stack.

What if some code modifys that stack? Like merges it with a stack that isn’t empty? Won’t that modify ItemStack.EMPTY then?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
4 minutes ago, Cadiboo said:

What if some code modifys that stack? Like merges it with a stack that isn’t empty? Won’t that modify ItemStack.EMPTY then?

You can't. ItemStack.EMPTY is meant to be immutable. That's why its a static reference and named the way its named.

 

Its item is Air (and you can't change a stack's item) and Air is always empty.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
49 minutes ago, Draco18s said:

You can't. ItemStack.EMPTY is meant to be immutable. That's why its a static reference and named the way its named.

 

Its item is Air (and you can't change a stack's item) and Air is always empty.

Isn’t it’s item null? Point taken that you can’t change the item though

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
9 hours ago, Cadiboo said:

Isn’t it’s item null?

That it is, but null has always been Minecraft's air. Block.AIR was null at one point too.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
10 hours ago, Cadiboo said:

get the stack in slot X with inventory#getStackInSlot(X);

COPY THE STACK

set the stack with inventory#setStackInSlot(Y, copyOfX);

clear the old stack in slot X with inventory#setStackInSlot(X, ItemStack.EMPTY.copy())

 

As I understand it, this will not work?

Posted
Just now, NoName_ said:

As I understand it, this will not work?

And why do you think that?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
    Minecraft.getMinecraft().player.inventory.setInventorySlotContents(0, Minecraft.getMinecraft().player.inventory.getStackInSlot(i).copy());
    Minecraft.getMinecraft().player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);

It does not work on a server. A server does not know that I moved the item. I understand me need to use the exchange of packages?

 

Edited by NoName_
Posted
4 minutes ago, NoName_ said:

    Minecraft.getMinecraft().player.inventory.setInventorySlotContents(0, Minecraft.getMinecraft().player.inventory.getStackInSlot(i).copy());
    Minecraft.getMinecraft().player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);

That's because your using client-side only code.

 

5 minutes ago, NoName_ said:

need to use the exchange of packages?

What is "exchange of packets"?

From a user perspective, when do you want this to happen in the inventory? 

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
4 minutes ago, larsgerrits said:

What is "exchange of packets"?

Packets? I do not know how to properly call it. (NetHandlerPlayClient  and NetHandlerPlayServer)

4 minutes ago, larsgerrits said:

From a user perspective, when do you want this to happen in the inventory? 

I need a method that changes the place of an item in the inventory.
I do with the example of a hoe. I'm looking for a hoe in the inventory, when I found it, I move it to the first location of the inventory.

 

for (int i = 1; i < 36; i++) {
    if(Minecraft.getMinecraft().player.inventory.getStackInSlot(i).getItem() instanceof ItemHoe){
        Minecraft.getMinecraft().player.inventory.setInventorySlotContents(0, Minecraft.getMinecraft().player.inventory.getStackInSlot(i).copy());
        Minecraft.getMinecraft().player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
        break;
    }
}
Posted

I recommend placing some breakpoints, manually doing this & seeing what methods get called. Some breakpoints in CPackets and the CLIENTSIDE containers (as your making a client side mod) would be a good place to start. Make sure that your not looking at the servers handling when debugging

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

And with "from a user perspective" I meant: what should the user to do run this action? For example: the user presses a key or clicks a button in a GUI.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

What are the circumstances

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
1 minute ago, Animefan8888 said:

What version are you doing this for? And is this only for the client?

1.12.2 

Yes, only on the client, because it is necessary for the mod to work on other servers

Posted
2 minutes ago, NoName_ said:

1.12.2 

Yes, only on the client, because it is necessary for the mod to work on other servers

And why not just use Inventory Tweaks? It has the same feature you are requesting from us.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
1 minute ago, Animefan8888 said:

And why not just use Inventory Tweaks? It has the same feature you are requesting from us.

I do not understand how it works. This is not good. Besides, why add the whole mod if I need one function. In addition, it would not be bad to understand this issue.

Posted
1 minute ago, NoName_ said:

I do not understand how it works. This is not good. In addition, it would not be bad to understand this issue.

What you need to do from your original implementation is let the server know that you changed them.

 

3 minutes ago, NoName_ said:

Besides, why add the whole mod if I need one function. 

Because that one function is already done and the inventory sorting function is a god send.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.