public static Object getEntityNBTTagCompound(Object NMSEntity) { try { Object nbt = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance(); Object answer = ReflectionMethod.NMS_ENTITY_GET_NBT.run(NMSEntity, nbt); if (answer == null) answer = nbt; return answer; } catch (Exception e) { e.printStackTrace(); } return null; }
public static Object getNMSEntity(Entity entity) { try { return ReflectionMethod.CRAFT_ENTITY_GET_HANDLE.run(ClassWrapper.CRAFT_ENTITY.getClazz().cast(entity)); } catch (Exception e) { e.printStackTrace(); } return null; }
public void setString(int i, String s) { if (type != NBTType.NBTTagString) { new Throwable("Using String method on a non String list!").printStackTrace(); return; } try { ReflectionMethod.LIST_SET.run(listObject, i, ClassWrapper.NMS_NBTTAGSTRING.getClazz().getConstructor(String.class).newInstance(s)); save(); } catch (Exception ex) { ex.printStackTrace(); } }
public void addString(String s) { if (type != NBTType.NBTTagString) { new Throwable("Using String method on a non String list!").printStackTrace(); return; } try { ReflectionMethod.LIST_ADD.run(listObject, ClassWrapper.NMS_NBTTAGSTRING.getClazz().getConstructor(String.class).newInstance(s)); save(); } catch (Exception ex) { ex.printStackTrace(); } }
public NBTListCompound addCompound() { if (type != NBTType.NBTTagCompound) { new Throwable("Using Compound method on a non Compound list!").printStackTrace(); return null; } try { Object compound = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance(); ReflectionMethod.LIST_ADD.run(listObject, compound); return new NBTListCompound(this, compound); } catch (Exception ex) { ex.printStackTrace(); } return null; }
@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; }
@SuppressWarnings({"unchecked"}) public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) { @SuppressWarnings("rawtypes") Class clazz = ClassWrapper.NMS_ITEMSTACK.getClazz(); try { if(MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_12_R1.getVersionId()){ Constructor<?> constructor = clazz.getConstructor(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()); constructor.setAccessible(true); return constructor.newInstance(nbtcompound.getCompound()); }else{ Method method = clazz.getMethod("createStack", ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()); method.setAccessible(true); return method.invoke(null, nbtcompound.getCompound()); } } catch (Exception e) { e.printStackTrace(); } return null; }
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; }
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 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 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(); } }