Search in sources :

Example 56 with CompoundTag

use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.

the class Item method setLore.

public Item setLore(String... lines) {
    CompoundTag tag;
    if (!this.hasCompoundTag()) {
        tag = new CompoundTag();
    } else {
        tag = this.getNamedTag();
    }
    ListTag<StringTag> lore = new ListTag<>("Lore");
    for (String line : lines) {
        lore.add(new StringTag("", line));
    }
    if (!tag.contains("display")) {
        tag.putCompound("display", new CompoundTag("display").putList(lore));
    } else {
        tag.getCompound("display").putList(lore);
    }
    this.setNamedTag(tag);
    return this;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 57 with CompoundTag

use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.

the class Item method getEnchantments.

public Enchantment[] getEnchantments() {
    if (!this.hasEnchantments()) {
        return new Enchantment[0];
    }
    List<Enchantment> enchantments = new ArrayList<>();
    ListTag<CompoundTag> ench = this.getNamedTag().getList("ench", CompoundTag.class);
    for (CompoundTag entry : ench.getAll()) {
        Enchantment e = Enchantment.getEnchantment(entry.getShort("id"));
        if (e != null) {
            e.setLevel(entry.getShort("lvl"));
            enchantments.add(e);
        }
    }
    return enchantments.stream().toArray(Enchantment[]::new);
}
Also used : ArrayList(java.util.ArrayList) Enchantment(cn.nukkit.item.enchantment.Enchantment) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 58 with CompoundTag

use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.

the class Item method getLore.

public String[] getLore() {
    Tag tag = this.getNamedTagEntry("display");
    ArrayList<String> lines = new ArrayList<>();
    if (tag instanceof CompoundTag) {
        CompoundTag nbt = (CompoundTag) tag;
        ListTag<StringTag> lore = nbt.getList("Lore", StringTag.class);
        if (lore.size() > 0) {
            for (StringTag stringTag : lore.getAll()) {
                lines.add(stringTag.data);
            }
        }
    }
    return lines.toArray(new String[0]);
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) ArrayList(java.util.ArrayList) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) StringTag(cn.nukkit.nbt.tag.StringTag) Tag(cn.nukkit.nbt.tag.Tag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 59 with CompoundTag

use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.

the class ItemBookWritten method getPages.

public String[] getPages() {
    if (!this.isWritten)
        return new String[0];
    ListTag<CompoundTag> tag = (ListTag<CompoundTag>) this.getNamedTag().getList("pages");
    String[] pages = new String[tag.size()];
    int i = 0;
    for (CompoundTag pageCompound : tag.getAll()) {
        pages[i] = pageCompound.getString("text");
        i++;
    }
    return pages;
}
Also used : ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 60 with CompoundTag

use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.

the class BlockPistonBase method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (Math.abs(player.x - this.x) < 2 && Math.abs(player.z - this.z) < 2) {
        double y = player.y + player.getEyeHeight();
        if (y - this.y > 2) {
            this.setDamage(BlockFace.UP.getIndex());
        } else if (this.y - y > 0) {
            this.setDamage(BlockFace.DOWN.getIndex());
        } else {
            this.setDamage(player.getHorizontalFacing().getIndex());
        }
    } else {
        this.setDamage(player.getHorizontalFacing().getIndex());
    }
    this.level.setBlock(block, this, true, false);
    CompoundTag nbt = new CompoundTag("").putString("id", BlockEntity.PISTON_ARM).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z).putBoolean("Sticky", this.sticky);
    BlockEntityPistonArm be = new BlockEntityPistonArm(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
    // this.checkState();
    return true;
}
Also used : BlockEntityPistonArm(cn.nukkit.blockentity.BlockEntityPistonArm) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Aggregations

CompoundTag (cn.nukkit.nbt.tag.CompoundTag)74 ListTag (cn.nukkit.nbt.tag.ListTag)28 BlockEntity (cn.nukkit.blockentity.BlockEntity)13 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)13 FloatTag (cn.nukkit.nbt.tag.FloatTag)13 Tag (cn.nukkit.nbt.tag.Tag)13 StringTag (cn.nukkit.nbt.tag.StringTag)12 Map (java.util.Map)8 Entity (cn.nukkit.entity.Entity)7 IOException (java.io.IOException)7 Player (cn.nukkit.Player)5 BinaryStream (cn.nukkit.utils.BinaryStream)5 ArrayList (java.util.ArrayList)5 BlockRail (cn.nukkit.block.BlockRail)4 FullChunk (cn.nukkit.level.format.FullChunk)4 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)4 Rail (cn.nukkit.utils.Rail)4 File (java.io.File)4 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)3 BlockEntitySpawnable (cn.nukkit.blockentity.BlockEntitySpawnable)3