Search in sources :

Example 1 with ListTag

use of org.dragonet.common.data.nbt.tag.ListTag in project DragonProxy by DragonetMC.

the class ItemBlockTranslator method translateRawNBT.

@SuppressWarnings("unchecked")
public static org.dragonet.common.data.nbt.tag.CompoundTag translateRawNBT(int id, Tag pcTag, org.dragonet.common.data.nbt.tag.CompoundTag target) {
    if (pcTag != null) {
        String name = pcTag.getName() != null ? pcTag.getName() : "";
        if (target == null)
            target = new org.dragonet.common.data.nbt.tag.CompoundTag(name);
        switch(pcTag.getClass().getSimpleName()) {
            case "ByteArrayTag":
                target.putByteArray(name, (byte[]) pcTag.getValue());
                break;
            case "ByteTag":
                target.putByte(name, (byte) pcTag.getValue());
                break;
            case "DoubleTag":
                target.putDouble(name, (double) pcTag.getValue());
                break;
            case "FloatTag":
                target.putFloat(name, (float) pcTag.getValue());
                break;
            case "IntArrayTag":
                target.putIntArray(name, (int[]) pcTag.getValue());
                break;
            case "IntTag":
                target.putInt(name, (int) pcTag.getValue());
                break;
            case "LongTag":
                target.putLong(name, (long) pcTag.getValue());
                break;
            case "ShortTag":
                target.putShort(name, (short) pcTag.getValue());
                break;
            case "StringTag":
                target.putString(name, (String) pcTag.getValue());
                break;
            case "CompoundTag":
                for (String subName : ((CompoundTag) pcTag).getValue().keySet()) translateRawNBT(0, ((CompoundTag) pcTag).getValue().get(subName), target);
                break;
            case "ListTag":
                ListTag listTag = new ListTag();
                for (Tag subTag : (List<Tag>) pcTag.getValue()) listTag.add(translateRawNBT(0, subTag, new org.dragonet.common.data.nbt.tag.CompoundTag()));
                target.putList(listTag);
                break;
            default:
                System.out.println("TAG not implemented : " + pcTag.getClass().getSimpleName());
                break;
        }
    }
    return target;
}
Also used : List(java.util.List) IntTag(com.github.steveice10.opennbt.tag.builtin.IntTag) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) ListTag(org.dragonet.common.data.nbt.tag.ListTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) ListTag(org.dragonet.common.data.nbt.tag.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Aggregations

CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)1 IntTag (com.github.steveice10.opennbt.tag.builtin.IntTag)1 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)1 Tag (com.github.steveice10.opennbt.tag.builtin.Tag)1 List (java.util.List)1 ListTag (org.dragonet.common.data.nbt.tag.ListTag)1