Jump to content

[1.7.10] Cannot cast itemstack to item?


ashjack

Recommended Posts

I am trying to create an itemstack in order to get the localised name of an item, but for some reason creating the itemstack causes the game to crash with "java.lang.ClassCastException: net.minecraft.item.ItemStack cannot be cast to net.minecraft.item.Item"

 

I do not understand why this is happening because I am simply creating a new itemstack and using an item with it.

 

I am using the following code:

 

public static List<Item> itemList = new ArrayList<Item>();

public static void learnItems()
{
	itemList.clear();

	Iterator iterator = Item.itemRegistry.iterator();

                while (iterator.hasNext())
                {
                    Item item = (Item)iterator.next();

                    if (item != null)
                    {
                        item.getSubItems(item, (CreativeTabs)null, itemList);
                    }
            
                    itemList.add(item);
            
                    ModLog.log.info("Added " + new ItemStack(item).getDisplayName());
                }
}

        public static Item getItemFromMsg(String msg)
{
	for(int i = 0; i < itemList.size(); i++)
	{
		if(itemList.get(i) != null)
		{
			ItemStack is = new ItemStack(itemList.get(i)); // I tried new ItemStack(itemList.get(i), 1); with same results

			if(msg.contains(is.getDisplayName()))
			{
				return itemList.get(i);
			}
		}
		else
		{
			ModLog.log.info("Item is null");
		}
	}
	return null;
}

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.