Jump to content

Need working examples of IItemHandler-based furnace or machine to study


Sinhika

Recommended Posts

I've been trying to implement a custom furnace that uses IItemHandler instead of IInventory as the latter is deprecated, and getting stuck on the client-server (tile-entity <-> GUI) sync. After a certain point it just fails to work, and not only does my custom furnace-thing stop working, vanilla furnaces stop working!  Makes me wonder if I'm somehow crashing the block update mechanism or the tick handling.

 

I'd like to figure this one out myself, but the vanilla furnace isn't a good example as it is still ISidedInventory-based, and the open-source mods with furnace-like machines are very complex and have the working details split between layers of inherited classes and handler classes that make it a pain to figure out what is going on by studying the code. So, anyone have any simple, yet successfully working examples of IItemHandler-based machines with slots, GUI, and stuff happening over time that I can study to figure out what SHOULD be going on?

Link to comment
Share on other sites

Well, I did want to avoid inflicting all that code on you, but if you're willing to give it a look:

 

The device in question is the Nether Furnace in Netherrocks:  https://github.com/Sinhika/Netherrocks

Nether Furnace classes:

Ancestral classes are in the SimpleCore library, general source at: https://github.com/Sinhika/SimpleCore

Mostly, you'll probably find what you are looking for in https://github.com/Sinhika/SimpleCore/tree/1.12/src/main/java/alexndr/api/content

 

Version 1.12.2 if it wasn't obvious. I've been compiling against the current stable version of Forge, 14.23.4.2705 .  If there's an important fix in a later version that  I should move to, please let me know.

Link to comment
Share on other sites

A furnace works ultimately very simply, especially with IItemHandler. A furnace simply needs to know if it can cook the item in question(is it part of a recipe/does it have fuel/does it have room for the result). This can be done very easily.

 

  • You need a method that burns fuel if it can and needs to while also checking if it has fuel.
  • You need a method that checks if the item in the input slot is part of a recipe.
  • You need a method that checks if there is room in the output slot(s) (this can be done using IItemHandler.insertItem(slot, item, true) if it returns an empty ItemStack then there is room for the output).
  • Next you just need to implement ITickable and in the update method check all of the above and once enough time has passed complete the burning by calling IItemHandler.insertItem and IItemHandler.extractItem.

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.

Link to comment
Share on other sites

On 8/1/2018 at 6:11 PM, Animefan8888 said:

A furnace works ultimately very simply, especially with IItemHandler. A furnace simply needs to know if it can cook the item in question(is it part of a recipe/does it have fuel/does it have room for the result). This can be done very easily.

 

  • You need a method that burns fuel if it can and needs to while also checking if it has fuel.
  • You need a method that checks if the item in the input slot is part of a recipe.
  • You need a method that checks if there is room in the output slot(s) (this can be done using IItemHandler.insertItem(slot, item, true) if it returns an empty ItemStack then there is room for the output).
  • Next you just need to implement ITickable and in the update method check all of the above and once enough time has passed complete the burning by calling IItemHandler.insertItem and IItemHandler.extractItem.

 

I presume this is all in the tile entity class?  So how do you correctly update the GUI to show cooking progress, etc?

Link to comment
Share on other sites

4 hours ago, Sinhika said:

I presume this is all in the tile entity class?  So how do you correctly update the GUI to show cooking progress, etc?

You can recreate the abstraction of getField and setField if you wish, but the premise is you need to override detectAndSendChanges and updateProgressBar. Your detect and send changes will iterate through the listeners field and then call sendWindowProperty.

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.

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.