Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So I was trying to create a custom furnace in 1.12.2, but whenever I tried to open the furnace, the game would crash. And then I tried to find out why, and apparently the code is outdated, and instead of using IInventory, I should use capabilities but I don't really know what it is and how to use it.

Capabilities are easy.

There's only three or four things you need to do.

 

The first is to remove any existing IInventory code.

Then add (in place of ItemStack[]) an ItemStackHandler. You can use one or multiple, depending on how you want to expose these as slots, or collection of slots, in the places that they're used.

Next, override getCapability. if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY), you return one of your the ItemStackHandler fields. If you want more than one to be exposed, you can merge them with CombinedInvWrapper. Return super for any case you don't handle.

Third, override hasCapability and make it return true for any case where you return an ItemStackHandler (and call super for other cases). A lot of modders override this to return this.getCapability(capability, facing) != null;

 

The only "tricky" part is that if you want to expose different slots for different sides or do things like having output-only slots, but that's largely logic.

 

Fourth, you need to update your Gui/Container to use SlotItemHandler (or a subclass thereof) instead of Slot.

 

And a couple of examples:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/ores/entities/TileEntitySifter.java#L141

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/ores/inventory/ContainerSifter.java#L27

https://github.com/Draco18s/ReasonableRealism/tree/1.12.1/src/main/java/com/draco18s/hardlib/api/internal/inventory

 

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.

  • Author
1 hour ago, Draco18s said:

Capabilities are easy.

There's only three or four things you need to do.

 

The first is to remove any existing IInventory code.

Then add (in place of ItemStack[]) an ItemStackHandler. You can use one or multiple, depending on how you want to expose these as slots, or collection of slots, in the places that they're used.

Next, override getCapability. if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY), you return one of your the ItemStackHandler fields. If you want more than one to be exposed, you can merge them with CombinedInvWrapper. Return super for any case you don't handle.

Third, override hasCapability and make it return true for any case where you return an ItemStackHandler (and call super for other cases). A lot of modders override this to return this.getCapability(capability, facing) != null;

 

The only "tricky" part is that if you want to expose different slots for different sides or do things like having output-only slots, but that's largely logic.

 

Fourth, you need to update your Gui/Container to use SlotItemHandler (or a subclass thereof) instead of Slot.

 

And a couple of examples:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/ores/entities/TileEntitySifter.java#L141

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/ores/inventory/ContainerSifter.java#L27

https://github.com/Draco18s/ReasonableRealism/tree/1.12.1/src/main/java/com/draco18s/hardlib/api/internal/inventory

 

I'll try to implement this into my code, and thanks for the response. This really helped me understand what they are.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.