I have no idea how I did that.

This commit is contained in:
Richard 2016-01-28 20:29:07 -02:00
parent 2718e2f763
commit ba08d4bde2

View File

@ -20,8 +20,9 @@ public class NBTUtil {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void addCompound(Object NBT, Object toAdd) { public static void addCompound(Object NBT, Object toAdd) {
if (NBT.getClass().getName().contains("NBTTagCompound") && toAdd.getClass().getName().contains("NBTTagCompound")) { if (NBT.getClass().getName().contains("NBTTagCompound") && toAdd.getClass().getName().contains("NBTTagCompound")) {
Field map = null;
try { try {
Field map = nbtClass.getDeclaredField("map"); map = nbtClass.getDeclaredField("map");
map.setAccessible(true); map.setAccessible(true);
Set<String> keySet = (Set<String>) nbtClass.getMethod("c").invoke(toAdd); Set<String> keySet = (Set<String>) nbtClass.getMethod("c").invoke(toAdd);
Iterator<String> iterator = keySet.iterator(); Iterator<String> iterator = keySet.iterator();
@ -33,7 +34,7 @@ public class NBTUtil {
if((boolean) nbtClass.getMethod("hasKeyOfType", String.class, int.class).invoke(NBT, string, 10)) { if((boolean) nbtClass.getMethod("hasKeyOfType", String.class, int.class).invoke(NBT, string, 10)) {
Object localNBT = null; Object localNBT = null;
localNBT = nbtClass.getMethod("getCompound", String.class).invoke(localNBT, string); localNBT = nbtClass.getMethod("getCompound", String.class).invoke(localNBT, string);
NBTUtil.addCompound(localNBT.toString(), base.getClass().cast(nbtClass)); NBTUtil.addCompound(localNBT, base.getClass().cast(nbtClass));
} else { } else {
nbtClass.getMethod("set", String.class, nbtBaseClass).invoke(NBT, string, base.getClass().getMethod("clone").invoke(base)); nbtClass.getMethod("set", String.class, nbtBaseClass).invoke(NBT, string, base.getClass().getMethod("clone").invoke(base));
} }
@ -43,6 +44,7 @@ public class NBTUtil {
} }
map.setAccessible(false); map.setAccessible(false);
} catch (Exception ex) { } catch (Exception ex) {
map.setAccessible(false);
ex.printStackTrace(); ex.printStackTrace();
} }
} }