skullywag Posted January 29, 2014 Share Posted January 29, 2014 Hi all, Ive got a meta item with all 16 slots used and im trying to colour said item using 1 texture. First off ive created the texture and desaturated it (I assume this is correct, im no artist) Now ive gone the IItemRenderer renderer route as after my last issue ive become quite familiar with it and even some GL stuff. So my plan was to use"GL11.glColor4f(float,float,float,float)" but I have hex code format from vanilla dyes and that takes RGB, so these are the numbers im playing with (and associated colours) public static String[] dyeItemNames = new String[] {"black", "red", "green", "brown", "blue", "purple", "cyan", "silver", "gray", "pink", "lime", "yellow", "light_blue", "magenta", "orange", "white"}; public static int[] dyeColors = new int[] {1973019, 11743532, 3887386, 5320730, 2437522, 8073150, 2651799, 11250603, 4408131, 14188952, 4312372, 14602026, 6719955, 12801229, 15435844, 15790320}; Is there some clever way of converting between the 2 or am i being silly and there is a simpler way of doing this? Quote Link to comment Share on other sites More sharing options...
Draco18s Posted January 29, 2014 Share Posted January 29, 2014 Is there some clever way of converting between the 2 or am i being silly and there is a simpler way of doing this? Yes. int hex = 0x123456; int r = (hex & 0xFF0000) >> 16; int g = (hex & 0xFF00) >> 8; int b = (hex & 0xFF); (If you need floats, rather than ints, divide by 255) Quote 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 More sharing options...
skullywag Posted January 29, 2014 Author Share Posted January 29, 2014 hmm think I might be doing something wrong here, first of minecaft uses decimals not hexadecimals (my bad) so using: Color color = new Color(colorStr); int red = color.getRed(); int green = color.getGreen(); int blue = color.getBlue(); return color; obviously works perfectly fine in this case. So my problem now is im getting no image appearing in inventory. Now im not sure if this is a translate problem (its off the screen or soemthing..) or something else ive missed. heres the relevant code from my item renderer: @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { switch (type) { case ENTITY: case EQUIPPED: case EQUIPPED_FIRST_PERSON: case INVENTORY: return true; default: return false; } } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { switch (type) { case ENTITY: { return (helper == ItemRendererHelper.ENTITY_BOBBING || helper == ItemRendererHelper.ENTITY_ROTATION || helper == ItemRendererHelper.BLOCK_3D); } case EQUIPPED: { return (helper == ItemRendererHelper.BLOCK_3D || helper == ItemRendererHelper.EQUIPPED_BLOCK); } case EQUIPPED_FIRST_PERSON: { return helper == ItemRendererHelper.EQUIPPED_BLOCK; } case INVENTORY: { return helper == ItemRendererHelper.INVENTORY_BLOCK; } default: { return false; } } } @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { int itemMeta = item.getItemDamage(); int itemColour = dyeColors[itemMeta]; Color rgb = hex2Rgb(itemColour); Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("mymod:textures/items/mypic.png")); GL11.glPushMatrix(); System.out.println(rgb.getRed()/255); GL11.glColor4f(rgb.getRed()/255, rgb.getBlue()/255, rgb.getGreen()/255, 0); float Scale = 0.5F; switch (type) { case ENTITY: { break; } case EQUIPPED_FIRST_PERSON: { break; } case FIRST_PERSON_MAP: { break; } case EQUIPPED: { break; } case INVENTORY: { Scale = 0.5F; GL11.glTranslatef(-0.5F, -0.5F, -0.5F); GL11.glRotatef(90, 1F, 0F, 0F); break; } default: GL11.glRotatef(90, 1F, 0F, 0F); break; } GL11.glScalef(Scale, Scale, Scale); GL11.glPopMatrix(); } Now that to me should work....but im betting as its me ive missed something bloody obvious. Quote Link to comment Share on other sites More sharing options...
Draco18s Posted January 29, 2014 Share Posted January 29, 2014 Well you've done a bunch of GL rotation, color, and translation stuff. But you haven't drawn anything. Quote 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 More sharing options...
skullywag Posted January 29, 2014 Author Share Posted January 29, 2014 ok think ive stepped into yet another part of minecraft modding i dont fully get. So normally I have a model to render which is the line I now realise im missing (derp). How does one go about rendering an "icon" for an item only item (only going to show in inventory, hand, floor), my texture in the code above is the icon itself (imagine the vanilla apple item texture, desaturated) does the glColor4f apply the rgb to the whole image or just the "grey" parts, or do I have to do something else. The custom 2d item tutorial doesnt seem to give me the info mm missing for what im trying to do. Quote Link to comment Share on other sites More sharing options...
Draco18s Posted January 29, 2014 Share Posted January 29, 2014 You mean like signs? Generally that's easy. It's getting minecraft to not do that that's hard. Quote 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 More sharing options...
skullywag Posted January 29, 2014 Author Share Posted January 29, 2014 basically I have 16 meta items on 1 item ID, I want the 16 dye colours of vanilla minecraft applied to each of them but I dont want to make 16 textures (admittedly that would be easier, but I dont like doing things the easy way if you havent noticed). So I have 1 texture desaturated and I am passing the RGB to the Item renderer (ive confirmed this all works) my issue is simply how using GL do i "render" this and is using glColor4f correct for what im trying to do, from what ive read it seems to be. I believe grass and vines from vanilla do this with biome colours (the textures are grey) its just not obvious from those items how I can do it with custom items and IitemRenderer Quote Link to comment Share on other sites More sharing options...
Draco18s Posted January 29, 2014 Share Posted January 29, 2014 Ditch your IItemRenderer, you don't need it. Implement public int getColorFromItemStack(ItemStack par1ItemStack, int pass) { } In your item class. Done. Quote 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 More sharing options...
GotoLink Posted January 29, 2014 Share Posted January 29, 2014 You might want to use ItemRenderer.renderItemIn2D Quote Link to comment Share on other sites More sharing options...
skullywag Posted January 29, 2014 Author Share Posted January 29, 2014 So the method provided by Draco is almost perfect (i learned something new...I looked through the itemarmour class but for some reason this didnt jump out even though it has all the keywords...) the only issue is it seems no transparency, even though this isnt critical it would be nice. (the texture is at 90% transparency) Can I achieve it with this function or would I then need to go down the GL render route? Quote Link to comment Share on other sites More sharing options...
Draco18s Posted January 29, 2014 Share Posted January 29, 2014 You would need to GL it. Unfortunately. Quote 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 More sharing options...
skullywag Posted January 29, 2014 Author Share Posted January 29, 2014 Booooo..that is all Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.