Search in sources :

Example 11 with ByteTag

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

the class FireworkRocketTranslator method translateToBedrock.

@Override
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
    CompoundTag fireworks = itemTag.get("Fireworks");
    if (fireworks == null) {
        return;
    }
    if (fireworks.get("Flight") != null) {
        fireworks.put(new ByteTag("Flight", MathUtils.getNbtByte(fireworks.get("Flight").getValue())));
    }
    ListTag explosions = fireworks.get("Explosions");
    if (explosions == null) {
        return;
    }
    for (Tag effect : explosions.getValue()) {
        CompoundTag effectData = (CompoundTag) effect;
        CompoundTag newEffectData = translateExplosionToBedrock(effectData, "");
        explosions.remove(effectData);
        explosions.add(newEffectData);
    }
}
Also used : ByteTag(com.github.steveice10.opennbt.tag.builtin.ByteTag) ByteTag(com.github.steveice10.opennbt.tag.builtin.ByteTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) 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 12 with ByteTag

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

the class Inventory method setItem.

public void setItem(int slot, @Nonnull GeyserItemStack newItem, GeyserSession session) {
    if (slot > this.size) {
        session.getGeyser().getLogger().debug("Tried to set an item out of bounds! " + this);
        return;
    }
    GeyserItemStack oldItem = items[slot];
    updateItemNetId(oldItem, newItem, session);
    items[slot] = newItem;
    // Lodestone caching
    if (newItem.getJavaId() == session.getItemMappings().getStoredItems().compass().getJavaId()) {
        CompoundTag nbt = newItem.getNbt();
        if (nbt != null) {
            Tag lodestoneTag = nbt.get("LodestoneTracked");
            if (lodestoneTag instanceof ByteTag) {
                session.getLodestoneCache().cacheInventoryItem(newItem);
            }
        }
    }
}
Also used : ByteTag(com.github.steveice10.opennbt.tag.builtin.ByteTag) ByteTag(com.github.steveice10.opennbt.tag.builtin.ByteTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 13 with ByteTag

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

the class EntityPackets method createOverworldCavesEntry.

private static CompoundTag createOverworldCavesEntry() {
    CompoundTag tag = new CompoundTag();
    tag.put("name", new StringTag("minecraft:overworld_caves"));
    tag.put("has_ceiling", new ByteTag((byte) 1));
    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 14 with ByteTag

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

the class EntityPackets method createNetherEntry.

private static CompoundTag createNetherEntry() {
    CompoundTag tag = new CompoundTag();
    tag.put("piglin_safe", new ByteTag((byte) 1));
    tag.put("natural", new ByteTag((byte) 0));
    tag.put("ambient_light", new FloatTag(0.1F));
    tag.put("infiniburn", new StringTag("minecraft:infiniburn_nether"));
    tag.put("respawn_anchor_works", new ByteTag((byte) 1));
    tag.put("has_skylight", new ByteTag((byte) 0));
    tag.put("bed_works", new ByteTag((byte) 0));
    tag.put("fixed_time", new LongTag(18000));
    tag.put("has_raids", new ByteTag((byte) 0));
    tag.put("name", new StringTag("minecraft:the_nether"));
    tag.put("logical_height", new IntTag(128));
    tag.put("shrunk", new ByteTag((byte) 1));
    tag.put("ultrawarm", new ByteTag((byte) 1));
    tag.put("has_ceiling", new ByteTag((byte) 1));
    return tag;
}
Also used : StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) FloatTag(com.github.steveice10.opennbt.tag.builtin.FloatTag) ByteTag(com.github.steveice10.opennbt.tag.builtin.ByteTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) IntTag(com.github.steveice10.opennbt.tag.builtin.IntTag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag)

Example 15 with ByteTag

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

the class TagStringReader method scalar.

/**
 * A tag that is definitely some sort of scalar.
 *
 * <p>Does not detect quoted strings, so those should have been parsed already.</p>
 *
 * @return a parsed tag
 */
private Tag scalar() {
    final StringBuilder builder = new StringBuilder();
    int noLongerNumericAt = -1;
    while (this.buffer.hasMore()) {
        char current = this.buffer.peek();
        if (current == '\\') {
            // escape -- we are significantly more lenient than original format at the moment
            this.buffer.advance();
            current = this.buffer.take();
        } else if (Tokens.id(current)) {
            this.buffer.advance();
        } else {
            // end of value
            break;
        }
        builder.append(current);
        if (noLongerNumericAt == -1 && !Tokens.numeric(current)) {
            noLongerNumericAt = builder.length();
        }
    }
    final int length = builder.length();
    final String built = builder.toString();
    if (noLongerNumericAt == length) {
        final char last = built.charAt(length - 1);
        try {
            switch(// try to read and return as a number
            Character.toLowerCase(last)) {
                case Tokens.TYPE_BYTE:
                    return new ByteTag(Byte.parseByte(built.substring(0, length - 1)));
                case Tokens.TYPE_SHORT:
                    return new ShortTag(Short.parseShort(built.substring(0, length - 1)));
                case Tokens.TYPE_INT:
                    return new IntTag(Integer.parseInt(built.substring(0, length - 1)));
                case Tokens.TYPE_LONG:
                    return new LongTag(Long.parseLong(built.substring(0, length - 1)));
                case Tokens.TYPE_FLOAT:
                    final float floatValue = Float.parseFloat(built.substring(0, length - 1));
                    if (Float.isFinite(floatValue)) {
                        // don't accept NaN and Infinity
                        return new FloatTag(floatValue);
                    }
                    break;
                case Tokens.TYPE_DOUBLE:
                    final double doubleValue = Double.parseDouble(built.substring(0, length - 1));
                    if (Double.isFinite(doubleValue)) {
                        // don't accept NaN and Infinity
                        return new DoubleTag(doubleValue);
                    }
                    break;
            }
        } catch (final NumberFormatException ignored) {
        }
    } else if (noLongerNumericAt == -1) {
        // if we run out of content without an explicit value separator, then we're either an integer or string tag -- all others have a character at the end
        try {
            return new IntTag(Integer.parseInt(built));
        } catch (final NumberFormatException ex) {
            if (built.indexOf('.') != -1) {
                try {
                    return new DoubleTag(Double.parseDouble(built));
                } catch (final NumberFormatException ex2) {
                // ignore
                }
            }
        }
    }
    if (built.equalsIgnoreCase(Tokens.LITERAL_TRUE)) {
        return new ByteTag((byte) 1);
    } else if (built.equalsIgnoreCase(Tokens.LITERAL_FALSE)) {
        return new ByteTag((byte) 0);
    }
    return new StringTag(built);
}
Also used : StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) DoubleTag(com.github.steveice10.opennbt.tag.builtin.DoubleTag) ShortTag(com.github.steveice10.opennbt.tag.builtin.ShortTag) FloatTag(com.github.steveice10.opennbt.tag.builtin.FloatTag) ByteTag(com.github.steveice10.opennbt.tag.builtin.ByteTag) IntTag(com.github.steveice10.opennbt.tag.builtin.IntTag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag)

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