Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So I have an item registered in the game, and have a class ItemRenderRegister to register the item to a modelresource location via the following code:

Spoiler

public class ItemRenderRegister {
	public static void registerItemRenderer() {
		Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(ModItems.oldTome, 0, new ModelResourceLocation("ds:oldtome", "inventory"));

	}

the method is called in the client proxy

but I can't wrap my head around how to use the ModelResourceLocation. I'm getting no errors about a missing json file, the item just simply has not model or texture, which makes it very hard to debug. 

Edited by GooberGunter

I'm no expert, I have just posted my own problem, but I would suggest checking your directory eg: make sure there is an assets folder, make sure the .json is valid etc, take my advice with a grrain of salt though as i said I'm no expert

  • Author

There is a Json and it’s in the right directory, ill double check when I get back, but I’m to too sure about it’s validity, maybe they changed the json files in 1.12.2 again. 

  • Author

Quick Question, what should the model path look like modid:filename or modid:item//filename. Or modid:models\\item\\filename.

 

Edited by GooberGunter

  • Author

        ModelLoader.setCustomModelResourceLocation(ModItems.oldTome, 0, new ModelResourceLocation("ds:models//item//old_tome.json", "inventory"));
 

still not working

 

Spoiler

{
    "parent": "builtin/generated",
    "textures": {
        "layer0": "ds:items/old_tome"
    }
}

 And I'm not any errors in the log about the texture location so I know that's right. It's just this part. And I also had a problem where I made two instances of the item, registering one and registering the render of the other, which I have fixed.

Edited by GooberGunter

You should use items/blocks getRegistryName() as the first parameter.
First parameter should not contain any extensions (".json") nor any file-separators ("/"). All of that is automagically done "behind the curtains" for you.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

  • Author

That was suggested in the documentation but i didn't see it in the source code, but I fixed it now. I also added the first parameter, but it's still not showing up

		ModelLoader.setCustomModelResourceLocation(ModItems.oldTome, 0, new ModelResourceLocation(ModItems.oldTome.getRegistryName(), "ds:old_tome"));

Am i supposed to register the render or is the model loader enough?

 

Here is all the code involving the item:

 

ModItems:

Spoiler

package com.GooberGunter.DivineSorcery.common.items;

import java.rmi.registry.Registry;

import com.GooberGunter.DivineSorcery.DSReferences;
import com.GooberGunter.DivineSorcery.common.utils.Util;

import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.item.Item;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public final class ModItems {
	
	public static Item oldTome = new ItemOldTome("old_tome");
	
	@Mod.EventBusSubscriber
	public static class ItemRegister{
		
		@SubscribeEvent
	    public static void registerItem(RegistryEvent.Register<Item> e) {
	    	e.getRegistry().register(oldTome);
	    	Util.logger.info("ITEMS REGISTERED");
	    }//Items MUST MUST MUST MUST MUST BE REGISTERED IN STATIC FIELDS
	}
}

 

ItemRegisterRender:

Spoiler

package com.GooberGunter.DivineSorcery.client.render.items;

import java.io.FileNotFoundException;
import java.io.IOException;

import com.GooberGunter.DivineSorcery.DSReferences;
import com.GooberGunter.DivineSorcery.common.items.ModItems;
import com.GooberGunter.DivineSorcery.common.utils.Util;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;

public class ItemRenderRegister {
	public static void registerItemRenderer() {
		ModelLoader.setCustomModelResourceLocation(ModItems.oldTome, 0, new ModelResourceLocation(ModItems.oldTome.getRegistryName(), "ds:old_tome"));
		Util.logger.info("Item Renders Registered");
	}
}

 

 

Edited by GooberGunter

...

The second parameter is the variant of which you want to use... Unless otherwise specified in the BlockState file, there is only "inventory" for items, but blocks also have "normal" (placed)...

The Item's RegistryName (which comes from getRegistryName()) should already equal "ds:old_tome", IF you used setRegistryName("old_tome") in the item's constructor... You don't need to worry about that...
On a tangent however, modid's are recommended to never be shortened or otherwise altered from the original "name". I don't know what "ds" stands for, but for example, what if I made a mod called "Deep Storage" and also used "ds" as my modid? The longer a modid is, the probability of another mod having the same name exponentially becomes smaller.

 

You also need to actually have this code RUN during the ModelRegistryEvent...

You can do this very simply by annotating your client-proxy with @Mod.EventBusSubscriber and moving your registerItemRenderer method to said client-proxy. Your registerItemRenderer() also needs to become registerItemRenderer(ModelRegistryEvent event), so that the method can be picked up by the scanner, and called when the ModelRegistryEvent is fired, which then will run the code.

Edited by Matryoshika

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

  • Author

Thanks a lot for the tips. Man, it seems like everything was replaced with annotations

 

So to be clear, the render register no longer goes in the init? What are the initialization methods for?

 

Now I'm getting a file not found exception, I've been waiting for one. I have a lead.

 

Edit: classic blockstate, I fixed the chain and now I have the item model json, the blockstate json, and the texture. Everything works fine now

 

 

Do recipes, world generators, and entities still initialize the same or are they events too?

Edited by GooberGunter

2 hours ago, GooberGunter said:

Do recipes, world generators, and entities still initialize the same or are they events too?

 

Recipes and entities are managed by registries, so register them in RegistryEvent.Register<IRecipe> and RegistryEvent.Register<EntityEntry> respectively. Use EntityEntryBuilder to create the EntityEntry.

 

World Generators aren't managed by a registry and there's no dedicated event to register them, so do it in preInit/init/postInit.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.