Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;
}

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.