Jump to content

[1.7.2][SOLVED] Textures not working properly


Recommended Posts

Guest Abrynos
Posted

I've got a problem with my saplings textures. I've made 2 Saplings for 2 trees. In the inventory they got the same texture, but if I plant them on the ground they got their own texture and different trees are growing. I'll give you my block sapling code and a screenshot, because I can't figure out, what to do.

 

I would be grateful if you could help me!

 

Picture:

lld2fc8k48.png

Code:

 

  Reveal hidden contents

 

Posted

You need to use this method:

    /**
     * Gets the block's texture. Args: side, meta
     */
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int p_149691_1_, int p_149691_2_)

 

In BlockSapling the body is this:

    {
        p_149691_2_ &= 7;
        return field_149881_b[MathHelper.clamp_int(p_149691_2_, 0, 5)];
    }

 

So looking at your code the body should look something like this:

    {
        p_149691_2_ &= 7; // Though I don't know exactly what this is for, I would keep it as long as it won't cause a problem.
                          // This is a binary and on binary 0111 if you're curious, should have the same effect as %= 7 if I'm not mistaken.
        return saplingicon[MathHelper.clamp_int(p_149691_2_, 0, 1)]; // 0, 1 in clamp_int is to make sure you don't overIndex your saplingicon[]
                                                                     //which currently has two icons in it (at indexes 0 and 1).
    }

 

And as always, feel free to rename parameter names in overridden code, you don't need to keep the parameter names just the types.

Guest Abrynos
Posted

Sorry but this doesn't work!

 

 

 

 

@diesieben08: du kannst es mir auch auf deutsch erklären wenns nicht zu viele umstände macht

Guest Abrynos
Posted

That's a good point! I haven't thought about others needing this for their own mod

Posted

Hi.

 

Is the problem that your inventory shows the same icon for both different types of tree?

Or that the two trees are different when planted?

 

This line doesn't look right and I'm not sure how it compiles even

 

       for (int i = 0; i < saplingicon.length; ++i)
        {
           saplingicon = iconRegister.registerIcon("Abrynos:Sapling" + saplings);  // ?
        }

 

The icon shown in your inventory depends on the Item for this block, not the Block.  So for example BlockWood has an ItemMultiTexture; BlockWool has an ItemCloth.

 

Look at those vanilla to see how they do it (getIconFromDamage - since the damage value for the item corresponds to the Block metadata);

 

-TGG

 

 

 

 

Guest Abrynos
Posted

It's like you said: My problem is, that the inventory shows the same texture for both saplings!

 

The code you showed up tells minecraft to register 2 icons (do this as long as i is less than the amount of saplings = saplingicon.length) and then it tells minecraft where to find the textures: assets.abrynos.textures.blocks (shortened with "abrynos:") and that there are 2 textures (because of the for loop) the textures names are SaplingPinkcherry.png and SaplingWhitecherry.png defined with "Abrynos:Saplings" + saplings what links to

 public static final String[] saplings = new String[] {"Whitecherry", "Pinkcherry"};

Guest Abrynos
Posted

Ok i figured it out! I had to change 2 methods in my ItemSaplingBlocks.class...

 

For others to learn from this I'll add the code.

 

 

 

public static final String[] saplings = new String[] {"Whitecherry", "Pinkcherry"};
private static final IIcon[] saplingicon = new IIcon[saplings.length];

@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int par1){
par1 &= 7;
return saplingicon[MathHelper.clamp_int(par1, 0, 1)];
}

@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister){
for (int i = 0; i < saplingicon.length; ++i){
        	saplingicon[i] = iconRegister.registerIcon("Abrynos:Sapling" + saplings[i]);
        }
}

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.