Jump to content

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


Recommended Posts

Posted

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?

Posted

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.

Posted

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.

Posted
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?

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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