Created
December 21, 2016 17:55
-
-
Save TheMasteredPanda/7f14becfa26603264db6b6655217d6d4 to your computer and use it in GitHub Desktop.
NBTTagUtils#getAttribute(ItemStack item, String attributeName);
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Object getAttribute(ItemStack itemStack, String attributeName) | |
{ | |
// CraftItemStack.asNMSCopy(ItemStack item). | |
Class<?> obcCraftItemStackClazz = ReflectionUtils.getOBCClass("CraftItemStack"); | |
try { | |
Object nmsItem = ReflectionUtils.callMethod(obcCraftItemStackClazz.getMethod("asNMSCopy", ItemStack.class), null, itemStack); | |
Object compoundGetter = ReflectionUtils.callMethod(nmsItem.getClass().getMethod("getCompound"), obcCraftItemStackClazz, null); | |
return ReflectionUtils.callMethod(compoundGetter.getClass().getMethod("get", String.class), compoundGetter, attributeName); | |
} catch (Exception nbtTagUtilsAttributeGetterExceptions) { | |
nbtTagUtilsAttributeGetterExceptions.printStackTrace(); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment