Jump to content

Recommended Posts

Posted

Hi :)

 

I'm currently trying to figure out how to get different textures on different sides of a block, while using the infinite terrain / sprite index.

 

I did this before in modloader fine, but in forge using the terrain.png style approach I'm a bit stumped.  I have tried for hours scouring the net for answers and the few I found were just vague.  Maybe I'm being blind and/or stupid but hopefully someone can help.

 

I have the textures working fine using the mods terrain.png, I just need to know the code that applies a different index number for each side of the block in question.

 

Thanks in advance,

Husky :)

 

NB: Work I've referenced http://www.minecraftforge.net/wiki/How_to_use_infinite_terrain_and_sprite_indexes

Posted

public int getBlockTextureFromSide(int i);

 

This is a method that can go in your block class. You should say if(i == x) return y; With x being the side (a number between 0 and 5) and y being the sprite index (a number between 0 and 255).

Posted

Hi :)

 

I'm currently trying to figure out how to get different textures on different sides of a block, while using the infinite terrain / sprite index.

 

I did this before in modloader fine, but in forge using the terrain.png style approach I'm a bit stumped.  I have tried for hours scouring the net for answers and the few I found were just vague.  Maybe I'm being blind and/or stupid but hopefully someone can help.

 

I have the textures working fine using the mods terrain.png, I just need to know the code that applies a different index number for each side of the block in question.

 

Thanks in advance,

Husky :)

 

NB: Work I've referenced http://www.minecraftforge.net/wiki/How_to_use_infinite_terrain_and_sprite_indexes

 

This is actually really simple, don't get discouaged. Texture files have mini texture tiles of 16 rows of 16. if you start numbering them from the top left to the bottom right, these are the numbers that are expected to be returned. The code depends on the way you set up your texture file, and which side needs which texture, but in the method:

getTextureFromSideAndMetadata(int i, int j) the two variables are, as expected side and metadata, in that order.

 

From this info, you can figure out which texture index you need to return. The actual texture file is retrieved by the renderer by your getTextureFile() method you need to override.

 

 

Posted

Simple as that... >.< 

 

Haha, I guess I've been battling with it for long enough I expect it to be more difficult.  Can't wait to get home and try this out!  Have a relaxing day of VBA programming until then though :P

 

Thanks guys :)  Glad I signed up here now.

 

Husky

 

 

EDIT:

 

So the coding might be like this:

 

public int getBlockTextureFromSide(int sideNumber)
{
    if(sideNumber==0)
        {
            return 6;
        }
    if(sideNumber==1)
        {
            return 7;
        }
    if(sideNumber==2)
        {
            return 8;
        }
    if(sideNumber==3)
        {
            return 9;
        }
    Else
        {
            return 10;
}
}

 

I'm quite new to Java programming and wrote the above in notepad so forgive any errors.  I'm wondering if there is more elegant way of writing this, perhaps select case?  I found some code by googling, adapted it, and wonder if this is right?

 

public int getBlockTextureFromSide(int sideNumber)
{
    Switch (sideNumber)
    {
        Case 0:
            return 6;
        Case 1:
            return 7;
        Case 2:
            return 8;
        Case 3:
            return 9;
        Case 4:
        Case 5:
        default:
            return 10;
    }
}

Posted

yes, well:

Case 4:

Case 5:

default:

    return 10;

is redundant. default means everything else, and cases will do the code in the next case unless you break or return, so you can remove the last two cases and it would do the same thing.

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.