Jump to content

(SOLVED) [1.11] Changing Texture/Model file on right click?


Recommended Posts

Posted

Is there an easy way to change the texture of an item in say, an overridden onItemRightClick, by changing which layer, or which model file is being loaded?

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

Is there an easy way to change the texture of an item in say, an overridden onItemRightClick, by changing which layer, or which model file is being loaded?

It depends is it limited? Or can it be anything?

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.

Posted

It depends is it limited? Or can it be anything?

 

Just the easiest way. Preferably if it doesn't involve just removing the item, and adding in another one.

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

It depends is it limited? Or can it be anything?

 

Just the easiest way. Preferably if it doesn't involve just removing the item, and adding in another one.

Modifing the metadata of the stack, and assigning the different metadata a different model when registered using ModelLoader.setCustomModelResourceLocation(...)

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.

Posted

Modifing the metadata of the stack, and assigning the different metadata a different model when registered using ModelLoader.setCustomModelResourceLocation(...)

 

Hmm. That sounded easy until I managed to confuse myself. I was originally using

 

 

public static void registerRenders() 
{
registerRender(testItem);
}

public static void registerRender(Item item)
{
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}

 

 

and it could find my original json file just fine, and it showed in game. I tried changing that to take a string to seperate them, making it:

 

 

 

public static void registerRenders() 
{
registerRender(testItem, 0, "Stage0");
registerRender(testItem, 1, "Stage1");
registerRender(testItem, 2, "Stage2");
}

public static void registerRender(Item item, int meta, String addon)
{
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, meta, new ModelResourceLocation(item.getRegistryName()+addon, "inventory"));
}

 

 

And that didn't complain about not being able to find my new json files, but it was broken texture in game.

 

After switching that to

 

ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName() + addon, "inventory"));

Now it also can't find my json files.

 

After remembering to register my event, same problem as above. It doesn't complain that it can't find the json files... ...it just doesn't load the textures in game.

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

You shouldn't be using the ModelMesher anyway, that method has been outdated for a while.

 

Make sure you're calling ModelLoader.setCustomModelResourceLocation during the ModelRegistryEvent (preferred 1.11 way, although I think during PreInit still works).

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.

Posted

I seem to be failing to properly register my ModelRegistryEvent, as it seems it doesn't complain because that method never runs?

 

I've tried registering it with the forge event bus in both my Main, and ClientProxy and neither works...

 

...This is probably all wrong?

 

MinecraftForge.EVENT_BUS.register(new LoadModelEvent());

 

LoadModelEvent:

...

@SubscribeEvent
public void onModelRegistry(ModelRegistryEvent event)
{
     testItems.registerRenders();
}

 

TestItems:

...

public static void registerRenders() 
{
registerRender(testItem, 0, "Stage0");
registerRender(testItem, 1, "Stage1");
registerRender(testItem, 2, "Stage2");
}

public static void registerRender(Item item, int meta, String addon)
{	
ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName() + addon, "inventory"));

LogHelper.debug("I should be loading the json file for: " + item.getRegistryName() + addon + " and setting metadata: " + meta);
}

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

ModelRegistryEvent

is fired before preInit, so it needs to be handled by a static

@SubscribeEvent

method in a class annotated with

@Mod.EventBusSubscriber

.

 

You should also be registering all of your

IForgeRegistryEntry

implementations (e.g.

Item

,

Block

,

SoundEvent

) in response to

RegistryEvent.Register<T>

, where

T

is the registry's type.

 

You can read more about events here.

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.

Posted

MinecraftForge.EVENT_BUS.register(new LoadModelEvent());

 

When are you calling this?

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.

Posted

When are you calling this?

 

I was calling it during the preinit of my main class

public static void PreInit(FMLPreInitializationEvent PreEvent)
{
     MinecraftForge.EVENT_BUS.register(new LoadModelEvent());
}

 

I also tried (after reading through Choonster's link) making it static, and making that

 

public static void PreInit(FMLPreInitializationEvent PreEvent)
{
     MinecraftForge.EVENT_BUS.register(LoadModelEvent.class);
}

 

Which also didn't work. I then tried removing that, and using:

 

@Mod.EventBusSubscriber
public class LoadModelEvent 
{
     ...
}

 

Which runs, and gets a nullpointerexception because the items aren't loaded yet...

Attempting to load the items by registering them in the event too instead of normal fixes that, but then they get initialized as being from

minecraft instead of being from my MODID

 

Exception loading model for variant minecraft:testitemstage0#inventory for item "minecraft:testitem", normal location exception: 

 

Sorry, I am 100% thoroughly lost and confused.

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

Events that extend

FMLEvent

(e.g.

FMLPreInitializationEvent

) still need to be handled by instance

@Mod.EventHandler

methods in your

@Mod

class.

 

You should instantiate your

Item

s in a static initialiser and register them in response to

RegistryEvent.Register<Item>

. The same applies to all other

IForgeRegistryEntry

implementations.

 

You can see how I do this here and in the other classes in the

init

package.

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.

Posted

You can see how I do this here and in the other classes in the

init

package.

 

Registering my item this way, worked perfectly. I now have textures in the game, and can cycle between the different textures no problem.

 

Thank you all, so much.

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

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.