Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name -> Item #8

Open
Swedz opened this issue Jul 5, 2018 · 1 comment
Open

Name -> Item #8

Swedz opened this issue Jul 5, 2018 · 1 comment

Comments

@Swedz
Copy link

Swedz commented Jul 5, 2018

So I have a situation where I need to take the name of an item, and convert it back to an item. I don't care for the item count or anything, just the data value and the material. Like a situation where I would type White Wool and it would give me new ItemStack(Material.WOOL, 1, (byte)0). I was imagining I could just do a loop through Material.values(), but that wouldn't give me the different colored wools, or types of logs, etc.

@Swedz
Copy link
Author

Swedz commented Jul 6, 2018

May have found a way of doing it. Let me know if this would be the correct way of doing it with your API:

private ItemStack getItem(String text) {
	HashMap<ItemStack, String> names = new HashMap<>();
	for(EnumItem ei : EnumItem.values()) {
		String unlocal = ei.getUnlocalizedName();
		String local = LanguageHelper.translateToLocal(unlocal, EnumLang.EN_US.getLocale());
		names.put(new ItemStack(ei.getMaterial(), 1, (short)ei.getMetadata()), local);
	}
	
	for(ItemStack item : names.keySet()) {
		String local = names.get(item);
		if(local.equalsIgnoreCase(text))
			return item;
	}
	
	return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant