Jump to content

Recommended Posts

Posted (edited)

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
Posted
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.

Posted
6 minutes ago, diesieben07 said:

Yes, because the default ItemBlock class always places metadata 0.

So it turns out I need to write my ItemBlock nbt storage, and to store the meta for each block there?

Posted (edited)
7 minutes ago, diesieben07 said:

What on earth do you need an example for? You literally replace new ItemBlock with new ItemMultiTexture.

Solved

Edited by WildHeart

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.