Jump to content

[SOLVED] Getting color for ItemStack in crafting


yooksi

Recommended Posts

After a lot of experimenting I've learned the basics of setting up item subtypes and making them display in different colours via ColorHandlers. This however does not work for items that are displayed in the crafting output field when crafting (they are displayed with their default non-coloured textures). The only way I know how to fix this is to make an item model and texture file for every colour I want (not to mention registering separate classes). This will bring a lot of redundant files, is there a way around this?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

Can you please explain further? What do you expect to get as a crafting result? And show relevant code, we need it to help.

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

Can you please explain further? What do you expect to get as a crafting result? And show relevant code, we need it to help.

 

I want the ItemStack that is the result of the crafting (displayed in the crafting output slot) to be coloured, much the same way as it would be after it leaves the crafting output slot - via the use of

IItemColor#getColorFromItemstack

. The mentioned method works for all cases except when the item is residing in the crafting output slot, then a default texture is used (from metadata).

 

So let's say I've got a test item that has a model file and a custom texture all set up. I register a ColorHandler for it, and return

Color.RED

from

getColorFromItemstack

. The item is properly colored red in my inventory and in the creative tabs. Everything works fine until I decide to craft that item, in which case the item is displayed un-colored (using the default texture, without custom color applied to it) in the crafting output slot. When removed, the item is rendered normally again.

 

In order to fix this I would need to abandon the subtype system of handling this item and split it up into separate items (one for each color), each with it's own model and texture file. My question is, is there a way of forcing the item in the crafting output slot to be rendered with a color applied to it (just like we do with

getColorFromItemstack

) WITHOUT resorting to dedicating separate item classes, model and texture files? Hope I made more sense this time =)

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

The colour returned by

IItemColor

is always used to render the item's model, regardless of where it is. You can see this by crafting a leather helmet with dye, the output item will be rendered with the appropriate colour.

 

Post your

Item

and

IItemColor

.

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.

Link to comment
Share on other sites

I suspect the problem is that the color is coming from NBT and he's using the onCrafted to apply the NBT, rather than in the recipe output declaration.

 

Or something similar.

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

The colour returned by

IItemColor

is always used to render the item's model, regardless of where it is. You can see this by crafting a leather helmet with dye, the output item will be rendered with the appropriate colour.

 

Post your

Item

and

IItemColor

.

 

Ah, you are right. Now that I checked it again

getColorFromItemstack

does get properly called even when the item is in the crafting output grid. I must have been setting my debug breakpoints in wrong places, because I could have sworn it was never called.

 

However, my next problem is that because I store the colour values (or to be more precise dyeColor metadata values) in item NBT, I am unable to retrieve them when crafting because the item did not have a chance to initialize it's NBTTagCompound. I do the initialization when the ItemCraftedEvent is fired. I would like to do the initialization in getSubItems but unfortunately that is not called until after the item has been crafted (pulled out of the crafting output slot). Any idea on how I should handle this?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

I suspect the problem is that the color is coming from NBT and he's using the onCrafted to apply the NBT, rather than in the recipe output declaration.

 

Or something similar.

 

Spot on, that's exactly what I am doing.

When should create a new NBTTagCompound for the item to make this work?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

The colour returned by

IItemColor

is always used to render the item's model, regardless of where it is. You can see this by crafting a leather helmet with dye, the output item will be rendered with the appropriate colour.

 

Post your

Item

and

IItemColor

.

Ah, you are right. Now that I checked it again

getColorFromItemstack

does get properly called even when the item is in the crafting output grid. I must have been setting my debug breakpoints in wrong places, because I could have sworn it was never called.

 

However, my next problem is that because I store the colour values (or to be more precise dyeColor metadata values) in item NBT, I am unable to retrieve them when crafting because the item did not have a chance to initialize it's NBTTagCompound. I do the initialization when the ItemCraftedEvent is fired. I would like to do the initialization in getSubItems but unfortunately that is not called until after the item has been crafted (pulled out of the crafting output slot). Any idea on how I should handle this?

 

Set the NBT from

IRecipe#getCraftingResult

instead of

ItemCraftedEvent

.

 

Events should generally only be used when dealing with things from vanilla or other mods, overriding the appropriate method should be preferred.

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.

Link to comment
Share on other sites

Set the NBT from

IRecipe#getCraftingResult

instead of

ItemCraftedEvent

.

 

Events should generally only be used when dealing with things from vanilla or other mods, overriding the appropriate method should be preferred.

 

I am guessing that I have to declare my recipe as an IRecipe and then make it override

IRecipe#getCraftingResult

, correct? If so, I don't know how to do this, any examples?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

Set the NBT from

IRecipe#getCraftingResult

instead of

ItemCraftedEvent

.

 

Events should generally only be used when dealing with things from vanilla or other mods, overriding the appropriate method should be preferred.

 

I am guessing that I have to declare my recipe as an IRecipe and then make it override

IRecipe#getCraftingResult

, correct? If so, I don't know how to do this, any examples?

 

You'll probably want to create a class that extends an existing implementation of

IRecipe

like

ShapedOreRecipe

and then override

IRecipe#getCraftingResult

to call the super method, add the NBT and return the

ItemStack

.

 

Use

GameRegistry#addRecipe(IRecipe)

to add an instance of this recipe class.

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.

Link to comment
Share on other sites

 

You'll probably want to create a class that extends an existing implementation of

IRecipe

like

ShapedOreRecipe

and then override

IRecipe#getCraftingResult

to call the super method, add the NBT and return the

ItemStack

.

 

Use

GameRegistry#addRecipe(IRecipe)

to add an instance of this recipe class.

 

After taking a look at

ShapedOreRecipe

and

RecipeFirework

, I realized that setting up this class manually is going to be a pain in the ass, and for some reason I don't feel comfortable extending

ShapedOreRecipe

out of pure convenience in the moment. If it gets changed and becomes incompatible with my recipes, I will have to rewrite them. Makes more sense to set it up manually, right?

 

EDIT: I figured out that

ShapedOreRecipe

is actually a Forge implemented class, and in order to have a custom recipe class I need to register it and all that. Think I will stick with the native Forge class for now.

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

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.