Search in sources :

Example 6 with ByteTag

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

the class EntityPackets method createOverworldEntry.

private static CompoundTag createOverworldEntry() {
    CompoundTag tag = new CompoundTag();
    tag.put("name", new StringTag("minecraft:overworld"));
    tag.put("has_ceiling", new ByteTag((byte) 0));
    addSharedOverwaldEntries(tag);
    return tag;
}
Also used : StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) ByteTag(com.github.steveice10.opennbt.tag.builtin.ByteTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 7 with ByteTag

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

the class CommandBlockStorage method getCommandBlock.

public Optional<CompoundTag> getCommandBlock(Position position) {
    Pair<Integer, Integer> chunkCoords = getChunkCoords(position);
    Map<Position, CompoundTag> blocks = storedCommandBlocks.get(chunkCoords);
    if (blocks == null)
        return Optional.empty();
    CompoundTag tag = blocks.get(position);
    if (tag == null)
        return Optional.empty();
    tag = tag.clone();
    tag.put("powered", new ByteTag((byte) 0));
    tag.put("auto", new ByteTag((byte) 0));
    tag.put("conditionMet", new ByteTag((byte) 0));
    return Optional.of(tag);
}
Also used : Position(com.viaversion.viaversion.api.minecraft.Position) ByteTag(com.github.steveice10.opennbt.tag.builtin.ByteTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 8 with ByteTag

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

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

the class CrossbowTranslator method translateToBedrock.

@Override
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
    if (itemTag.get("ChargedProjectiles") != null) {
        ListTag chargedProjectiles = itemTag.get("ChargedProjectiles");
        if (!chargedProjectiles.getValue().isEmpty()) {
            CompoundTag projectile = (CompoundTag) chargedProjectiles.getValue().get(0);
            ItemMapping projectileMapping = session.getItemMappings().getMapping((String) projectile.get("id").getValue());
            if (projectileMapping == null)
                return;
            CompoundTag tag = projectile.get("tag");
            ItemStack itemStack = new ItemStack(mapping.getJavaId(), (byte) projectile.get("Count").getValue(), tag);
            ItemData itemData = ItemTranslator.translateToBedrock(session, itemStack);
            CompoundTag newProjectile = new CompoundTag("chargedItem");
            newProjectile.put(new ByteTag("Count", (byte) itemData.getCount()));
            newProjectile.put(new StringTag("Name", projectileMapping.getBedrockIdentifier()));
            newProjectile.put(new ShortTag("Damage", (short) itemData.getDamage()));
            itemTag.put(newProjectile);
        }
    }
}
Also used : ItemMapping(org.geysermc.geyser.registry.type.ItemMapping) ItemStack(com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 10 with ByteTag

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

ByteTag (com.github.steveice10.opennbt.tag.builtin.ByteTag)13 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)11 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)8 IntTag (com.github.steveice10.opennbt.tag.builtin.IntTag)5 FloatTag (com.github.steveice10.opennbt.tag.builtin.FloatTag)4 Tag (com.github.steveice10.opennbt.tag.builtin.Tag)4 LongTag (com.github.steveice10.opennbt.tag.builtin.LongTag)3 ListTag (com.github.steveice10.opennbt.tag.builtin.ListTag)2 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)1 ByteArrayTag (com.github.steveice10.opennbt.tag.builtin.ByteArrayTag)1 DoubleTag (com.github.steveice10.opennbt.tag.builtin.DoubleTag)1 IntArrayTag (com.github.steveice10.opennbt.tag.builtin.IntArrayTag)1 ShortTag (com.github.steveice10.opennbt.tag.builtin.ShortTag)1 ItemData (com.nukkitx.protocol.bedrock.data.inventory.ItemData)1 Position (com.viaversion.viaversion.api.minecraft.Position)1 List (java.util.List)1 ListTag (org.dragonet.common.data.nbt.tag.ListTag)1 ItemMapping (org.geysermc.geyser.registry.type.ItemMapping)1