Jump to content

Combining ItemStacks which have capabilities


Jay Avery

Recommended Posts

(I hope there's no daily post limit on this forum...)

 

I'm working on an ItemStack capability which is given to stackable (max stack size > 1) items. Stacks with the capability can be in one of several defined states. I want stacks of the same item to be able to be combined if they are in the same state, but not if they are different. The trouble is that Forge's areCapsCompatible is called in most places, but not quite everywhere. One obvious spot where it's missing is in Container#slotClick, which refers to Container.canAddItemToSlot. And that method checks that the items and stackTagCompounds are equal, but ignores capability tags. But it's static, so I can't override it to add my own functionality.

 

I could try to override slotClick (I'm already overriding the player container anyway), but it's a huge method and it also refers to a bunch of private fields, and seems like it would be generally a bad idea.

 

I could try to add my capability's tags to the stackTagCompound, but that's not the intended use so I'm guessing it would have other messy effects or wouldn't work (the doc comment says that Minecraft validates only non-stackable items can use it, although I haven't found where that happens in the code).

 

Does anyone have any suggestions? Is there any way for me to edit a static method (if I could just add one areCapsCompatible check to Container.canAddItemToSlot...!)? Is there some other workaround I can use to force Minecraft to check capabilities when attempting to combine stacks? Forge is great, but times like this make me wish I could just edit the vanilla classes myself!

Edited by Jay Avery
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.



×
×
  • Create New...

Important Information

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