@Override public TagCompound save() { TagCompound nbtTagCompound = new TagCompound(); nbtTagCompound.getCompoundData().put("Buffs", new TagIntArray(selectedBuffs.stream().mapToInt(Buff::getId).toArray())); nbtTagCompound.getCompoundData().put("Active", new TagByte(this.active)); nbtTagCompound.getCompoundData().put("Reciever", new TagString(this.receiver.name())); return nbtTagCompound; }
@Override public void load(TagCompound compound) { if (compound.getCompoundData().containsKey("Buff")) { Buff selectedBuff = Buff.getBuffByID(compound.getAs("Buff", TagInt.class).getIntData()); if (selectedBuff != null) { this.selectedBuffs.add(selectedBuff); } } if (compound.getCompoundData().containsKey("Buffs")) { int[] selectedBuffs = compound.getAs("Buffs", TagIntArray.class).getIntArrayData(); if (selectedBuffs.length != 0) { for (int selectedBuffId : selectedBuffs) { Buff selectedBuff = Buff.getBuffByID(selectedBuffId); if (selectedBuff != null) { this.selectedBuffs.add(selectedBuff); } } } } if (compound.getCompoundData().containsKey("Active")) { this.active = compound.getAs("Active", TagByte.class).getBooleanData(); } if (compound.getCompoundData().containsKey("Reciever")) { this.receiver = BuffReceiver.valueOf(compound.getAs("Reciever", TagString.class).getStringData()); } }
@SuppressWarnings("unchecked") public void applyTo(TagCompound tag) { if (hasOwner()) { TagCompound ownerTag = new TagCompound(); ownerTag.put("Name", new TagString(getOwner())); if (hasTexture()) { TagCompound propertiesTag = new TagCompound(); TagList textureList = new TagList(); TagCompound textureTag = new TagCompound(); JSONObject jsonObject = new JSONObject(); JSONObject texturesObject = new JSONObject(); JSONObject skinObject = new JSONObject(); jsonObject.put("textures", texturesObject); texturesObject.put("SKIN", skinObject); skinObject.put("url", getTexture()); String base64 = BaseEncoding.base64Url().encode(jsonObject.toJSONString().getBytes()); textureTag.put("Value", new TagString(base64)); textureList.addTag(textureTag); propertiesTag.put("textures", textureList); ownerTag.put("Properties", propertiesTag); } tag.put("SkullOwner", ownerTag); } }
public void convert(StoredMyPet pet) { Version fromVersion = Version.v1_7_R4; TagCompound info = pet.getInfo(); if (info.containsKey("Version")) { if (info.containsKeyAs("Version", TagString.class)) { fromVersion = Version.valueOf(info.getAs("Version", TagString.class).getStringData()); } else if (info.containsKeyAs("Version", TagInt.class)) { fromVersion = Version.values()[info.getAs("Version", TagInt.class).getIntData() + 1]; } else { fromVersion = Version.values()[info.getAs("Version", TagShort.class).getShortData()]; } } for (Version v : Version.values()) { if (v.ordinal() <= fromVersion.ordinal()) { continue; } if (v.ordinal() > toVersion.ordinal()) { break; } try { Method m = this.getClass().getDeclaredMethod(v.name(), StoredMyPet.class); m.invoke(this, pet); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { } } } }
return new TagByteArray(((NBTTagByteArray) vanillaTag).c()); case 8: return new TagString(((NBTTagString) vanillaTag).a_()); case 9: NBTTagList tagList = (NBTTagList) vanillaTag;
return new NBTTagShort(((TagShort) tag).getShortData()); case String: return new NBTTagString(((TagString) tag).getStringData()); case Byte: return new NBTTagByte(((TagByte) tag).getByteData());