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:

 

public class AbrBlockSapling extends BlockSapling {

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

    private static final IIcon[] saplingicon = new IIcon[saplings.length];

 

    protected AbrBlockSapling()

    {

        float f = 0.4F;

        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);

        this.setCreativeTab(AbrCreativeTabs.Abrynosplants);

    }

 

    /**

    * Ticks the block if it's been scheduled

    */

    public void updateTick(World world, int x, int y, int z, Random random)

    {

        if (!world.isRemote)

        {

            super.updateTick(world, x, y, z, random);

 

            if (world.getBlockLightValue(x, y + 1, z) >= 9 && random.nextInt(7) == 0)

            {

                this.func_149879_c(world, x, y, z, random);

            }

        }

    }

 

    /**

    * Gets the block's texture. Args: side, meta

    */

    @SideOnly(Side.CLIENT)

    public IIcon getIcon(int side, int meta)

    {

        if(meta == 0){

        return saplingicon[0];

        }

        else{

        return saplingicon[1];

        }

    }

 

    //markOreGrowMarked

    public void func_149879_c(World world, int x, int y, int z, Random random)

    {

        int l = world.getBlockMetadata(x, y, z);

 

        if ((l & 8) == 0)

        {

            world.setBlockMetadataWithNotify(x, y, z, l | 8, 4);

        }

        else

        {

            this.func_149878_d(world, x, y, z, random);

        }

    }

 

    //growTree

    public void func_149878_d(World world, int x, int y, int z, Random random)

    {

        if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(world, random, x, y, z)) return;

        int l = world.getBlockMetadata(x, y, z) & 7;

        Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);

        int i1 = 0;

        int j1 = 0;

        boolean flag = false;

 

        switch (l) {

            case 0: //Whitecherry...   ID's of log & leaf = 0, 0

            object = new FeatureGenTrees(TreeRegistry.blockLog, TreeRegistry.blockLeaf, 0, 0, false, 5, 6, false);

            break;

            case 1: //Pinkcherry...   ID's of log & leaf = 1, 1

            object = new FeatureGenTrees(TreeRegistry.blockLog, TreeRegistry.blockLeaf, 0, 1, false, 5, 6, false);

                break;

            case 2:

                break;

            case 3:

                break;

            case 4:

                break;

            case 5:

            break;

            default:

            break;

        }

 

        Block block = Blocks.air;

 

        if (flag)

        {

            world.setBlock(x + i1, y, z + j1, block, 0, 4);

            world.setBlock(x + i1 + 1, y, z + j1, block, 0, 4);

            world.setBlock(x + i1, y, z + j1 + 1, block, 0, 4);

            world.setBlock(x + i1 + 1, y, z + j1 + 1, block, 0, 4);

        }

        else

        {

            world.setBlock(x, y, z, block, 0, 4);

        }

 

        if (!((WorldGenerator)object).generate(world, random, x + i1, y, z + j1))

        {

            if (flag)

            {

                world.setBlock(x + i1, y, z + j1, this, l, 4);

                world.setBlock(x + i1 + 1, y, z + j1, this, l, 4);

                world.setBlock(x + i1, y, z + j1 + 1, this, l, 4);

                world.setBlock(x + i1 + 1, y, z + j1 + 1, this, l, 4);

            }

            else

            {

                world.setBlock(x, y, z, this, l, 4);

            }

        }

    }

 

//isSameSapling

    public boolean func_149880_a(World world, int x, int y, int z, int par1)

    {

        return world.getBlock(x, y, z) == this && (world.getBlockMetadata(x, y, z) & 7) == par1;

    }

 

    /**

    * Determines the damage on the item the block drops. Used in cloth and wood.

    */

    public int damageDropped(int par1)

    {

        return MathHelper.clamp_int(par1 & 7, 0, 5);

    }

 

    /**

    * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)

    */

    @Override

    public void getSubBlocks(Item item, CreativeTabs tabs, List list)

    {

    for(int i = 0; i < saplings.length; i++){

list.add(new ItemStack(item, 1, i));

}

    }

 

    //RegisterIcons

    @SideOnly(Side.CLIENT)

    public void registerBlockIcons(IIconRegister iconRegister)

    {       

    for (int i = 0; i < saplingicon.length; ++i)

        {

        saplingicon = iconRegister.registerIcon("Abrynos:Sapling" + saplings);

        }

    }

 

 

    public boolean func_149851_a(World world, int x, int y, int z, boolean par1)

    {

        return true;

    }

 

    public boolean func_149852_a(World world, Random random, int x, int y, int z)

    {

        return (double)world.rand.nextFloat() < 0.45D;

    }

 

    public void func_149853_b(World world, Random random, int x, int y, int z)

    {

        this.func_149879_c(world, x, y, z, random);

    }

   

    @Override

public int getRenderColor(int p_149741_1_)

    {

        return -2;

    }

   

    @Override

public int colorMultiplier(IBlockAccess iBlockAccess, int x, int y, int z) {

return 0xf6cbec;

    }

}

 

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.