Jump to content

[1.12.2] How would I create a custom furnace?


CompactibleBlock

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.