Search in sources :

Example 1 with IntArrayTag

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

the class FireworkBaseTranslator method translateExplosionToJava.

protected CompoundTag translateExplosionToJava(CompoundTag explosion, String newName) {
    CompoundTag newExplosionData = new CompoundTag(newName);
    if (explosion.get("FireworkType") != null) {
        newExplosionData.put(new ByteTag("Type", MathUtils.getNbtByte(explosion.get("FireworkType").getValue())));
    }
    if (explosion.get("FireworkColor") != null) {
        byte[] oldColors = (byte[]) explosion.get("FireworkColor").getValue();
        int[] colors = new int[oldColors.length];
        int i = 0;
        for (byte color : oldColors) {
            colors[i++] = FireworkColor.fromBedrockId(color);
        }
        newExplosionData.put(new IntArrayTag("Colors", colors));
    }
    if (explosion.get("FireworkFade") != null) {
        byte[] oldColors = (byte[]) explosion.get("FireworkFade").getValue();
        int[] colors = new int[oldColors.length];
        int i = 0;
        for (byte color : oldColors) {
            colors[i++] = FireworkColor.fromBedrockId(color);
        }
        newExplosionData.put(new IntArrayTag("FadeColors", colors));
    }
    if (explosion.get("FireworkTrail") != null) {
        newExplosionData.put(new ByteTag("Trail", MathUtils.getNbtByte(explosion.get("FireworkTrail").getValue())));
    }
    if (explosion.get("FireworkFlicker") != null) {
        newExplosionData.put(new ByteTag("Flicker", MathUtils.getNbtByte(explosion.get("FireworkFlicker").getValue())));
    }
    return newExplosionData;
}
Also used : IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) ByteTag(com.github.steveice10.opennbt.tag.builtin.ByteTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 2 with IntArrayTag

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

the class FireworkStarTranslator method translateToBedrock.

@Override
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
    Tag explosion = itemTag.get("Explosion");
    if (explosion instanceof CompoundTag) {
        CompoundTag newExplosion = translateExplosionToBedrock((CompoundTag) explosion, "FireworksItem");
        itemTag.remove("Explosion");
        itemTag.put(newExplosion);
        Tag color = ((CompoundTag) explosion).get("Colors");
        if (color instanceof IntArrayTag) {
            // Determine the custom color, if any.
            // Mostly replicates Java's own rendering code, as Java determines the final firework star color client-side
            // while Bedrock determines it server-side.
            int[] colors = ((IntArrayTag) color).getValue();
            if (colors.length == 0) {
                return;
            }
            int finalColor;
            if (colors.length == 1) {
                finalColor = colors[0];
            } else {
                int r = 0;
                int g = 0;
                int b = 0;
                for (int fireworkColor : colors) {
                    r += (fireworkColor & (255 << 16)) >> 16;
                    g += (fireworkColor & (255 << 8)) >> 8;
                    b += fireworkColor & 255;
                }
                r /= colors.length;
                g /= colors.length;
                b /= colors.length;
                finalColor = r << 16 | g << 8 | b;
            }
            itemTag.put(new IntTag("customColor", finalColor));
        }
    }
}
Also used : IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) IntTag(com.github.steveice10.opennbt.tag.builtin.IntTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) IntTag(com.github.steveice10.opennbt.tag.builtin.IntTag)

Example 3 with IntArrayTag

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

the class TagStringReader method array.

/**
 * Similar to a list tag in syntax, but returning a single array tag rather than a list of tags.
 *
 * @return array-typed tag
 */
public Tag array(char elementType) throws StringTagParseException {
    this.buffer.expect(Tokens.ARRAY_BEGIN).expect(elementType).expect(Tokens.ARRAY_SIGNATURE_SEPARATOR);
    elementType = Character.toLowerCase(elementType);
    if (elementType == Tokens.TYPE_BYTE) {
        return new ByteArrayTag(this.byteArray());
    } else if (elementType == Tokens.TYPE_INT) {
        return new IntArrayTag(this.intArray());
    } else if (elementType == Tokens.TYPE_LONG) {
        return new LongArrayTag(this.longArray());
    } else {
        throw this.buffer.makeError("Type " + elementType + " is not a valid element type in an array!");
    }
}
Also used : IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) LongArrayTag(com.github.steveice10.opennbt.tag.builtin.LongArrayTag) ByteArrayTag(com.github.steveice10.opennbt.tag.builtin.ByteArrayTag)

Example 4 with IntArrayTag

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

the class InventoryPackets method handleItemToServer.

@Override
public Item handleItemToServer(Item item) {
    if (item == null)
        return null;
    item.setIdentifier(Protocol1_16To1_15_2.MAPPINGS.getOldItemId(item.identifier()));
    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 IntArrayTag) {
                UUID id = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue());
                ownerCompundTag.put("Id", new StringTag(id.toString()));
            }
        }
    }
    newToOldAttributes(item);
    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 5 with IntArrayTag

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

the class InventoryPackets method newToOldAttributes.

public static void newToOldAttributes(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", true);
        rewriteAttributeName(attribute, "Name", true);
        IntArrayTag uuidTag = attribute.get("UUID");
        if (uuidTag != null && uuidTag.getValue().length == 4) {
            UUID uuid = UUIDIntArrayType.uuidFromIntArray(uuidTag.getValue());
            attribute.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
            attribute.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
        }
    }
}
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) UUID(java.util.UUID) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag)

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