Jump to content

[Solved][1.11] Block Variants.


WildHeart

Recommended Posts

Hi, there is one block with a meta tag from 1-15, is to take in hand this block it shows as it should, but if you put it in the variable variants shows the registered name of the block. How to fix?

Spoiler

public class BlockCulture extends Block
{
    public static final PropertyEnum<HarvestType> VARIANT = PropertyEnum.create("variant", HarvestType.class);

    public BlockCulture(String name)
    {
        super(Material.WOOD);
        this.setRegistryName(name);
        this.setUnlocalizedName(name);
        this.setCreativeTab(Farmland.FMCT);
        this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, HarvestType.BEAN));
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list)
    {
        for(HarvestType seedsDoubleType : HarvestType.values())
        {
            list.add(new ItemStack(itemIn, 1, seedsDoubleType.getMeta()));
        }
    }

    @Override
    public int damageDropped(IBlockState state)
    {
        return state.getValue(VARIANT).getMeta();
    }

    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(VARIANT, HarvestType.byMetadata(meta));
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
        return state.getValue(VARIANT).getMeta();
    }

    @Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {VARIANT});
    }
}

 

 

Edited by WildHeart
Link to comment
Share on other sites

5 minutes ago, diesieben07 said:

Blocks that need their metadata in the inventory need to use ItemMultiTexture or a custom ItemBlock class instead of ItemBlock.

With the blocks in the inventory no problem, the problem is that when I put the block of its variants remains the same as the first block.

Link to comment
Share on other sites

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.