Jump to content

Recommended Posts

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 :)

Posted

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

Posted

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello , when I try to launch the forge installer it just crash with a message for 0,5 secondes. I'm using java 17 to launch it. Here's the link of the error :https://cdn.corenexis.com/view/?img=d/ma24/qs7u4U.jpg  
    • You will find the crash-report or log in your minecraft directory (crash-report or logs folder)
    • Use a modpack which is using these 2 mods as working base:   https://www.curseforge.com/minecraft/modpacks/life-in-the-village-3
    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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