Jump to content

1.12 Custom resource location


vsbmeza

Recommended Posts

Hello,

 

I'm porting my mod over to 1.12 and I've bumped into a problem that I can't wrap my head around.

Due to the functionality of the mod, the texture names don't correlate to the item name. Instead, they correlate to an internal property of the items. That is all dealt with in the item.getModelLocation().

 

In the example, I have 2 books. One configured to be yellow, the other to be blue.

The println in the code tells me that the unlocalized name and the resource location match up perfectly, and if I change the model location up to an invalid string, it actually can't find the resources. So I know that I have the right values.

 

However, after this runs, both of my books become blue, which was the last texture to load. What am I missing?

 

	@SubscribeEvent
	public static void registerModels(ModelRegistryEvent event) {
		for (final AchievementBookItem item : l2.items()) {

			System.out.println(String.format("Setting %s to %s", item.getUnlocalizedName(), item.getModelLocation().toString()));

			ModelLoader.setCustomModelResourceLocation(item, 0, item.getModelLocation());
			ModelBakery.registerItemVariants(item, item.getModelLocation());
			ModelLoader.setCustomMeshDefinition(item, new ItemMashes(item));
		}

	}

 

Link to comment
Share on other sites

What's happening, is that both the items get the same resource location.

 

The output is:

[STDOUT]: Setting item.achievementbooksbook_demo to achievementbooks:book-yellow#inventory
[STDOUT]: Setting item.achievementbooksbook_demo2 to achievementbooks:book-orange#inventory

 

yet both are now orange (I've changed the colour to verify my theory)

 

This is the new code:

	@SubscribeEvent
	public static void registerItems(final RegistryEvent.Register<Item> event) {
		l2.init();
		registry = event.getRegistry();

		for (final AchievementBookItem item : l2.items()) {
			registry.register(item);
		}
	}

	@SubscribeEvent
	public static void registerModels(ModelRegistryEvent event) {
		for (final AchievementBookItem item : l2.items()) {

			System.out.println(String.format("Setting %s to %s", item.getUnlocalizedName(), item.getModelLocation().toString()));

//			ModelLoader.setCustomModelResourceLocation(item, 0, item.getModelLocation());
			ModelBakery.registerItemVariants(item, item.getModelLocation());
			ModelLoader.setCustomMeshDefinition(item, new ItemMashes(item));
		}

	}

 

Same happens if I leave the setCustomModel* and remove the variants.

If I don't have one of them, it reverts to the item name resolver.

 

This is the resource location:

	public ModelResourceLocation getModelLocation() {
		return new ModelResourceLocation(MODID + ":book-" + book.colour(), "inventory");
	}

 

Link to comment
Share on other sites

Here they are:

 

Again: it sort of works. All the items get the texture of the last setCustomModelResourceLocation call. So they are mapped properly, textures load. But for some reason, the same texture is mapped to _all_ items

 

Orange:

{
	"parent": "achievementbooks:item/book",
	"textures": {
		"layer0": "achievementbooks:items/book-orange"
	}
}

 

Yellow:

{
	"parent": "achievementbooks:item/book",
	"textures": {
		"layer0": "achievementbooks:items/book-yellow"
	}
}

 

p.s.: I am going to eventually refactor the entire thing to variants and colours, but I just wanted to release a quick update to the people waiting for the 1.12 update ...

 

Screen Shot 2017-07-16 at 16.40.28.png

Edited by vsbmeza
added p.s.
Link to comment
Share on other sites

Book model:

{
	"parent": "item/book"
}

 

Updated code:

	@SubscribeEvent
	public static void registerItems(final RegistryEvent.Register<Item> event) {
		l2.init();
		registry = event.getRegistry();

		for (final AchievementBookItem item : l2.items()) {
			registry.register(item);
		}
	}

	@SubscribeEvent
	public static void registerModels(ModelRegistryEvent event) {
		for (final AchievementBookItem item : l2.items()) {

			System.out.println(String.format("Setting %s to %s", item.getUnlocalizedName(), item.getModelLocation().toString()));

			ModelLoader.setCustomModelResourceLocation(item, 0, item.getModelLocation());
			ModelLoader.setCustomMeshDefinition(item, new ItemMashes(item));
		}

	}

 

Link to comment
Share on other sites

And I'm telling you the 3rd time, that the texture gets set properly, even if I change the colours in the config.

 

The thing that doesn't work is that all my items get the same texture - the model that I set as the last in the loop.

Link to comment
Share on other sites

So it turns out that Forge's RegistryDelegate doesn't populate their name parameter properly and when you have the same class in different implementations as the item, it disregards the differences.

 

Basically what's been happening is that every single item custom model I register ends up setting the same "delegate" becaue their internal equals function only deals with the name attribute, not the actual object reference.

Link to comment
Share on other sites

Awful, awful, terrible, no good, very bad things.

But we can't tell, because you haven't posted all of the code involved.

 

Liiiike your AchievementBookItem class where you declare getModelLocation()

Edited by Draco18s

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

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.