Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi guys :D I wanna ask you how to render my custom leaves in fast graphic too, like the normal leafes?

 

Here is my BlockLeafMod file:


package mod.mineworld.blocks.mod_plants;


import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mod.mineworld.MineWorld;
import mod.mineworld.mod_tabs;
import net.minecraft.block.BlockLeaves;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockLeafMod extends BlockLeaves
{
    public static final String[][] leaf_names = new String[][] {{"leaves_apple", "leaves_palm"}, {"leaves_apple_opaque", "leaves_palm_opaque"}};
    public static final String[] leaf_types = new String[] {"apple", "palm"};
    protected IIcon[][] icon = new IIcon[2][];
    
    public BlockLeafMod()
    {
        this.setCreativeTab(mod_tabs.tabPlantsDecorations);
        this.setHardness(0.2F);
        this.setLightOpacity(1);
        this.setStepSound(soundTypeGrass);
        this.setTickRandomly(true);
    }
    

    protected void dropBlockAsItemWithChance(World par1, int par2, int par3, int par4, int par5, int par6)
    {
        if ((par5 & 3) == 0 && par1.rand.nextInt(par6) == 0)
        {
            this.dropBlockAsItem(par1, par2, par3, par4, new ItemStack(Items.apple, 1, 0));
        }
    }

    protected int func_150123_b(int par1)
    {
        int j = super.func_150123_b(par1);

        if ((par1 & 3) == 3)
        {
            j = 40;
        }

        return j;
    }

    /**
     * Gets the block's texture. Args: side, meta
     */
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int par1, int par2)
    {
        return (par2 & 3) == 1 ? this.icon[this.field_150127_b][1] : ((par2 & 3) == 3 ? this.icon[this.field_150127_b][3] : ((par2 & 3) == 2 ? this.icon[this.field_150127_b][2] : this.icon[this.field_150127_b][0]));
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void registerBlockIcons(IIconRegister par1)
    {
    	setGraphicsLevel(Minecraft.getMinecraft().gameSettings.fancyGraphics);
    	for (int i = 0; i < leaf_names.length; ++i)
        {
            this.icon[i] = new IIcon[leaf_names[i].length];

            for (int j = 0; j < leaf_names[i].length; ++j)
            {
                this.icon[i][j] = par1.registerIcon(MineWorld.MODID + ":mod_plants/" + leaf_names[i][j]);
            }
        }
    }

    public String[] func_150125_e()
    {
        return leaf_types;
    }
    
    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item par1, CreativeTabs par2, List par3)
    {
        par3.add(new ItemStack(par1, 1, 0));
        par3.add(new ItemStack(par1, 1, 1));
    }

    /**
     * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
     * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
     */
    protected ItemStack createStackedBlock(int par1)
    {
        return new ItemStack(this, 1, par1 & 3);
    }
    
    /**
     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
     */
    public boolean isOpaqueCube()
    {
    	return false;
    }
    

}

 

and the ItemLeaf file:

package mod.mineworld.blocks.mod_plants;

import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

public class ItemLeaf extends ItemBlock {

private final static String[] subNames = {
	"apple", "palm"
};

public ItemLeaf(Block id) {
	super(id);
	setHasSubtypes(true);
}

@Override
public int getMetadata (int damageValue) {
	return damageValue;
}

@Override
public String getUnlocalizedName(ItemStack itemstack) {
	return getUnlocalizedName() + "." + subNames[itemstack.getItemDamage()];
}

}

 

Thanks in advice for all who will help me :D

Don't blame me if i always ask for your help. I just want to learn to be better :)

Just add this line to the

getIcon()

method:

 

this.setGraphicsLevel(Minecraft.getMinecraft().gameSettings.fancyGraphics);

 

It should look like this:

 

    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int par1, int par2)
    {
        this.setGraphicsLevel(Minecraft.getMinecraft().gameSettings.fancyGraphics);

        return (par2 & 3) == 1 ? this.icon[this.field_150127_b][1] : ((par2 & 3) == 3 ? this.icon[this.field_150127_b][3] : ((par2 & 3) == 2 ? this.icon[this.field_150127_b][2] : this.icon[this.field_150127_b][0]));
    }

 

P.S.: I also had the same problem, a few days ago: [1.7.2] [solved] Custom Leaves always render transparent

  • Author

I've add that line in the registerIcon method, not in the getIcon method, now i've changed it and placed it in the right place and it works! :D Thanks man! ;)

Don't blame me if i always ask for your help. I just want to learn to be better :)

Guest
This topic is now closed to further replies.

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.