Java Code Examples for net.minecraft.item.Item#getHasSubtypes()

The following examples show how to use net.minecraft.item.Item#getHasSubtypes() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static NonNullList<ItemStack> createSubItems(Item item, CreativeTabs creativeTab, Attribute<String> tabLabels, int[] subtypes)
{
    NonNullList<ItemStack> list = NonNullList.create();

    if (item.getHasSubtypes())
    {
        for (int meta : subtypes)
        {
            tabLabels.get(meta)
                     .ifPresent(tabLabel ->
                                {
                                    if (creativeTab == null || creativeTab == CreativeTabs.SEARCH || Objects.equals(tabLabel, getTabLabel(creativeTab)))
                                    {
                                        list.add(new ItemStack(item, 1, meta));
                                    }
                                });
        }
    } else
    {
        list.add(new ItemStack(item, 1, 0));
    }

    return list;
}
 
Example 2
@Override
protected ItemStack getSilkTouchDrop(IBlockState state)
{
    Item item = Item.getItemFromBlock(this);
    int subtype = 0;

    if (item.getHasSubtypes())
    {
        subtype = getSubtype(state);
    }

    return new ItemStack(item, 1, subtype);
}
 
Example 3
public static String getItemID(Item item, int meta) {
	if (item.getHasSubtypes()) {
		return Item.REGISTRY.getNameForObject(item) + ":" + meta;
	} else {
		return Objects.toString(Item.REGISTRY.getNameForObject(item));
	}
}
 
Example 4
@Nonnull
public static String getItemID(@Nonnull Item item, int meta) {
	if (item.getHasSubtypes()) {
		return String.format("%s:%d", Item.itemRegistry.getNameForObject(item), meta);
	} else {
		return String.valueOf(Item.itemRegistry.getNameForObject(item));
	}
}
 
Example 5
@Nonnull
public static String getItemID(@Nonnull Item item, int meta) {
	if (item.getHasSubtypes()) {
		return String.format("%s:%d", Item.itemRegistry.getNameForObject(item), meta);
	} else {
		return Item.itemRegistry.getNameForObject(item);
	}
}