Search in sources :

Example 6 with IntArrayTag

use of com.github.steveice10.opennbt.tag.builtin.IntArrayTag in project ViaVersion by ViaVersion.

the class InventoryPackets method oldToNewAttributes.

public static void oldToNewAttributes(Item item) {
    if (item.tag() == null)
        return;
    ListTag attributes = item.tag().get("AttributeModifiers");
    if (attributes == null)
        return;
    for (Tag tag : attributes) {
        CompoundTag attribute = (CompoundTag) tag;
        rewriteAttributeName(attribute, "AttributeName", false);
        rewriteAttributeName(attribute, "Name", false);
        Tag leastTag = attribute.get("UUIDLeast");
        if (leastTag != null) {
            Tag mostTag = attribute.get("UUIDMost");
            int[] uuidIntArray = UUIDIntArrayType.bitsToIntArray(((NumberTag) leastTag).asLong(), ((NumberTag) mostTag).asLong());
            attribute.put("UUID", new IntArrayTag(uuidIntArray));
        }
    }
}
Also used : IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 7 with IntArrayTag

use of com.github.steveice10.opennbt.tag.builtin.IntArrayTag in project ViaVersion by ViaVersion.

the class InventoryPackets method handleItemToClient.

@Override
public Item handleItemToClient(Item item) {
    if (item == null)
        return null;
    if (item.identifier() == 771 && item.tag() != null) {
        CompoundTag tag = item.tag();
        Tag ownerTag = tag.get("SkullOwner");
        if (ownerTag instanceof CompoundTag) {
            CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
            Tag idTag = ownerCompundTag.get("Id");
            if (idTag instanceof StringTag) {
                UUID id = UUID.fromString((String) idTag.getValue());
                ownerCompundTag.put("Id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(id)));
            }
        }
    }
    oldToNewAttributes(item);
    item.setIdentifier(Protocol1_16To1_15_2.MAPPINGS.getNewItemId(item.identifier()));
    return item;
}
Also used : StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) UUID(java.util.UUID) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 8 with IntArrayTag

use of com.github.steveice10.opennbt.tag.builtin.IntArrayTag 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)

Example 9 with IntArrayTag

use of com.github.steveice10.opennbt.tag.builtin.IntArrayTag in project ViaVersion by ViaVersion.

the class WorldPackets method handleBlockEntity.

private static void handleBlockEntity(CompoundTag compoundTag) {
    StringTag idTag = compoundTag.get("id");
    if (idTag == null)
        return;
    String id = idTag.getValue();
    if (id.equals("minecraft:conduit")) {
        Tag targetUuidTag = compoundTag.remove("target_uuid");
        if (!(targetUuidTag instanceof StringTag))
            return;
        // target_uuid -> Target
        UUID targetUuid = UUID.fromString((String) targetUuidTag.getValue());
        compoundTag.put("Target", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(targetUuid)));
    } else if (id.equals("minecraft:skull") && compoundTag.get("Owner") instanceof CompoundTag) {
        CompoundTag ownerTag = compoundTag.remove("Owner");
        StringTag ownerUuidTag = ownerTag.remove("Id");
        if (ownerUuidTag != null) {
            UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue());
            ownerTag.put("Id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(ownerUuid)));
        }
        // Owner -> SkullOwner
        CompoundTag skullOwnerTag = new CompoundTag();
        for (Map.Entry<String, Tag> entry : ownerTag.entrySet()) {
            skullOwnerTag.put(entry.getKey(), entry.getValue());
        }
        compoundTag.put("SkullOwner", skullOwnerTag);
    }
}
Also used : StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) LongArrayTag(com.github.steveice10.opennbt.tag.builtin.LongArrayTag) UUID(java.util.UUID) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Aggregations

CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)8 IntArrayTag (com.github.steveice10.opennbt.tag.builtin.IntArrayTag)8 Tag (com.github.steveice10.opennbt.tag.builtin.Tag)7 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)6 ListTag (com.github.steveice10.opennbt.tag.builtin.ListTag)4 LongTag (com.github.steveice10.opennbt.tag.builtin.LongTag)4 NumberTag (com.github.steveice10.opennbt.tag.builtin.NumberTag)4 UUID (java.util.UUID)4 IntTag (com.github.steveice10.opennbt.tag.builtin.IntTag)2 LongArrayTag (com.github.steveice10.opennbt.tag.builtin.LongArrayTag)2 ByteArrayTag (com.github.steveice10.opennbt.tag.builtin.ByteArrayTag)1 ByteTag (com.github.steveice10.opennbt.tag.builtin.ByteTag)1 List (java.util.List)1 ListTag (org.dragonet.common.data.nbt.tag.ListTag)1