/** * */ package net.machinemuse.general; import net.machinemuse.numina.general.MuseLogger; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagInt; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; /** * Workaround class to access static NBTTagCompound.getTagMap() * * @author MachineMuse */ public class NBTTagAccessor extends NBTTagCompound { public static Method mTagAccessor; /** * Accesses the package-visible *

*

     * Map NBTTagCompound.getTagMap(NBTTagCompound tag)
     * 
*

* Will likely need to be updated every time the obfuscation changes. * * @return * @throws SecurityException * @throws NoSuchMethodException */ public static Method getTagAccessor() throws NoSuchMethodException, SecurityException { if (mTagAccessor == null) { try { mTagAccessor = NBTTagCompound.class.getDeclaredMethod( "getTagMap", NBTTagCompound.class); mTagAccessor.setAccessible(true); return mTagAccessor; } catch (NoSuchMethodException e) { mTagAccessor = NBTTagCompound.class.getDeclaredMethod( "a", NBTTagCompound.class); mTagAccessor.setAccessible(true); return mTagAccessor; } } else { return mTagAccessor; } } public static Map getMap(NBTTagCompound nbt) { try { return (Map) getTagAccessor().invoke(nbt, nbt); } catch (Exception e) { e.printStackTrace(); } MuseLogger.logError("Unable to access nbt tag map!"); return null; } public static List getValues(NBTTagCompound nbt) { Set keyset = (Set) nbt.func_150296_c(); ArrayList a = new ArrayList(keyset.size()); for (String key : keyset) { NBTBase c = nbt.getTag(key); if (c instanceof NBTTagCompound) { a.add((NBTTagCompound) c); } } return a; } }