Jump to content

[1.7.10] Get item and color from tool material...


Recommended Posts

Posted

Hello everybody,

I'm here with 2 interesting questions:

-Can we get material's item (or itemstack), another way than using

material.getRepairItemStack()

?

--Why?

--Because i found that there's no single mod that cares about specifiyng repair item stack in tool material. And when recipes for mod items are generated, recipes for items based on modded tool materials have no recipe...

-How can i get tool material's color?

--Rgb or hex, both will work.

--For example, wood color is 110:65:43 (r:g:b) and iron is 153:153:153 (r:g:b), but these i found manually...

--I have not tried anything yet, i'm just asking about it, if anybody has done it already or knows approximative way to do it.

--Note: color option is client only, so i can "scan" textures...

 

Thanks for help!

If you have any questions - just ask!

Posted

- There is no way to get the color, so you have to specify it yourself.

I was meaning "repair" item, item which is used to make/repair tools. For example, for

ToolMaterial.WOOD

it's planks, for

ToolMaterial.IRON

it's iron ingot...

- There is no way to get the color, so you have to specify it yourself.

So there's no way i can "scan" texture (of let's say repair item, which i found above) and determine "average" color??? (Yes, this will not work if item is special rendered)...

Posted

I was meaning "repair" item, item which is used to make/repair tools. For example, for

ToolMaterial.WOOD

it's planks, for

ToolMaterial.IRON

it's iron ingot...

That is what getRepairItemStack does...?

I'm still using

material.getRepairItemStack()

, but this only works for vanilla items, as

I found that there's no single mod that cares about specifiyng repair item stack in tool material.

So what should i do in this case???

My guess is only to scan over all items, find tool instances with this material and apply pattern recipe "cutting" to determine item used...

 

So there's no way i can "scan" texture (of let's say repair item, which i found above) and determine "average" color??? (Yes, this will not work if item is special rendered)...

Sure, you could do that.

Ok, so it's possible...

I'm not experienced with graphics or open gl, so how can i proceed when i get texture file location? I heard of java image classes, is that what i can use?

Posted

Then you should not support those mods and if people complain send them to the mod authors. It's not your job to fix that :P

Ok, got it... I'll report to all of them one by one :D ...

Yes, the Java 2d image classes should be fine.

Wait, but isn't texture sheet generated from iicons?

Fo items with single layer, i can just get their texture location and that's it (this is probably like 99.9% of cases for material items), fo colored items with color mutiplier method, i can apply this multiplier to medium color, but what for items with multiple layers? They are generated from multiple iicons, and where i can find them is on generated texture sheet... Or should i consider not coding them???

Posted

For multiple layers... idk, I am not sure that is doable easily. And then yes, you can use OpenGL to get the actual texture data and then alter that with java 2d APIs.

Oh, ok... But as i said, it's probably like 0.001% of cases for items that are used in crafting that have multiple render passes... Because it's kinda useless, i guess...

But anyways, thanks for help. I'll see what i can do...

Thanks!

Posted

Ok, so:

-I found that TextureUtil.readImageData does what i need: reads pixels in to int array.

-I created dummy testing tool material with repair item stack specified:

EnumHelper.addToolMaterial("BLAZE", 3, 900, 10, 8, 9).setRepairItem(new ItemStack(Items.blaze_rod));

-I tried using following code: https://gist.github.com/elix-x/61525e6fc172f0b7e6c5

-And it fails on:

[20:19:16] [Client thread/ERROR] [CoB Materials Manager]: Caught exception while parsing texture to get color: 
java.io.FileNotFoundException: minecraft:blaze_rod
at net.minecraft.client.resources.FallbackResourceManager.getResource(FallbackResourceManager.java:65) ~[FallbackResourceManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:67) ~[simpleReloadableResourceManager.class:?]
at net.minecraft.client.renderer.texture.TextureUtil.readImageData(TextureUtil.java:347) ~[TextureUtil.class:?]
at code.elix_x.coremods.colourfulblocks.material.ExtensionsManager.recognizeColor(ExtensionsManager.java:198) [ExtensionsManager.class:?]
at code.elix_x.coremods.colourfulblocks.material.ExtensionsManager.initGenMaterials(ExtensionsManager.java:111) [ExtensionsManager.class:?]
at code.elix_x.coremods.colourfulblocks.material.ExtensionsManager.initDefaultMaterials(ExtensionsManager.java:78) [ExtensionsManager.class:?]
at code.elix_x.coremods.colourfulblocks.material.ExtensionsManager.init(ExtensionsManager.java:65) [ExtensionsManager.class:?]
at code.elix_x.coremods.colourfulblocks.ColourfulBlocksBase.init(ColourfulBlocksBase.java:141) [ColourfulBlocksBase.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532) [FMLModContainer.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212) [LoadController.class:?]
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190) [LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119) [LoadController.class:?]
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:737) [Loader.class:?]
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:311) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:597) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:942) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]

 

Any ideas?

Posted

Note: Some tool materials don't have a repair stack specified for a reason.

I know that in my artifacts mod my armor items have a tool material that is used for the initiation of the item class, but it's not actually used in any meaningful way because

1) the durability data (etc) is all handled by nbt, including effective material

2) the repair item is based off that nbt data as well. Iron items are repaired using a special item crafted with an iron ingot to make the item actually used by the anvil.

 

Other mods might do other things, such as materials that CANNOT be repaired.

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

The resource defining the item icons is not a real resource location that you can just load like that. You have to extract the texture from the big texture sheet.

I did not take it from big sheet, but:

-Using reflection i get iconString value, which is basically texture location with modid:file. https://gist.github.com/elix-x/61525e6fc172f0b7e6c5#file-colorfromtoolmaterial-L16'>https://gist.github.com/elix-x/61525e6fc172f0b7e6c5#file-colorfromtoolmaterial-L16

-Then i give it to ResourceLocation: https://gist.github.com/elix-x/61525e6fc172f0b7e6c5#file-colorfromtoolmaterial-L18'>https://gist.github.com/elix-x/61525e6fc172f0b7e6c5#file-colorfromtoolmaterial-L18

-And it should work...

 

EDIT: I think i have to do some manipulations before feeding texture name to resource location - add

items/

after

:

...

 

EDIT 2: OMG!!! It works!!! Kinda of...

Code was changed to this: https://gist.github.com/elix-x/61525e6fc172f0b7e6c5

For blaze rod, it gave me

39:26:5

which is this color... What does not seem to be correct... I'll try with something else...

 

EDIT 3: Further testing results:

Blaze rod: 39:26:5 - does not seems to be correct.

Ender pearl: 10:46:40 - seems to be correct.

Brick: 59:29:20 - does not seems to be correct at all.

Nether star: 54:63:58 - seems mostly correct.

Bone: 34:34:31 - seems partially correct.

Coal: 8:8:8 - correct.

So what do you think about it??? It seems mostly correct, how ever, some times it does not give correct value (brick result for example)...

 

EDIT 4: Improved code to support blocks: https://gist.github.com/elix-x/61525e6fc172f0b7e6c5

Some block testing results:

Coal block: 18:18:18 - correct.

Lapis block: 38:67:137 - mostly correct.

Redstone block: 171:27:9 - mostly correct.

Iron block: 219:219:219 - mostly correct.

Gold block: 249:236:78 - mostly correct.

Diamond block: 97:219:213 - mostly correct.

Emerald block: 81:217:117 - mostly correct.

It did pretty good job with blocks, at least better then with items... Do you think that on items texture there may be spots with low color values, but also with low transparency? I'm already ignoring transparent pixels, but something else shifts color a bit to darker one...

 

Note: Some tool materials don't have a repair stack specified for a reason.

I know that in my artifacts mod my armor items have a tool material that is used for the initiation of the item class, but it's not actually used in any meaningful way because

1) the durability data (etc) is all handled by nbt, including effective material

2) the repair item is based off that nbt data as well. Iron items are repaired using a special item crafted with an iron ingot to make the item actually used by the anvil.

 

Other mods might do other things, such as materials that CANNOT be repaired.

That's true...

So how do i do in this case???

(PS: Item of tool material is needed not for repairing, but for creation of new type of tool, if we can even call it a tool)...

Posted

Note: Some tool materials don't have a repair stack specified for a reason.

I know that in my artifacts mod my armor items have a tool material that is used for the initiation of the item class, but it's not actually used in any meaningful way because

1) the durability data (etc) is all handled by nbt, including effective material

2) the repair item is based off that nbt data as well. Iron items are repaired using a special item crafted with an iron ingot to make the item actually used by the anvil.

 

Other mods might do other things, such as materials that CANNOT be repaired.

That's true...

So how do i do in this case???

(PS: Item of tool material is needed not for repairing, but for creation of new type of tool, if we can even call it a tool)...

 

Not just tools, but armor as well.

In any case, your best bet is to simply use the method vanilla provides, and then if a mod doesn't work properly with it, you file a bug report with that mod to properly use the function.

 

Then if the material is not supposed to be repairable, if the user is using a texture pack that alters the colors or locations of pixels, or any other variety of strange things, you don't get weird results.

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

Not just tools, but armor as well.

Right, but i don't care about armor materials at the moment...

In any case, your best bet is to simply use the method vanilla provides, and then if a mod doesn't work properly with it, you file a bug report with that mod to properly use the function.

You mean like if it returns invalid stack? Then yes, this must be reported...

Then if the material is not supposed to be repairable, if the user is using a texture pack that alters the colors or locations of pixels, or any other variety of strange things, you don't get weird results.

Weird results for texture? They will be based on texture pack and higher is definition, exactlier is color detection.

 

But still, what about materials without repair item stack specified (Not reparable or whatever...)?

I'm not only using this item for color detection, but also for crafting recipe...

Which means that when my mod will generate tools for new tool materials, these tools will be uncraftable...

Even, though, user can change crafting item (and even recipe) at any time, it would be better if mod was good enough to auto detect crafting material, so that users don't spend hours trying to configure crafting material and color manually for each from-modded-tool-material-generated-item...

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.