Sinhika Posted August 1, 2018 Share Posted August 1, 2018 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? Quote Stuff I maintain: https://minecraft.curseforge.com/members/sinhika/projects Repositories: https://github.com/Sinhika?tab=repositories Link to comment Share on other sites More sharing options...
Sinhika Posted August 1, 2018 Author Share Posted August 1, 2018 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: Block - https://github.com/Sinhika/Netherrocks/blob/1.12/src/main/java/alexndr/plugins/netherrocks/blocks/NetherFurnaceBlock.java Container and Slots - https://github.com/Sinhika/Netherrocks/tree/1.12/src/main/java/alexndr/plugins/netherrocks/inventory GUI - https://github.com/Sinhika/Netherrocks/blob/1.12/src/main/java/alexndr/plugins/netherrocks/gui/NetherFurnaceGui.java Tile Entity - https://github.com/Sinhika/Netherrocks/blob/1.12/src/main/java/alexndr/plugins/netherrocks/tiles/NetherFurnaceTileEntity.java 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. Quote Stuff I maintain: https://minecraft.curseforge.com/members/sinhika/projects Repositories: https://github.com/Sinhika?tab=repositories Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 1, 2018 Share Posted August 1, 2018 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. Quote 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 More sharing options...
Sinhika Posted August 5, 2018 Author Share Posted August 5, 2018 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? Quote Stuff I maintain: https://minecraft.curseforge.com/members/sinhika/projects Repositories: https://github.com/Sinhika?tab=repositories Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 5, 2018 Share Posted August 5, 2018 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. Quote 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 More sharing options...
Recommended Posts
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.