Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED] Rendering rainbow item

Recommended Posts

My mod has a set of tools and armour as the highest tier that should cycle through every hue value and overlay the colour onto the item texture. However, with my sword renderer, I end up with http://puu.sh/c1Q0q/42bf7e4465.png, http://puu.sh/c1QlN/fcdcb7dd54.png, http://puu.sh/c1Qwu/576c1ca1fa.png, http://puu.sh/c1QDU/1db230b12d.png and http://puu.sh/c1QOp/9e1b62746a.png  - the scaling is off (I messed around with that for a couple of hours), the colour doesn't blend properly except in the inventory (where it has an odd background), the item entity doesn't rotate to face the player (or spin at all with Fancy Graphics on) and the item is 2D.




package net.condorcraft110.stygian.render;

import java.awt.*;
import java.util.*;
import org.lwjgl.opengl.*;
import net.minecraft.item.*;
import net.minecraftforge.client.*;
import net.condorcraft110.stygian.core.*;
import net.minecraft.client.renderer.entity.*;

public class RenderElderSword implements IItemRenderer
private float hue = 0.0F;

public boolean handleRenderType(ItemStack stack, ItemRenderType type)
	return type != ItemRenderType.FIRST_PERSON_MAP && stack.getItem() == Stygian.elderSword;

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack stack, ItemRendererHelper helper)
	return type != ItemRenderType.FIRST_PERSON_MAP && helper == ItemRendererHelper.ENTITY_BOBBING && stack.getItem() == Stygian.eldserSword;

public void renderItem(ItemRenderType type, ItemStack stack, Object... data) // only sword for now
	Color color = Color.getHSBColor(hue += 0.01F, 1.0F, 1.0F);

	if(type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON || type == ItemRenderType.ENTITY)
		if(type != ItemRenderType.ENTITY)
			GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
			GL11.glTranslatef(-1.5F, -1.5F, 0.0F);

		GL11.glScalef(1.0F / 8.0F, 1.0F / 8.0F, 0.0F);

	RenderItem.getInstance().renderIcon(0, 0, stack.getIconIndex(), 16, 16);


		GL11.glColor4f((float)color.getRed() / 255, (float)color.getGreen() / 255, (float)color.getBlue() / 255, 0.5F);

		GL11.glVertex2i(15, 0);
		GL11.glVertex2i(15, 3);
		GL11.glVertex2i(16, 3);
		GL11.glVertex2i(16, 0);

		GL11.glVertex2i(14, 0);
		GL11.glVertex2i(14, 4);
		GL11.glVertex2i(15, 4);
		GL11.glVertex2i(15, 0);

		GL11.glVertex2i(13, 0);
		GL11.glVertex2i(13, 5);
		GL11.glVertex2i(14, 5);
		GL11.glVertex2i(14, 0);

		GL11.glVertex2i(12, 1);
		GL11.glVertex2i(12, 6);
		GL11.glVertex2i(13, 6);
		GL11.glVertex2i(13, 1);

		GL11.glVertex2i(11, 2);
		GL11.glVertex2i(11, 7);
		GL11.glVertex2i(12, 7);
		GL11.glVertex2i(12, 2);

		GL11.glVertex2i(10, 3);
		GL11.glVertex2i(10, ;
		GL11.glVertex2i(11, ;
		GL11.glVertex2i(11, 3);

		GL11.glVertex2i(9, 4);
		GL11.glVertex2i(9, 9);
		GL11.glVertex2i(10, 9);
		GL11.glVertex2i(10, 4);

		GL11.glVertex2i(8, 5);
		GL11.glVertex2i(8, 10);
		GL11.glVertex2i(9, 10);
		GL11.glVertex2i(9, 5);

		GL11.glVertex2i(7, 6);
		GL11.glVertex2i(7, 13);
		GL11.glVertex2i(8, 13);
		GL11.glVertex2i(8, 6);

		GL11.glVertex2i(6, 7);
		GL11.glVertex2i(6, 13);
		GL11.glVertex2i(7, 13);
		GL11.glVertex2i(7, 7);

		GL11.glVertex2i(2, 6);
		GL11.glVertex2i(2, ;
		GL11.glVertex2i(3, ;
		GL11.glVertex2i(3, 6);

		GL11.glVertex2i(3, 6);
		GL11.glVertex2i(3, 10);
		GL11.glVertex2i(4, 10);
		GL11.glVertex2i(4, 6);

		GL11.glVertex2i(4, 7);
		GL11.glVertex2i(4, 11);
		GL11.glVertex2i(5, 11);
		GL11.glVertex2i(5, 7);

		GL11.glVertex2i(5, ;
		GL11.glVertex2i(5, 12);
		GL11.glVertex2i(6, 12);
		GL11.glVertex2i(6, ;

		GL11.glVertex2i(8, 11);
		GL11.glVertex2i(8, 14);
		GL11.glVertex2i(9, 14);
		GL11.glVertex2i(9, 11);

		GL11.glVertex2i(9, 12);
		GL11.glVertex2i(9, 14);
		GL11.glVertex2i(10, 14);
		GL11.glVertex2i(10, 12);

		GL11.glVertex2i(0, 13);
		GL11.glVertex2i(0, 16);
		GL11.glVertex2i(2, 16);
		GL11.glVertex2i(2, 13);

		GL11.glVertex2i(2, 14);
		GL11.glVertex2i(2, 16);
		GL11.glVertex2i(3, 16);
		GL11.glVertex2i(3, 14);




Can anyone please tell me what I'm doing wrong and how to fix it?

Link to post
Share on other sites

Can't you just create a different png with an animation of all colors. Like the portal or fire. And then use that picture as an overlay on the sword.


I could, but there are 256 different colours. That would be a lot more difficult to render, anyway, as I would still have the scaling issues but I would also have to switch textures and render them with blending.

Link to post
Share on other sites

private static void renderIcon(IIcon icon) {

	ItemRenderer.renderItemIn2D(Tessellator.instance, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(), 255, 255, 0.0625F);


That should render the 3D item.


I'm not an OpenGL wizard, but what I would do is:



-Have 2 icons, the part that doesn't change color and the one that does

-In the render class, keep a static integer/float/double

-On every update, increment it by whatever

-Render the part that doesn't change color

-Push matrix

-Use some kind of OpenGL call that alters the colors that it renders

-Render the part that does change color

-Pop matrix


*This is all tentative and untested*




Link to post
Share on other sites



This link might help you understand how to use the IItemRenderer to achieve the things you want. 


Look at the Item Rendering sections.


I think TLHPoE's suggestions are good;

esp. you could make the image for your coloured parts white (or grayscale), then before you draw it change the colour (using glColor4f like you already do)


You don't need Blend unless you want the coloured parts to be partially transparent, but if you try to draw two textures exactly on top of each other you will get the weird 'texture fighting stripes" in your first picture.  Try splitting your icon into two non-overlapping parts instead like TLHPoE suggested.



Link to post
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.

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.

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.