Jump to content

[Solved]Transferring itemStack on shift click without loosing items


Recommended Posts

Posted

Hello,

I created container with 5 slots following tutorial here on forge forums.

 

I also properly(at least I hope so) modified transferStackInSlot method. The problem is that I want my container to have capacity only 1 per slot (not 64). I set this using getInventoryStackLimit in my TileEntity for the container.

 

The problem is that each time I transfer stack from player inventory into the container holding shift, it removes whole stack from player inventory, but transfers only 1 piece into the container(obviously because the limit per slot is set to 1).

 

I would like to know how to force it to pick only so many pieces that fits into container for transferring(when using shift). If this would be too difficult, I would simply like to do it so it picks only one item even when using shift.

 

I guess I need to rewrite container method mergeItemStack? Or maybe something different?

 

Thanks in advance to anyone who tries to help :)

 

Here is my transferStackInSlot method if needed

 

  Reveal hidden contents

 

Sorry for mistakes, English is not my mother tongue

Posted

You could try checking the stack size with stack.stackSize, and check if it equals 1, otherwise subtract 1 from the stack, and add a new stack to the slot, then check if there is an empty slot and if there is, the repeat

Hope this helps, I'm still newbish to modding

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Posted

I think I figured it out.

 

You don't need to change anything from the defaults except for the following:

change the TileEntity.getInventoryStackLimit to return 1, or any value you want.

 

Then in your Container class (ContainerTiny in the tutorial) add the following function:

 

  Reveal hidden contents

 

 

Basically, this function was called from Container, which did not care about the value of tileEntity.getInventoryStackSize() at all.

I made it so when you shift right click the container will be filled as much as possible. You can change that in the code above pretty easily.

 

Hope that helps

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.