Search in sources :

Example 26 with CompoundTag

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

the class Item method setCustomBlockData.

public Item setCustomBlockData(CompoundTag compoundTag) {
    CompoundTag tags = compoundTag.copy();
    tags.setName("BlockEntityTag");
    CompoundTag tag;
    if (!this.hasCompoundTag()) {
        tag = new CompoundTag();
    } else {
        tag = this.getNamedTag();
    }
    tag.putCompound("BlockEntityTag", tags);
    this.setNamedTag(tag);
    return this;
}
Also used : CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 27 with CompoundTag

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

the class Item method addEnchantment.

public void addEnchantment(Enchantment... enchantments) {
    CompoundTag tag;
    if (!this.hasCompoundTag()) {
        tag = new CompoundTag();
    } else {
        tag = this.getNamedTag();
    }
    ListTag<CompoundTag> ench;
    if (!tag.contains("ench")) {
        ench = new ListTag<>("ench");
        tag.putList(ench);
    } else {
        ench = tag.getList("ench", CompoundTag.class);
    }
    for (Enchantment enchantment : enchantments) {
        boolean found = false;
        for (int k = 0; k < ench.size(); k++) {
            CompoundTag entry = ench.get(k);
            if (entry.getShort("id") == enchantment.getId()) {
                ench.add(k, new CompoundTag().putShort("id", enchantment.getId()).putShort("lvl", enchantment.getLevel()));
                found = true;
                break;
            }
        }
        if (!found) {
            ench.add(new CompoundTag().putShort("id", enchantment.getId()).putShort("lvl", enchantment.getLevel()));
        }
    }
    this.setNamedTag(tag);
}
Also used : Enchantment(cn.nukkit.item.enchantment.Enchantment) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 28 with CompoundTag

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

the class Item method setCustomName.

public Item setCustomName(String name) {
    if (name == null || name.equals("")) {
        this.clearCustomName();
    }
    CompoundTag tag;
    if (!this.hasCompoundTag()) {
        tag = new CompoundTag();
    } else {
        tag = this.getNamedTag();
    }
    if (tag.contains("display") && tag.get("display") instanceof CompoundTag) {
        tag.getCompound("display").putString("Name", name);
    } else {
        tag.putCompound("display", new CompoundTag("display").putString("Name", name));
    }
    this.setNamedTag(tag);
    return this;
}
Also used : CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 29 with CompoundTag

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

the class Item method clearCustomBlockData.

public Item clearCustomBlockData() {
    if (!this.hasCompoundTag()) {
        return this;
    }
    CompoundTag tag = this.getNamedTag();
    if (tag.contains("BlockEntityTag") && tag.get("BlockEntityTag") instanceof CompoundTag) {
        tag.remove("BlockEntityTag");
        this.setNamedTag(tag);
    }
    return this;
}
Also used : CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 30 with CompoundTag

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

the class ItemBoat method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (face != BlockFace.UP)
        return false;
    EntityBoat boat = new EntityBoat(level.getChunk(block.getFloorX() >> 4, block.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", block.getX() + 0.5)).add(new DoubleTag("", block.getY() - 0.0625)).add(new DoubleTag("", block.getZ() + 0.5))).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", (float) ((player.yaw + 90f) % 360))).add(new FloatTag("", 0))).putByte("woodID", this.getDamage()));
    if (player.isSurvival()) {
        Item item = player.getInventory().getItemInHand();
        item.setCount(item.getCount() - 1);
        player.getInventory().setItemInHand(item);
    }
    boat.spawnToAll();
    return true;
}
Also used : FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityBoat(cn.nukkit.entity.item.EntityBoat) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) 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