public NBTContainer() { super(null, null); nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); }
public NBTFile(File file) throws IOException { super(null, null); this.file = file; if (file.exists()) { FileInputStream inputsteam = new FileInputStream(file); nbt = NBTReflectionUtil.readNBTFile(inputsteam); } else { nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); save(); } }
@SuppressWarnings({"unchecked"}) public static NBTContainer convertNMSItemtoNBTCompound(Object nmsitem) { @SuppressWarnings("rawtypes") Class clazz = nmsitem.getClass(); Method method; try { method = clazz.getMethod("save", ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()); Object answer = method.invoke(nmsitem, ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance()); return new NBTContainer(answer); } catch (Exception e) { e.printStackTrace(); } return null; }
public static String getContent(NBTCompound comp, String key) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return null; Object workingtag = gettoCompount(rootnbttag, comp); Method method; try { method = workingtag.getClass().getMethod("get", String.class); return method.invoke(workingtag, key).toString(); } catch (Exception ex) { ex.printStackTrace(); } return null; }
public static Boolean valideCompound(NBTCompound comp) { Object root = comp.getCompound(); if (root == null) { root = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } return (gettoCompount(root, comp)) != null; }
public static NBTList getList(NBTCompound comp, String key, NBTType type) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return null; Object workingtag = gettoCompount(rootnbttag, comp); Method method; try { method = workingtag.getClass().getMethod("getList", String.class, int.class); return new NBTList(comp, key, type, method.invoke(workingtag, key, type.getId())); } catch (Exception ex) { ex.printStackTrace(); } return null; }
public static void set(NBTCompound comp, String key, Object val) { if (val == null) { remove(comp, key); return; } Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) { new Throwable("InvalideCompound").printStackTrace(); return; } Object workingtag = gettoCompount(rootnbttag, comp); Method method; try { method = workingtag.getClass().getMethod("set", String.class, ClassWrapper.NMS_NBTBASE.getClazz()); method.invoke(workingtag, key, val); comp.setCompound(rootnbttag); } catch (Exception ex) { ex.printStackTrace(); } }
public static void addNBTTagCompound(NBTCompound comp, String name) { if (name == null) { remove(comp, name); return; } Object nbttag = comp.getCompound(); if (nbttag == null) { nbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return; Object workingtag = gettoCompount(nbttag, comp); Method method; try { method = workingtag.getClass().getMethod("set", String.class, ClassWrapper.NMS_NBTBASE.getClazz()); method.invoke(workingtag, name, ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance()); comp.setCompound(nbttag); return; } catch (Exception ex) { ex.printStackTrace(); } return; }
@SuppressWarnings("unchecked") public static Set<String> getKeys(NBTCompound comp) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return null; Object workingtag = gettoCompount(rootnbttag, comp); return (Set<String>) ReflectionMethod.COMPOUND_GET_KEYS.run(workingtag); }
public static void setTileEntityNBTTagCompound(BlockState tile, Object comp) { try { Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ()); Object cworld = ClassWrapper.CRAFT_WORLD.getClazz().cast(tile.getWorld()); Object nmsworld = ReflectionMethod.CRAFT_WORLD_GET_HANDLE.run(cworld); Object o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos); ReflectionMethod.TILEENTITY_SET_NBT.run(o, comp); } catch (Exception e) { e.printStackTrace(); } }
public static void addOtherNBTCompound(NBTCompound comp, NBTCompound nbtcompound) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return; Object workingtag = gettoCompount(rootnbttag, comp); try { ReflectionMethod.COMPOUND_ADD.run(workingtag, nbtcompound.getCompound()); comp.setCompound(rootnbttag); } catch (Exception ex) { ex.printStackTrace(); } }
public static void remove(NBTCompound comp, String key) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return; Object workingtag = gettoCompount(rootnbttag, comp); ReflectionMethod.COMPOUND_REMOVE_KEY.run(workingtag, key); comp.setCompound(rootnbttag); }
public static Object getTileEntityNBTTagCompound(BlockState tile) { try { Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ()); Object cworld = ClassWrapper.CRAFT_WORLD.getClazz().cast(tile.getWorld()); Object nmsworld = ReflectionMethod.CRAFT_WORLD_GET_HANDLE.run(cworld); Object o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos); Object tag = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance(); Object answer = ReflectionMethod.TILEENTITY_GET_NBT.run(o, tag); if (answer == null) answer = tag; return answer; } catch (Exception e) { e.printStackTrace(); } return null; }
public static void setData(NBTCompound comp, ReflectionMethod type, String key, Object data) { if (data == null) { remove(comp, key); return; } Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return; Object workingtag = gettoCompount(rootnbttag, comp); type.run(workingtag, key, data); comp.setCompound(rootnbttag); }