Skip to content

Instantly share code, notes, and snippets.

@TheMasteredPanda
Created December 21, 2016 17:55
Show Gist options
  • Save TheMasteredPanda/7f14becfa26603264db6b6655217d6d4 to your computer and use it in GitHub Desktop.
Save TheMasteredPanda/7f14becfa26603264db6b6655217d6d4 to your computer and use it in GitHub Desktop.
NBTTagUtils#getAttribute(ItemStack item, String attributeName);
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