Jump to content

Recommended Posts

Posted

Hey guys,

 

I'm having issues texturing some of the ItemBlocks for my Tile Entites. All my Tile Entities are simply for model renders, nothing fancy.

 

Most of them are just a simple one, and work. However, I have a few cases where I have four different textures for the same render, changed based on meta. These are where I'm having the issue - I'm trying to set a different texture for each of the four ItemBlocks which actually show in creative, but it's only registering the first one (for meta 0). I know they actually work, because they place the correctly textured model in-game.

 

Here's my current Block code:

package co.uk.silvania.roads.tileentities.blocks;

import java.util.List;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import co.uk.silvania.roads.Roads;
import co.uk.silvania.roads.tileentities.entities.TileEntityTrafficLightEntity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class TileEntityTrafficLightBlock extends BlockContainer {

    public TileEntityTrafficLightBlock(int id) {
        super(id, Material.iron);
        this.setHardness(1.0F);
        this.setCreativeTab(Roads.tabRoads);
        this.setLightOpacity(0);
        this.setBlockBounds(0.35F, 0.0F, 0.35F, 0.65F, 0.8F, 0.65F);
    }

    @Override
    public TileEntity createNewTileEntity(World world) {
        return new TileEntityTrafficLightEntity();
    }

    @Override
    public int getRenderType() {
        return -1;
    }

    @Override
    public boolean isOpaqueCube() {
        return false;
    }

    @Override
    public boolean renderAsNormalBlock() {
        return false;
    }

    @Override
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemStack) {
    int blockSet = world.getBlockMetadata(x, y, z) / 4;
    int direction = MathHelper.floor_double((double)(entityliving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
    int newMeta = (blockSet * 4) + direction;
    world.setBlockMetadataWithNotify(x, y, z, newMeta, 0);
    }

    @SideOnly(Side.CLIENT)
    private Icon red;
    @SideOnly(Side.CLIENT)
    private Icon green;
    @SideOnly(Side.CLIENT)
    private Icon redamber;
    @SideOnly(Side.CLIENT)
    private Icon amber;

    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister iconRegister) {
        red = iconRegister.registerIcon("Roads:trafficLight0");
        green = iconRegister.registerIcon("Roads:trafficLight4");
        redamber = iconRegister.registerIcon("Roads:trafficLight8");
        amber = iconRegister.registerIcon("Roads:trafficLight12");
    }

    @SideOnly(Side.CLIENT)
    public Icon getIcon(int par1, int meta) {
	if (meta == 0) {
		System.out.println("Red!");
		return red;	
        }
	if (meta == 4) {
		System.out.println("Green!");
        	return green;
        }
	if (meta ==  {
		System.out.println("Red/Amber!");
        	return redamber;
        }
	if (meta == 12) {
		System.out.println("Amber!!");
        	return amber;
        }
	System.out.println("Nothin'!");
	return amber;	
    }

    @SideOnly(Side.CLIENT)
    public void getSubBlocks(int par1, CreativeTabs creativeTabs, List list) {
        list.add(new ItemStack(par1, 1, 0));
        list.add(new ItemStack(par1, 1, 4));
        list.add(new ItemStack(par1, 1, );
        list.add(new ItemStack(par1, 1, 12));
    }
}

 

And here it is in-game. The four traffic lights in my inventory are in order left-right to the ones placed in front of me:

51e28764447da.jpg

 

 

I'm happy to either use an icon (as shown) or the IItemRenderer. I tried following another thread a few pages back about using that, but it died without a solution, so wasn't much help really.

 

It's worth noting I'm not using an ItemBlock class for the texturing - as far as I'm aware I don't need to do that. Correct me if I'm wrong?

 

Anyone able to help?

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

  • 2 weeks later...
Posted

Correct icons in world, but not in inventory...

How do you render in the inventory ?

You have

@Override
    public int getRenderType() {
        return -1;
    }

you have a custom renderer, right ?

Posted

Sorry, I didn't think it would be relevant as it only renders the in-game block, which as I said works fine :P

 

Here it is anyway:

package co.uk.silvania.roads.tileentities.renderers;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import co.uk.silvania.roads.client.models.RoadSlopeModel;
import co.uk.silvania.roads.client.models.TrafficLightModel;


public class TileEntityTrafficLightRenderer extends TileEntitySpecialRenderer {

    private TrafficLightModel model;

    public TileEntityTrafficLightRenderer() {
        model = new TrafficLightModel();
    }

    @Override
    public void renderTileEntityAt(TileEntity te, double x, double y, double z,
            float scale) {
        int rotation = 180;
        switch (te.getBlockMetadata() % 4) {
            case 0:
                rotation = 0;
                break;
            case 3:
                rotation = 90;
                break;
            case 2:
                rotation = 180;
                break;
            case 1:
                rotation = 270;
                break;
        }

        GL11.glPushMatrix();
        int i = te.getBlockMetadata();
        if (i == 0 || i == 1 || i == 2 || i == 3) {
            Minecraft.getMinecraft().renderEngine.func_110577_a(new ResourceLocation("roads", "textures/entities/TrafficLightRed.png"));
        }
        if (i == 4 || i == 5 || i == 6 || i == 7) {
            Minecraft.getMinecraft().renderEngine.func_110577_a(new ResourceLocation("roads", "textures/entities/TrafficLightGreen.png"));
        }
        if (i == 8 || i == 9 || i == 10 || i == 11) {
            Minecraft.getMinecraft().renderEngine.func_110577_a(new ResourceLocation("roads", "textures/entities/TrafficLightRedAmber.png"));
        }
        if (i == 12 || i == 13 || i == 14 || i == 15) {
            Minecraft.getMinecraft().renderEngine.func_110577_a(new ResourceLocation("roads", "textures/entities/TrafficLightAmber.png"));
        }
        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
        GL11.glRotatef(rotation, 0.0F, 1.0F, 0.0F);
        GL11.glScalef(1.0F, -1F, -1F);
        model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glPopMatrix();
    }
}

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

So you don't render it into the inventory.

This is probably the reason of your issue.

So, remove

@Override
    public int getRenderType() {
        return -1;
    

or use a custom renderer.

Posted

I don't think you quite understand my issue :P

 

If I set my render ID to 0 by removing that, it breaks the block in-game - it tries to render a solid block over my rendered block, like this:

51f59e909497a.jpg

 

Right now, everything works absolutely fine when placed in the world.

All I want is a simple icon to show it in the inventory. I have an icon- I just want to change the icon based on what metadata the block has. I don't want it to render 3D in my inventory (I wouldn't complain if it did, but it's not something I'm actively aiming for)

 

 

Basically- when placed everything is absolutely fine. It's just the held icon that I'm having trouble with.

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

I don't think you quite understand my issue :P

 

he understands it fine, man. do you have a custom item for your block? if you don't, then you're probably gonna have to make a custom renderer to render your item properly. a custom renderer for your item not your tile entity.

Posted

I don't think you quite understand my issue :P

 

If I set my render ID to 0 by removing that, it breaks the block in-game - it tries to render a solid block over my rendered block, like this:

Sorry, forgot to add:

@Override
@SideOnly(Side.CLIENT)
    public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
    {
       return false;
    }

Posted

I don't think you quite understand my issue :P

 

he understands it fine, man. do you have a custom item for your block? if you don't, then you're probably gonna have to make a custom renderer to render your item properly. a custom renderer for your item not your tile entity.

 

No- he hasn't even touched on the meta which is solely where the issue is. I don't want it to render 3D

If I don't use meta on a block, it's 100% fine. Everything is exactly as I want it. Because I use meta on a few, the icons don't quite register properly. I want icons, not in-hand rendering. Here's a few screenshots which might explain it better.

Everything I hold is related to everything I place in the screenshots:

 

The icon in my hand correctly matches the block placed here:

51f64344b3993.jpg

 

And here:

51f6446123a2f.jpg

 

And here:

51f644999e73c.jpg

 

And even here:

51f644b6bdaf3.jpg

 

It's when I try and use a meta variation of the lights that I get issues....

51f644edb5330.jpg

 

 

What I want is to be able to change the icon (not rendered, not a 3D block, an icon) to match the metadata. It works everywhere else absolutely fine- it only breaks when I try and use metadata.

 

 

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

Okay, assuming he really didn't understand your problem, a custom item renderer will still solve your problem. item renderers aren't just for equipped items

Posted

No- he hasn't even touched on the meta which is solely where the issue is. I don't want it to render 3D

If I don't use meta on a block, it's 100% fine. Everything is exactly as I want it. Because I use meta on a few, the icons don't quite register properly. I want icons, not in-hand rendering. Here's a few screenshots which might explain it better.

Everything I hold is related to everything I place in the screenshots:

I don't need to touch the meta because the issue isn't here.

If it was, the world blocks wouldn't render any different.

Though I just noticed you are talking about an ItemBlock in your title.

pelep already asked, but you didn't answer.

If you have a custom ItemBlock, you should show it now.

Or basically, is it an ItemBlockWithMetadata ?

  • 5 months later...
Posted

If you haven't solved this yet, there's a video I found that answers this question:

 

 

Here's the relevant part of the code:


@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
  {
    icons = new Icon[4];
    for(int i = 0; i < icons.length; i++)
      {
        icons[i] = par1IconRegister.registerIcon(NewBlocks.modid + ":" + (this.getUnlocalizedName().substring(5)) + i);
      }
  }

@SideOnly(Side.CLIENT)
public Icon getIcon(int par1, int par2)
  {
    return icons[par2];
  }
[/Code]

 

if the files are named table0, table1, table2, etc., this will work just fine.  Hope this helps!

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.