Jump to content

Creating a custom tile entity with a container and binding it to already registered custom block


applegod

Recommended Posts

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.

Link to comment
Share on other sites

Tile enntities haven't changed significantly in several versions. 

 

Override hasTileEntity and createTileEntity in your block class. 

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

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.

Link to comment
Share on other sites

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 by Beethoven92

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to comment
Share on other sites

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.

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

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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. :)

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.