Jump to content

Seperate Icon Textures on metadata block[Solved]


Lua

Recommended Posts

Hi, I've created a metadata block with 6 subtypes(0-5). The block is a tile entity with a special renderer and it uses the same model but just rotated a bit. However, I want the icon for the 0-2 blocks to be one icon and the 3-5 blocks be another. Obviously, its got to with getIcon method but I can't get them to be different and I thought this would be a really simple task.

 

Heres the relevant code:

 

 

@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister iconRegister)
{
this.blockIcon = iconRegister.registerIcon(Arcticraft.MOD_ID + ":icicle_ud");
this.icicle = iconRegister.registerIcon(Arcticraft.MOD_ID + ":icicle");
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta)
{
if(meta == 3 || meta == 4 || meta == 5){
return this.blockIcon;
}
else{
return this.icicle;
}
}

Link to comment
Share on other sites

Show your TESR.

 

package net.arcticraft.tileentity.renderers;

import net.arcticraft.block.BlockIcicle;
import net.arcticraft.main.Arcticraft;
import net.arcticraft.tileentity.TileEntityIcicle;
import net.arcticraft.tileentity.models.ModelBlockIcicle;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.FMLClientHandler;

public class TileEntityIcicleRender extends TileEntitySpecialRenderer{

private ModelBlockIcicle model;

public TileEntityIcicleRender(){
	model = new ModelBlockIcicle();
}

public void renderAModelAt(TileEntityIcicle tileEntity, double x, double y, double z, float f)
{
	TileEntityIcicle icicle = (TileEntityIcicle) tileEntity;
	icicle = (TileEntityIcicle) tileEntity.getWorldObj().getTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);

	int meta = 0;
	if(tileEntity.getWorldObj() != null)
	{
		meta = tileEntity.getBlockMetadata();
		icicle.rotation = meta;
	}
	FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation(Arcticraft.MOD_ID, "textures/blocks/modeled_blocks/icicle.png"));
	GL11.glPushMatrix();
	GL11.glEnable(GL11.GL_NORMALIZE);
	GL11.glEnable(GL11.GL_BLEND);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
	GL11.glScalef(1.0F, -1F, -1F);
	GL11.glRotatef(icicle.rotation * 90, 0.0F, 1.0F, 0.0F);
	if(icicle.type == 0 || icicle.type == 3)
	{
		// large
		GL11.glScalef(2.0F, 1.0F, 1F);
	}
	else if(icicle.type == 1 || icicle.type == 4)
	{
		// regular
		GL11.glScalef(1.5F, 1F, 1F);
	}
	else if(icicle.type == 2 || icicle.type == 5)
	{
		// small
		GL11.glScalef(1.0F, 1F, 1F);
	}
	if(icicle.upsideDown){
		GL11.glRotatef(180, 1, 0, 0);
		GL11.glTranslatef(0, (float) -1.5F, 0);
	}
	model.renderAll();
	GL11.glPopMatrix();
}

@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float par8)
{
	this.renderAModelAt((TileEntityIcicle) tileEntity, x, y, z, par8);
}

}

Link to comment
Share on other sites

In that TESR code you bind a specific texture. That is also where you need to have the check for which texture to bind. The icons you have are irrelevant.

 

Noooo, the texture for the actual blocks should be the same, I just want the icons to differ.

Link to comment
Share on other sites

Yeah, you'll need to make changes in your ItemRenderer class. If you don't have one yet, there are plenty of tutorials. Once you have that, you can change the way it renders based on metadata using the itemstack in renderItem().

Okay, thank you.

Link to comment
Share on other sites

Ok so I tried making a IItemRenderer and I came up with this and yes I registered it in the clientProxy.

 

package net.arcticraft.item.render;

import net.arcticraft.main.Arcticraft;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;

public class ItemIcicleRender implements IItemRenderer{

public ItemIcicleRender(){}

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type)
{
	return true;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
{
	return true;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
{
	System.out.println(item.getItemDamage());
	if(item.getItemDamage() == 0 && item.getItemDamage() == 1 && item.getItemDamage() == 2)
	{
		item.getItem().setTextureName(Arcticraft.MOD_ID + ":icicle");
	}
	else
	{
		item.getItem().setTextureName(Arcticraft.MOD_ID + ":icicle_ud");
	}
}

}

 

But they just come up as the missing texture texture(the purple black squares one). Is this because I commented out the getIcon and registerIcon in the block method? Probably, but I shouldnt need em should since its a tileentity w/ model and it uses the same texture.

Link to comment
Share on other sites

You should register those icons into the 'registerIcons' and Render them on 'renderItem'.

Just setting texture name there should not work.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

You should register those icons into the 'registerIcons' and Render them on 'renderItem'.

Just setting texture name there should not work.

 

In the item class I did register em with and now theyre just invisible.

 

 @SideOnly(Side.CLIENT)
   
public static final String[] iciclesTextures = new String[]{"icicle", "icicle", "icicle", "icicle_ud","icicle_ud", "icicle_ud"};
@SideOnly(Side.CLIENT)
private IIcon[] texture;

public void registerIcons(IIconRegister iconRegister)
    {
        this.texture = new IIcon[iciclesTextures.length];

        for (int i = 0; i < iciclesTextures.length; ++i)
        {
            this.texture[i] = iconRegister.registerIcon(Arcticraft.MOD_ID + ":" + iciclesTextures[i]);
        }
    }

 

Im not quite sure how I would just render em on RenderItem

Link to comment
Share on other sites

..Wait, do you only changes the texture via item metadata? Then ItemRenderer is not appropriate.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Then just use Item#getIconFromDamage(int damage).

EDIT: Wait, you are just using metadata for tileentity! Then you should bind your texture yourself, in the TileEntitySpecialRenderer!

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Then just use Item#getIconFromDamage(int damage).

EDIT: Wait, you are just using metadata for tileentity! Then you should bind your texture yourself, in the TileEntitySpecialRenderer!

 

I bind the texture to the model in TESR but I just wanted the icons to be different and now they are. getIconFromDamage was exactly what I needed.

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.