applegod Posted January 8, 2021 Posted January 8, 2021 I think the title is pretty self-explanatory. I have experience with Java & Minecraft (I started with coding spigot plugins), however I am new to Forge. I have decided that I want to make mods for the newest version (1.16.4), but soon realised there aren't many (almost none) tutorials for this version. I especially cannot figure out (after hours of searching through original Minecraft code) how to create a block that has it's own inventory that can be interacted with and saves when closed. I kinda figured out it has to do with tile entities but because of my lack of knowledge of the Forge API (the docs aren't helpful around this theme whatsoever) when I tried creating something related to tile entities I always encountered some stupid errors that I don't even remember yet. I would really appreciate any help I can get around this topic because it doesn't seem so straight forward. What I am mainly looking for here is complete code of a fully working yet simple block which basically just stores items (or later even a custom furnace) and upon right click opens a container (inventory/gui) in which these items are stored (for the most part I have already figured this part out) from which I could learn more about this topic. PS: I already have my block registered and working in game. Quote
Draco18s Posted January 8, 2021 Posted January 8, 2021 Tile enntities haven't changed significantly in several versions. Override hasTileEntity and createTileEntity in your block class. Quote 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.
applegod Posted January 8, 2021 Author Posted January 8, 2021 12 minutes ago, Draco18s said: Tile enntities haven't changed significantly in several versions. Override hasTileEntity and createTileEntity in your block class. Yeah but for that I need a custom tile entity class and a custom tile entity type and register all that don't I? Could you provide me with any sort of a code example for this? I understand that there are these functions that create the tile entities etc. but I just don't get how they are generally connected whatsoever. Quote
Beethoven92 Posted January 9, 2021 Posted January 9, 2021 (edited) I think studying a bit this example will give you useful informations: https://github.com/TheGreyGhost/MinecraftByExample/tree/working-1-16-4/src/main/java/minecraftbyexample/mbe30_inventory_basic It explains how to create a basic chest-like block. The code is very well documented Edited January 9, 2021 by Beethoven92 Quote Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
Draco18s Posted January 9, 2021 Posted January 9, 2021 2 hours ago, applegod said: Yeah but for that I need a custom tile entity class and a custom tile entity type and register all that don't I? Yes. Which is where you store the inventory. You can't store it anywhere else... 2 hours ago, applegod said: Could you provide me with any sort of a code example for this? I understand that there are these functions that create the tile entities etc. but I just don't get how they are generally connected whatsoever. Vanilla code is a pretty good resource. Just ignore anything about IInventory and use the Forge supplied Capabilities system instead. Quote 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.
applegod Posted January 9, 2021 Author Posted January 9, 2021 12 hours ago, Beethoven92 said: I think studying a bit this example will give you useful informations: https://github.com/TheGreyGhost/MinecraftByExample/tree/working-1-16-4/src/main/java/minecraftbyexample/mbe30_inventory_basic It explains how to create a basic chest-like block. The code is very well documented Hey, thanks for the advice, I looked into this and got inspired. I'm pretty sure everything works now but when I try to open the container I get an error that says: [14:09:56] [Render thread/WARN] [minecraft/ScreenManager]: Failed to create screen for menu type: modId:apple_smelter_container I don't really understand where the mistake happened. Should I post my code? Quote
applegod Posted January 9, 2021 Author Posted January 9, 2021 3 minutes ago, diesieben07 said: That error happens when you did not register an IScreenFactory for your container type. You can post your code if you can't figure it out. Thanks, I understand that's done with ScreenManager.registerFactory(StartupCommon.containerTypeContainerBasic, ContainerScreenBasic::new); But where should I put this? In my main startup class next to my bus registries? Quote
applegod Posted January 9, 2021 Author Posted January 9, 2021 3 minutes ago, diesieben07 said: FMLClientSetupEvent with enqueueWork. Alright thanks, is that mod event bus or forge event bus? And how can I convert the registerFactory() function to a runnable/work which I can enqueue? Quote
applegod Posted January 9, 2021 Author Posted January 9, 2021 3 minutes ago, diesieben07 said: Just use a lambda expression. event.enqueueWork(() -> ScreenManager.registerFactory(StartupCommon.containerTypeContainerBasic, ContainerScreenBasic::new)); Used this and everything works perfectly now! Thank you so much. Quote
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.