Jump to content

[1.6.4] How to change custom model render based on block metadata


skullywag

Recommended Posts

Hi all,

 

Im trying to add a block that "grows" using metadata (0 = just planted, 1 = slightly grown 2 = full grown). I have a model that contains all the shapes for all the states, I want to pick the ones to show with a switch/if, something like:

 

public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);

    if(meta == 0)
    {
    	MainCrystal.render(f5);
    }
    if(meta == 1)
    {
    MainCrystal1.render(f5);
    OffShoot11.render(f5);
    OffShoot12.render(f5);
    OffShoot13.render(f5);
    }
    if(meta == 2)
    {
    MainCrystal2.render(f5);
    OffShoot21.render(f5);
    OffShoot22.render(f5);
    OffShoot23.render(f5);
    }

 

but im having trouble passing the metadata in from anywhere, Ive tried from my TileEntity Renderer class in the renderTileEntityAt method to no avail. Ive tried NBT, no luck.

 

The problem seems to be that if i print the entity passed in to renderTileEntityAt it seems to know where it is (x,y,z) it know what its blocktype is it however ALWAYS returns 0 for getBlockMetadata and blockMetadata.

 

Once ive solved this issue there is something else id like to ask on this subject but i wont muddy the waters here until this is solved as this is the one thats bugging me.

Link to comment
Share on other sites

You....are not using a render function that is appropriate for blocks, AFAICT.  You should be using either ISimpleBlockRenderingHandler, which has this:

 

 public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { }

 

With the world and coordinates you can request the metadata.

 

Or there's TileEntitySpecialRenderer, which has this:

 

public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) { }

 

Which passes a reference to a TileEntity.

 

In any case, both Entity and TileEntity have a public object worldObj which has a reference to the world where you can request metadata from blocks.

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

Forgive me if im misunderstanding you but, the start of my renderer looks like this:

 

public class TileEntityCrystalRenderer extends TileEntitySpecialRenderer {
        
        private final ModelCustom model;
        
        public TileEntityCustomRenderer() {
                this.model = new ModelCustom ();
        }
                
        @Override
        public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) 
        {     	
            GL11.glPushMatrix();

 

As per my OP if I put a print statement before that GL11 PushMatrix, both te.getBlockMetadata and te.blockMetadata return 0 all the time, even I place meta 1, 2 or 3. The render method I posted in the OP is in my model class.

 

 

Link to comment
Share on other sites

Dont know what I did but realised I was getting meta 0 even when placing 1 2 or 3 and after id removed the renderer it was still happening, deleted and recreated my block class and now it works, albeit im getting openGL errors (stack overflow) but ill figure them out. (I hope)

 

Edit - ITS ALIVE, (forgot to pop twice in my renderat)

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.