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

The following examples show how to use net.minecraft.item.Item#getHasSubtypes() . 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
Source File: ItemHelper.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: BlockMixin.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@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
Source File: WrapUtility.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
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
Source File: WrapUtility.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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
Source File: WrapUtility.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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);
	}
}