Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Forge 1.8] How to Render Blocks in Inventory?


HassanS6000
 Share

Recommended Posts

Hi! I'm modding in Forge 1.8 and I was wondering how I'm supposed to render blocks in the inventory. I've made it so they render when placed, but when I try to render in Inventory, it says that my block is an Item, and the method

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(YourItem, metadata, new ModelResourceLocation("modid:items_registered_name", "inventory"));

 

is only for items.

 

So how do I render a block, which is obviously NOT an item?

Link to comment
Share on other sites

this is quite simple:

For each block, there is a corresponding item which you can get as following:

 

Item itemYourBlock = GameRegistry.findItem(mod.MODID, "yourBlock");

 

After this, you can simply render you block with the function you already have :)

 

~Brickfix

Link to comment
Share on other sites

Hi

 

This site has some info on Block Rendering

http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html  (See the four topics on Blocks and BLock rendering)

and the one on items

http://greyminecraftcoder.blogspot.com.au/2014/12/item-rendering-18.html

 

There is also an example project showing blocks and items here-

https://github.com/TheGreyGhost/MinecraftByExample

(see example 1) https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe01_block_simple

 

The short answers are- yes, you need a JSON file for the item.  No, your items doesn't need its own texture, your item can use the block texture.  And you also need to do

Item itemBlockSimple = GameRegistry.findItem("minecraftbyexample", "mbe01_block_simple");
ModelResourceLocation itemModelResourceLocation = new ModelResourceLocation("minecraftbyexample:mbe01_block_simple", "inventory");
final int DEFAULT_ITEM_SUBTYPE = 0;
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemBlockSimple, DEFAULT_ITEM_SUBTYPE, itemModelResourceLocation);

 

-TGG

 

Link to comment
Share on other sites

this is quite simple:

For each block, there is a corresponding item which you can get as following:

 

Item itemYourBlock = GameRegistry.findItem(mod.MODID, "yourBlock");

 

After this, you can simply render you block with the function you already have :)

 

~Brickfix

What...? Use

Item.getItemFromBlock(Block)

to get the corresponding Item.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

 

Item itemBlockSimple = GameRegistry.findItem("minecraftbyexample", "mbe01_block_simple");
ModelResourceLocation itemModelResourceLocation = new ModelResourceLocation("minecraftbyexample:mbe01_block_simple", "inventory");

 

 

Make sure you changed those lines to match your texture name and mod ID.

 

 

Maker of the Craft++ mod.

Link to comment
Share on other sites

Hi

 

You should register your items and blocks in FMLPreInitializationEvent , not FMLInitializationEvent.

 

The getItemModelMesher() stuff needs to come in FMLInitializationEvent, after you have registered the blocks and items.

 

Also just something I noticed - instances of your classes should always start with a lower case, otherwise it looks like they are classes, which is pretty confusing for anyone who reads your code

For example

SpartanBoots = new HaloArmor(HaloArmor, bootID, 3).setUnlocalizedName("SpartanBoots");  // should be spartanBoots

 

This resource is really good for learning how to format your code to make it easy for others to understand

http://google-styleguide.googlecode.com/svn/trunk/javaguide.html

 

-TGG

 

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • What do you mean "not working"? Your code (if it were logical) does nothing. Additionally, you have the following issues: You are using a client-only class (Minecraft) from common code (ClientSyncPacket). Your packet does not tell the client which player this is about. It needs to do so using the player's ID. Currently your packet just uses Minecraft#player, which is not necessarily the correct player.
    • when i tried joining a world my mc crashed exit code -805306369
    • Hello There! In the 73rd episode of Bed Wars we get into a lobby with a guy who had a cool name and for some reason Ben is very impressed with the name and thus the title!  
    • I have been trying to install forge, but I can't even get the installer to run. I'm really not sure what the issue is, first let me make sure I am even using the installer right, I downloaded the forge installer matching my minecraft version (1.19.2), if I double click the .jar from the download then I see a flash of a black window that immediately disappears. If I use a command prompt, I receive the following output: C:\Users\austi> java -jar forge-1.19.2-43.0.19-installer.jar Error: Unable to access jarfile forge-1.19.2-43.0.19-installer.jar   I feel like this is more likely a java issue than a forge issue but I was hoping that people here might be able to help. I've tried a couple versions of java, at first I was using 8 I believe because all of the install guides for forge were a bit older so they linked to the java website rather than oracle. I tried version 18 from the oracle site and received the same result from command prompt. It is also entirely possible that I am doing something else wrong that is blatantly obvious to everyone else.
    • Here is my configuration: % java -version java version "18.0.2" 2022-07-19 Java(TM) SE Runtime Environment (build 18.0.2+9-61) Java HotSpot(TM) 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing) forge-1.19-41.1.0-mdk on macOS Monterey 12.5 I ran the command: ./gradlew genEclipseRuns and was hoping it will generate the Eclipse project files for me. The run log is at https://gist.github.com/arun-gupta/06b983a6976b4c0a0f510d0dc225ddd3 and the generated directory structure is at https://gist.github.com/arun-gupta/3f5bfc70ec5d3d903b0f97d42840abda. In previous versions (1.12-ish), it used to generate an eclipse directory but 1.19 does not seem to have it. I tried opening the top-level forge directory but Eclipse does not recognize it as a project as well. How do I open this project in Eclipse now?  
  • Topics

×
×
  • Create New...

Important Information

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