use of net.minecraft.nbt.LongArrayTag 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.LongArrayTag 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;
}
}
Aggregations