Java Code Examples for net.minecraft.item.Item.getSubItems()

The following are Jave code examples for showing how to use getSubItems() of the net.minecraft.item.Item class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: pnc-repressurized   File: GuiSearcher.java   Source Code and License Vote up 6 votes
/**
 * Lazy cache.
 * @return
 */
private Stream<SearchEntry> getSearchEntries(){
    if(cachedSearchEntries == null){
        NonNullList<ItemStack> itemList = NonNullList.create();

        for(Item item : Item.REGISTRY){
            if (item != null && item.getCreativeTab() != null) {
                item.getSubItems(item.getCreativeTab(), itemList);
            }
        }

        for (Enchantment enchantment : Enchantment.REGISTRY) {
            if (enchantment != null && enchantment.type != null) {
                getAllEnchantedBooks(enchantment, itemList);
            }
        }

        cachedSearchEntries = itemList.stream().map(SearchEntry::new).collect(Collectors.toList());
    }
    return cachedSearchEntries.stream();
}
 
Example 2
Project: nei-lotr   File: PoisonedDrinkRecipeHandler.java   Source Code and License Vote up 6 votes
public void computeRecipes(Integer count, ItemStack stack) {
	if (stack.getItemDamage() == 0 && stack.getItem() instanceof LOTRItemMug) {
		Item item = stack.getItem();
		List<ItemStack> list = new ArrayList<>();
		item.getSubItems(item, null, list);
		list.forEach(stack2 -> {
			if (LOTRPoisonedDrinks.canPoison(stack2)) {
				ItemStack result = stack2.copy();
				LOTRPoisonedDrinks.setDrinkPoisoned(result, true);
				ItemStack ingred = stack2.copy();
				ExtendedCachedShapelessRecipe recipe = new ExtendedCachedShapelessRecipe(
						Arrays.asList(ingred, POISON_STACK), Arrays.asList(result));
				if (craftingRecipes.get(result) == null)
					craftingRecipes.put(result, new HashSet<>());
				craftingRecipes.get(result).add(recipe);
				if (usageRecipes.get(ingred) == null)
					usageRecipes.put(ingred, new HashSet<>());
				usageRecipes.get(ingred).add(recipe);
				if (usageRecipes.get(POISON_STACK) == null)
					usageRecipes.put(POISON_STACK, new HashSet<>());
				usageRecipes.get(POISON_STACK).add(recipe);
			}
		});
	}
}
 
Example 3
Project: BaseClient   File: CreativeTabs.java   Source Code and License Vote up 6 votes
/**
 * only shows items which have tabToDisplayOn == this
 */
public void displayAllReleventItems(List<ItemStack> p_78018_1_)
{
    for (Item item : Item.itemRegistry)
    {
        if (item != null && item.getCreativeTab() == this)
        {
            item.getSubItems(item, this, p_78018_1_);
        }
    }

    if (this.getRelevantEnchantmentTypes() != null)
    {
        this.addEnchantmentBooksToList(p_78018_1_, this.getRelevantEnchantmentTypes());
    }
}
 
Example 4
Project: BaseClient   File: CreativeTabs.java   Source Code and License Vote up 6 votes
/**
 * only shows items which have tabToDisplayOn == this
 */
public void displayAllReleventItems(List<ItemStack> p_78018_1_)
{
    for (Item item : Item.itemRegistry)
    {
        if (item != null && item.getCreativeTab() == this)
        {
            item.getSubItems(item, this, p_78018_1_);
        }
    }

    if (this.getRelevantEnchantmentTypes() != null)
    {
        this.addEnchantmentBooksToList(p_78018_1_, this.getRelevantEnchantmentTypes());
    }
}
 
Example 5
Project: Backmemed   File: CreativeTabs.java   Source Code and License Vote up 6 votes
/**
 * only shows items which have tabToDisplayOn == this
 */
public void displayAllRelevantItems(NonNullList<ItemStack> p_78018_1_)
{
    for (Item item : Item.REGISTRY)
    {
        if (item != null && item.getCreativeTab() == this)
        {
            item.getSubItems(item, this, p_78018_1_);
        }
    }

    if (this.getRelevantEnchantmentTypes() != null)
    {
        this.addEnchantmentBooksToList(p_78018_1_, this.getRelevantEnchantmentTypes());
    }
}
 
Example 6
Project: CustomWorldGen   File: GuiContainerCreative.java   Source Code and License Vote up 6 votes
private void updateCreativeSearch()
{
    GuiContainerCreative.ContainerCreative guicontainercreative$containercreative = (GuiContainerCreative.ContainerCreative)this.inventorySlots;
    guicontainercreative$containercreative.itemList.clear();

    CreativeTabs tab = CreativeTabs.CREATIVE_TAB_ARRAY[selectedTabIndex];
    if (tab.hasSearchBar() && tab != CreativeTabs.SEARCH)
    {
        tab.displayAllRelevantItems(guicontainercreative$containercreative.itemList);
        updateFilteredItems(guicontainercreative$containercreative);
        return;
    }

    for (Item item : Item.REGISTRY)
    {
        if (item != null && item.getCreativeTab() != null)
        {
            item.getSubItems(item, (CreativeTabs)null, guicontainercreative$containercreative.itemList);
        }
    }
    updateFilteredItems(guicontainercreative$containercreative);
}
 
Example 7
Project: CustomWorldGen   File: CreativeTabs.java   Source Code and License Vote up 6 votes
/**
 * only shows items which have tabToDisplayOn == this
 */
@SideOnly(Side.CLIENT)
public void displayAllRelevantItems(List<ItemStack> p_78018_1_)
{
    for (Item item : Item.REGISTRY)
    {
        if (item == null)
        {
            continue;
        }
        for (CreativeTabs tab : item.getCreativeTabs())
        {
            if (tab == this)
            {
                item.getSubItems(item, this, p_78018_1_);
            }
        }
    }

    if (this.getRelevantEnchantmentTypes() != null)
    {
        this.addEnchantmentBooksToList(p_78018_1_, this.getRelevantEnchantmentTypes());
    }
}
 
Example 8
Project: ModularMachinery   File: FuelItemHelper.java   Source Code and License Vote up 6 votes
public static void initialize() {
    NonNullList<ItemStack> stacks = NonNullList.create();
    for (Item i : ForgeRegistries.ITEMS) {
        CreativeTabs tab = i.getCreativeTab();
        if(tab != null) {
            i.getSubItems(tab, stacks);
        }
    }
    List<ItemStack> out = new LinkedList<>();
    for (ItemStack stack : stacks) {
        int burn = TileEntityFurnace.getItemBurnTime(stack); //Respects vanilla values.
        if(burn > 0) {
            out.add(stack);
        }
    }
    knownFuelStacks = ImmutableList.copyOf(out);
}
 
Example 9
Project: ThermionicsWorld   File: ClientProxy.java   Source Code and License Vote up 5 votes
public void registerItemModel(Item item) {
	ResourceLocation loc = Item.REGISTRY.getNameForObject(item);
	if (item instanceof ItemBlockEquivalentState) {
		
		NonNullList<ItemStack> subItems = NonNullList.create();
		item.getSubItems(ThermionicsWorld.TAB_THERMIONICS_WORLD, subItems);
		for(ItemStack stack : subItems) {
			Item stackItem = stack.getItem();
			if (stackItem!=item) continue; //The contract of getSubItems prohibits this condition.
			String keys = ((ItemBlockEquivalentState)item).getStateStringForItem(stack);
			//System.out.println("Registering model for "+loc+"#"+keys+" == meta:"+stack.getItemDamage());
			
			ModelLoader.setCustomModelResourceLocation(stackItem, stack.getItemDamage(),
					new ModelResourceLocation(loc, keys)
					);
		}
	} else if (item instanceof ItemBlockGemrock) {
		for(int i=0; i<16; i++) {
			ModelLoader.setCustomModelResourceLocation(item, i, new ModelResourceLocation(loc,"variant="+i));
		}
	} else if (item instanceof ItemBlockVarieties) {
		for(int i=0; i<16; i++) {
			ModelLoader.setCustomModelResourceLocation(item, i, new ModelResourceLocation(loc,"variant="+i));
		}
	} else {
		ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(loc, "inventory"));
	}
}
 
Example 10
Project: BaseClient   File: GuiContainerCreative.java   Source Code and License Vote up 4 votes
private void updateCreativeSearch()
{
    GuiContainerCreative.ContainerCreative guicontainercreative$containercreative = (GuiContainerCreative.ContainerCreative)this.inventorySlots;
    guicontainercreative$containercreative.itemList.clear();

    for (Item item : Item.itemRegistry)
    {
        if (item != null && item.getCreativeTab() != null)
        {
            item.getSubItems(item, (CreativeTabs)null, guicontainercreative$containercreative.itemList);
        }
    }

    for (Enchantment enchantment : Enchantment.enchantmentsBookList)
    {
        if (enchantment != null && enchantment.type != null)
        {
            Items.enchanted_book.getAll(enchantment, guicontainercreative$containercreative.itemList);
        }
    }

    Iterator<ItemStack> iterator = guicontainercreative$containercreative.itemList.iterator();
    String s1 = this.searchField.getText().toLowerCase();

    while (iterator.hasNext())
    {
        ItemStack itemstack = (ItemStack)iterator.next();
        boolean flag = false;

        for (String s : itemstack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips))
        {
            if (EnumChatFormatting.getTextWithoutFormattingCodes(s).toLowerCase().contains(s1))
            {
                flag = true;
                break;
            }
        }

        if (!flag)
        {
            iterator.remove();
        }
    }

    this.currentScroll = 0.0F;
    guicontainercreative$containercreative.scrollTo(0.0F);
}
 
Example 11
Project: BaseClient   File: GuiContainerCreative.java   Source Code and License Vote up 4 votes
private void updateCreativeSearch()
{
    GuiContainerCreative.ContainerCreative guicontainercreative$containercreative = (GuiContainerCreative.ContainerCreative)this.inventorySlots;
    guicontainercreative$containercreative.itemList.clear();

    for (Item item : Item.itemRegistry)
    {
        if (item != null && item.getCreativeTab() != null)
        {
            item.getSubItems(item, (CreativeTabs)null, guicontainercreative$containercreative.itemList);
        }
    }

    for (Enchantment enchantment : Enchantment.enchantmentsBookList)
    {
        if (enchantment != null && enchantment.type != null)
        {
            Items.enchanted_book.getAll(enchantment, guicontainercreative$containercreative.itemList);
        }
    }

    Iterator<ItemStack> iterator = guicontainercreative$containercreative.itemList.iterator();
    String s1 = this.searchField.getText().toLowerCase();

    while (iterator.hasNext())
    {
        ItemStack itemstack = (ItemStack)iterator.next();
        boolean flag = false;

        for (String s : itemstack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips))
        {
            if (EnumChatFormatting.getTextWithoutFormattingCodes(s).toLowerCase().contains(s1))
            {
                flag = true;
                break;
            }
        }

        if (!flag)
        {
            iterator.remove();
        }
    }

    this.currentScroll = 0.0F;
    guicontainercreative$containercreative.scrollTo(0.0F);
}
 
Example 12
Project: Solar   File: CreativeTabHandler.java   Source Code and License Vote up 4 votes
@SideOnly(Side.CLIENT)
void addItem(Item item) {
	item.getSubItems(this, list);
}
 
Example 13
Project: Backmemed   File: GuiContainerCreative.java   Source Code and License Vote up 4 votes
private void updateCreativeSearch()
{
    GuiContainerCreative.ContainerCreative guicontainercreative$containercreative = (GuiContainerCreative.ContainerCreative)this.inventorySlots;
    guicontainercreative$containercreative.itemList.clear();

    for (Item item : Item.REGISTRY)
    {
        if (item != null && item.getCreativeTab() != null)
        {
            item.getSubItems(item, (CreativeTabs)null, guicontainercreative$containercreative.itemList);
        }
    }

    for (Enchantment enchantment : Enchantment.REGISTRY)
    {
        if (enchantment != null && enchantment.type != null)
        {
            Items.ENCHANTED_BOOK.getAll(enchantment, guicontainercreative$containercreative.itemList);
        }
    }

    Iterator<ItemStack> iterator = guicontainercreative$containercreative.itemList.iterator();
    String s1 = this.searchField.getText().toLowerCase(Locale.ROOT);

    while (iterator.hasNext())
    {
        ItemStack itemstack = (ItemStack)iterator.next();
        boolean flag = false;

        for (String s : itemstack.getTooltip(this.mc.player, this.mc.gameSettings.advancedItemTooltips))
        {
            if (TextFormatting.getTextWithoutFormattingCodes(s).toLowerCase(Locale.ROOT).contains(s1))
            {
                flag = true;
                break;
            }
        }

        if (!flag)
        {
            iterator.remove();
        }
    }

    this.currentScroll = 0.0F;
    guicontainercreative$containercreative.scrollTo(0.0F);
}