use of de.keyle.knbt.TagBase in project MyPet by xXKeyleXx.
the class MyStray method readExtendedInfo.
@SuppressWarnings("unchecked")
@Override
public void readExtendedInfo(TagCompound info) {
if (info.containsKey("Equipment")) {
TagList equipment = info.getAs("Equipment", TagList.class);
List<TagBase> equipmentList = (List<TagBase>) equipment.getData();
for (TagBase tag : equipmentList) {
if (tag instanceof TagCompound) {
TagCompound item = (TagCompound) tag;
try {
ItemStack itemStack = MyPetApi.getPlatformHelper().compundToItemStack(item);
setEquipment(EquipmentSlot.getSlotById(item.getAs("Slot", TagInt.class).getIntData()), itemStack);
} catch (Exception e) {
MyPetApi.getLogger().warning("Could not load Equipment item from pet data!");
}
}
}
}
}
use of de.keyle.knbt.TagBase in project MyPet by xXKeyleXx.
the class ItemStackNBTConverter method compoundToVanillaCompound.
public static Tag compoundToVanillaCompound(TagBase tag) {
switch(TagType.getTypeById(tag.getTagTypeId())) {
case Int:
return IntTag.valueOf(((TagInt) tag).getIntData());
case Short:
return ShortTag.valueOf(((TagShort) tag).getShortData());
case String:
return StringTag.valueOf(((TagString) tag).getStringData());
case Byte:
return ByteTag.valueOf(((TagByte) tag).getByteData());
case Byte_Array:
return new ByteArrayTag(((TagByteArray) tag).getByteArrayData());
case Double:
return DoubleTag.valueOf(((TagDouble) tag).getDoubleData());
case Float:
return FloatTag.valueOf(((TagFloat) tag).getFloatData());
case Int_Array:
return new IntArrayTag(((TagIntArray) tag).getIntArrayData());
case Long:
return LongTag.valueOf(((TagLong) tag).getLongData());
case List:
TagList TagList = (TagList) tag;
ListTag tagList = new ListTag();
for (TagBase tagInList : TagList.getReadOnlyList()) {
tagList.add(compoundToVanillaCompound(tagInList));
}
return tagList;
case Compound:
TagCompound TagCompound = (TagCompound) tag;
CompoundTag tagCompound = new CompoundTag();
for (String name : TagCompound.getCompoundData().keySet()) {
tagCompound.put(name, compoundToVanillaCompound(TagCompound.getCompoundData().get(name)));
}
return tagCompound;
case End:
return null;
}
throw new IllegalArgumentException("Not a valid tag type");
}
use of de.keyle.knbt.TagBase in project MyPet by xXKeyleXx.
the class ConfigurationNBT method load.
public boolean load() {
if (!NBTFile.exists()) {
return false;
}
try {
InputStream is = new FileInputStream(NBTFile);
TagBase tag = TagStream.readTag(is, true);
if (tag != null) {
nbtTagCompound = (TagCompound) tag;
return true;
}
tag = TagStream.readTag(is, false);
if (tag != null) {
nbtTagCompound = (TagCompound) tag;
return true;
} else {
MyPetApi.getLogger().warning("Could not parse/load " + NBTFile.getName());
return false;
}
} catch (IOException e) {
return false;
}
}
use of de.keyle.knbt.TagBase in project MyPet by xXKeyleXx.
the class ItemStackNBTConverter method compoundToVanillaCompound.
public static Tag compoundToVanillaCompound(TagBase tag) {
switch(TagType.getTypeById(tag.getTagTypeId())) {
case Int:
return IntTag.valueOf(((TagInt) tag).getIntData());
case Short:
return ShortTag.valueOf(((TagShort) tag).getShortData());
case String:
return StringTag.valueOf(((TagString) tag).getStringData());
case Byte:
return ByteTag.valueOf(((TagByte) tag).getByteData());
case Byte_Array:
return new ByteArrayTag(((TagByteArray) tag).getByteArrayData());
case Double:
return DoubleTag.valueOf(((TagDouble) tag).getDoubleData());
case Float:
return FloatTag.valueOf(((TagFloat) tag).getFloatData());
case Int_Array:
return new IntArrayTag(((TagIntArray) tag).getIntArrayData());
case Long:
return LongTag.valueOf(((TagLong) tag).getLongData());
case List:
TagList TagList = (TagList) tag;
ListTag tagList = new ListTag();
for (TagBase tagInList : TagList.getReadOnlyList()) {
tagList.add(compoundToVanillaCompound(tagInList));
}
return tagList;
case Compound:
TagCompound TagCompound = (TagCompound) tag;
CompoundTag tagCompound = new CompoundTag();
for (String name : TagCompound.getCompoundData().keySet()) {
tagCompound.put(name, compoundToVanillaCompound(TagCompound.getCompoundData().get(name)));
}
return tagCompound;
case End:
return null;
}
throw new IllegalArgumentException("Not a valid tag type");
}
use of de.keyle.knbt.TagBase in project MyPet by xXKeyleXx.
the class MyGiant method readExtendedInfo.
@SuppressWarnings("unchecked")
@Override
public void readExtendedInfo(TagCompound info) {
if (info.containsKey("Equipment")) {
TagList equipment = info.get("Equipment");
List<TagBase> equipmentList = (List<TagBase>) equipment.getData();
for (TagBase tag : equipmentList) {
if (tag instanceof TagCompound) {
TagCompound item = (TagCompound) tag;
try {
ItemStack itemStack = MyPetApi.getPlatformHelper().compundToItemStack(item);
setEquipment(EquipmentSlot.getSlotById(item.getAs("Slot", TagInt.class).getIntData()), itemStack);
} catch (Exception e) {
MyPetApi.getLogger().warning("Could not load Equipment item from pet data!");
}
}
}
}
}
Aggregations