Search in sources :

Example 1 with IntArrayTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_16 method handleItemToServer.

@Override
public Item handleItemToServer(Item item) {
    if (item == null)
        return null;
    int identifier = item.identifier();
    super.handleItemToServer(item);
    CompoundTag tag = item.tag();
    if (identifier == 771 && tag != null) {
        Tag ownerTag = tag.get("SkullOwner");
        if (ownerTag instanceof CompoundTag) {
            CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
            Tag idTag = ownerCompundTag.get("Id");
            if (idTag instanceof StringTag) {
                UUID ownerUuid = UUID.fromString((String) idTag.getValue());
                ownerCompundTag.put("Id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(ownerUuid)));
            }
        }
    }
    InventoryPackets.oldToNewAttributes(item);
    enchantmentRewriter.handleToServer(item);
    return item;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) UUID(java.util.UUID) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 2 with IntArrayTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_12 method handleNbtToServer.

private void handleNbtToServer(CompoundTag compoundTag, CompoundTag backupTag) {
    // Restore the removed long array tags
    for (Map.Entry<String, Tag> entry : backupTag) {
        if (entry.getValue() instanceof CompoundTag) {
            CompoundTag nestedTag = compoundTag.get(entry.getKey());
            handleNbtToServer(nestedTag, (CompoundTag) entry.getValue());
        } else {
            compoundTag.put(entry.getKey(), fromIntArrayTag((IntArrayTag) entry.getValue()));
        }
    }
}
Also used : IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) Map(java.util.Map) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 3 with IntArrayTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_16_2 method handleBlockEntity.

private void handleBlockEntity(CompoundTag tag) {
    StringTag idTag = tag.get("id");
    if (idTag == null)
        return;
    if (idTag.getValue().equals("minecraft:skull")) {
        // Workaround an old client bug: MC-68487
        Tag skullOwnerTag = tag.get("SkullOwner");
        if (!(skullOwnerTag instanceof CompoundTag))
            return;
        CompoundTag skullOwnerCompoundTag = (CompoundTag) skullOwnerTag;
        if (!skullOwnerCompoundTag.contains("Id"))
            return;
        CompoundTag properties = skullOwnerCompoundTag.get("Properties");
        if (properties == null)
            return;
        ListTag textures = properties.get("textures");
        if (textures == null)
            return;
        CompoundTag first = textures.size() > 0 ? textures.get(0) : null;
        if (first == null)
            return;
        // Make the client cache the skinprofile over this uuid
        int hashCode = first.get("Value").getValue().hashCode();
        // TODO split texture in 4 for a lower collision chance
        int[] uuidIntArray = { hashCode, 0, 0, 0 };
        skullOwnerCompoundTag.put("Id", new IntArrayTag(uuidIntArray));
    }
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 4 with IntArrayTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_16 method handleBlockEntity.

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

Example 5 with IntArrayTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_16 method handleItemToClient.

@Override
public Item handleItemToClient(Item item) {
    if (item == null)
        return null;
    super.handleItemToClient(item);
    CompoundTag tag = item.tag();
    if (item.identifier() == 771 && tag != null) {
        Tag ownerTag = tag.get("SkullOwner");
        if (ownerTag instanceof CompoundTag) {
            CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
            Tag idTag = ownerCompundTag.get("Id");
            if (idTag instanceof IntArrayTag) {
                UUID ownerUuid = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue());
                ownerCompundTag.put("Id", new StringTag(ownerUuid.toString()));
            }
        }
    }
    InventoryPackets.newToOldAttributes(item);
    enchantmentRewriter.handleToClient(item);
    return item;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) UUID(java.util.UUID) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Aggregations

CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)5 IntArrayTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag)5 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)5 LongArrayTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag)4 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)4 UUID (java.util.UUID)3 ListTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)1 Map (java.util.Map)1