use of net.minecraft.nbt.FloatTag in project MyPet by xXKeyleXx.
the class ItemStackNBTConverter method vanillaCompoundToCompound.
public static TagBase vanillaCompoundToCompound(Tag vanillaTag) {
switch(vanillaTag.getId()) {
case 1:
return new TagByte(((ByteTag) vanillaTag).getAsByte());
case 2:
return new TagShort(((ShortTag) vanillaTag).getAsShort());
case 3:
return new TagInt(((IntTag) vanillaTag).getAsInt());
case 4:
return new TagLong(((LongTag) vanillaTag).getAsLong());
case 5:
return new TagFloat(((FloatTag) vanillaTag).getAsFloat());
case 6:
return new TagDouble(((DoubleTag) vanillaTag).getAsDouble());
case 7:
return new TagByteArray(((ByteArrayTag) vanillaTag).getAsByteArray());
case 8:
return new TagString(vanillaTag.getAsString());
case 9:
ListTag tagList = (ListTag) vanillaTag;
List compoundList = new ArrayList();
try {
ArrayList list = (ArrayList) TAG_LIST_LIST.get(tagList);
for (Object aList : list) {
compoundList.add(vanillaCompoundToCompound((Tag) aList));
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return new TagList(compoundList);
case 10:
TagCompound compound = new TagCompound();
CompoundTag tagCompound = ((CompoundTag) vanillaTag);
Set<String> keys = tagCompound.getAllKeys();
for (String tagName : keys) {
compound.getCompoundData().put(tagName, vanillaCompoundToCompound(tagCompound.get(tagName)));
}
return compound;
case 11:
return new TagIntArray(((IntArrayTag) vanillaTag).getAsIntArray());
}
return null;
}
use of net.minecraft.nbt.FloatTag in project SpongeCommon by SpongePowered.
the class NBTTranslator method setInternal.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void setInternal(Tag base, byte type, DataView view, String key) {
checkNotNull(base);
checkNotNull(view);
checkNotNull(key);
checkArgument(!key.isEmpty());
checkArgument(type > Constants.NBT.TAG_END && type <= Constants.NBT.TAG_INT_ARRAY);
switch(type) {
case Constants.NBT.TAG_BYTE:
if (key.contains(NBTTranslator.BOOLEAN_IDENTIFIER)) {
view.set(of(key.replace(NBTTranslator.BOOLEAN_IDENTIFIER, "")), (((ByteTag) base).getAsByte() != 0));
} else {
view.set(of(key), ((ByteTag) base).getAsByte());
}
break;
case Constants.NBT.TAG_SHORT:
view.set(of(key), ((ShortTag) base).getAsShort());
break;
case Constants.NBT.TAG_INT:
view.set(of(key), ((IntTag) base).getAsInt());
break;
case Constants.NBT.TAG_LONG:
view.set(of(key), ((LongTag) base).getAsLong());
break;
case Constants.NBT.TAG_FLOAT:
view.set(of(key), ((FloatTag) base).getAsFloat());
break;
case Constants.NBT.TAG_DOUBLE:
view.set(of(key), ((DoubleTag) base).getAsDouble());
break;
case Constants.NBT.TAG_BYTE_ARRAY:
view.set(of(key), ((ByteArrayTag) base).getAsByteArray());
break;
case Constants.NBT.TAG_STRING:
view.set(of(key), base.getAsString());
break;
case Constants.NBT.TAG_LIST:
ListTag list = (ListTag) base;
byte listType = list.getElementType();
int count = list.size();
List objectList = Lists.newArrayListWithCapacity(count);
for (final Tag inbt : list) {
objectList.add(NBTTranslator.fromTagBase(inbt, listType));
}
view.set(of(key), objectList);
break;
case Constants.NBT.TAG_COMPOUND:
DataView internalView = view.createView(of(key));
CompoundTag compound = (CompoundTag) base;
for (String internalKey : compound.getAllKeys()) {
Tag internalBase = compound.get(internalKey);
byte internalType = internalBase.getId();
// Basically.... more recursion.
// Reasoning: This avoids creating a new DataContainer which would
// then be copied in to the owning DataView anyways. We can internally
// set the actual data directly to the child view instead.
NBTTranslator.setInternal(internalBase, internalType, internalView, internalKey);
}
break;
case Constants.NBT.TAG_INT_ARRAY:
view.set(of(key), ((IntArrayTag) base).getAsIntArray());
break;
case Constants.NBT.TAG_LONG_ARRAY:
view.set(of(key), ((LongArrayTag) base).getAsLongArray());
break;
default:
throw new IllegalArgumentException("Unknown NBT type " + type);
}
}
use of net.minecraft.nbt.FloatTag in project SpongeCommon by SpongePowered.
the class NBTTranslator method fromTagBase.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Object fromTagBase(Tag base, byte type) {
switch(type) {
case Constants.NBT.TAG_BYTE:
return ((ByteTag) base).getAsByte();
case Constants.NBT.TAG_SHORT:
return (((ShortTag) base)).getAsShort();
case Constants.NBT.TAG_INT:
return ((IntTag) base).getAsInt();
case Constants.NBT.TAG_LONG:
return ((LongTag) base).getAsLong();
case Constants.NBT.TAG_FLOAT:
return ((FloatTag) base).getAsFloat();
case Constants.NBT.TAG_DOUBLE:
return ((DoubleTag) base).getAsDouble();
case Constants.NBT.TAG_BYTE_ARRAY:
return ((ByteArrayTag) base).getAsByteArray();
case Constants.NBT.TAG_STRING:
return base.getAsString();
case Constants.NBT.TAG_LIST:
ListTag list = (ListTag) base;
byte listType = list.getElementType();
int count = list.size();
List objectList = Lists.newArrayListWithCapacity(count);
for (Tag inbt : list) {
objectList.add(NBTTranslator.fromTagBase(inbt, listType));
}
return objectList;
case Constants.NBT.TAG_COMPOUND:
return NBTTranslator.getViewFromCompound((CompoundTag) base);
case Constants.NBT.TAG_INT_ARRAY:
return ((IntArrayTag) base).getAsIntArray();
case Constants.NBT.TAG_LONG_ARRAY:
return ((LongArrayTag) base).getAsLongArray();
default:
return null;
}
}
use of net.minecraft.nbt.FloatTag in project MyPet by xXKeyleXx.
the class ItemStackNBTConverter method vanillaCompoundToCompound.
public static TagBase vanillaCompoundToCompound(Tag vanillaTag) {
switch(vanillaTag.getId()) {
case 1:
return new TagByte(((ByteTag) vanillaTag).getAsByte());
case 2:
return new TagShort(((ShortTag) vanillaTag).getAsShort());
case 3:
return new TagInt(((IntTag) vanillaTag).getAsInt());
case 4:
return new TagLong(((LongTag) vanillaTag).getAsLong());
case 5:
return new TagFloat(((FloatTag) vanillaTag).getAsFloat());
case 6:
return new TagDouble(((DoubleTag) vanillaTag).getAsDouble());
case 7:
return new TagByteArray(((ByteArrayTag) vanillaTag).getAsByteArray());
case 8:
return new TagString(vanillaTag.getAsString());
case 9:
ListTag tagList = (ListTag) vanillaTag;
List compoundList = new ArrayList();
try {
ArrayList list = (ArrayList) TAG_LIST_LIST.get(tagList);
for (Object aList : list) {
compoundList.add(vanillaCompoundToCompound((Tag) aList));
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return new TagList(compoundList);
case 10:
TagCompound compound = new TagCompound();
CompoundTag tagCompound = ((CompoundTag) vanillaTag);
Set<String> keys = tagCompound.getAllKeys();
for (String tagName : keys) {
compound.getCompoundData().put(tagName, vanillaCompoundToCompound(tagCompound.get(tagName)));
}
return compound;
case 11:
return new TagIntArray(((IntArrayTag) vanillaTag).getAsIntArray());
}
return null;
}
Aggregations