Search in sources :

Example 1 with ByteArrayTag

use of com.github.steveice10.opennbt.tag.builtin.ByteArrayTag 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 2 with ByteArrayTag

use of com.github.steveice10.opennbt.tag.builtin.ByteArrayTag 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 3 with ByteArrayTag

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

the class FireworkBaseTranslator method translateExplosionToBedrock.

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

Aggregations

ByteArrayTag (com.github.steveice10.opennbt.tag.builtin.ByteArrayTag)2 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)2 ByteTag (com.github.steveice10.opennbt.tag.builtin.ByteTag)1 IntArrayTag (com.github.steveice10.opennbt.tag.builtin.IntArrayTag)1 IntTag (com.github.steveice10.opennbt.tag.builtin.IntTag)1 LongArrayTag (com.github.steveice10.opennbt.tag.builtin.LongArrayTag)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