Search in sources :

Example 21 with ListTag

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

the class ItemMinecartTNT method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartTNT minecart = new EntityMinecartTNT(level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<>("Pos").add(new DoubleTag("", target.getX() + 0.5)).add(new DoubleTag("", target.getY() + 0.0625D + adjacent)).add(new DoubleTag("", target.getZ() + 0.5))).putList(new ListTag<>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))));
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
Also used : BlockRail(cn.nukkit.block.BlockRail) Rail(cn.nukkit.utils.Rail) FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityMinecartTNT(cn.nukkit.entity.item.EntityMinecartTNT) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) BlockRail(cn.nukkit.block.BlockRail) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 22 with ListTag

use of cn.nukkit.nbt.tag.ListTag 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 23 with ListTag

use of cn.nukkit.nbt.tag.ListTag 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 24 with ListTag

use of cn.nukkit.nbt.tag.ListTag 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 25 with ListTag

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

the class BlockChest method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    BlockEntityChest chest = null;
    int[] faces = { 2, 5, 3, 4 };
    this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
    for (int side = 2; side <= 5; ++side) {
        if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == 4 || side == 5)) {
            continue;
        } else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == 2 || side == 3)) {
            continue;
        }
        Block c = this.getSide(BlockFace.fromIndex(side));
        if (c instanceof BlockChest && c.getDamage() == this.getDamage()) {
            BlockEntity blockEntity = this.getLevel().getBlockEntity(c);
            if (blockEntity instanceof BlockEntityChest && !((BlockEntityChest) blockEntity).isPaired()) {
                chest = (BlockEntityChest) blockEntity;
                break;
            }
        }
    }
    this.getLevel().setBlock(block, this, true, true);
    CompoundTag nbt = new CompoundTag("").putList(new ListTag<>("Items")).putString("id", BlockEntity.CHEST).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
    if (item.hasCustomName()) {
        nbt.putString("CustomName", item.getCustomName());
    }
    if (item.hasCustomBlockData()) {
        Map<String, Tag> customData = item.getCustomBlockData().getTags();
        for (Map.Entry<String, Tag> tag : customData.entrySet()) {
            nbt.put(tag.getKey(), tag.getValue());
        }
    }
    BlockEntity blockEntity = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
    if (chest != null) {
        chest.pairWith(((BlockEntityChest) blockEntity));
        ((BlockEntityChest) blockEntity).pairWith(chest);
    }
    return true;
}
Also used : BlockEntityChest(cn.nukkit.blockentity.BlockEntityChest) StringTag(cn.nukkit.nbt.tag.StringTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) ListTag(cn.nukkit.nbt.tag.ListTag) Map(java.util.Map) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Aggregations

CompoundTag (cn.nukkit.nbt.tag.CompoundTag)27 ListTag (cn.nukkit.nbt.tag.ListTag)27 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)13 FloatTag (cn.nukkit.nbt.tag.FloatTag)13 Entity (cn.nukkit.entity.Entity)5 StringTag (cn.nukkit.nbt.tag.StringTag)5 Tag (cn.nukkit.nbt.tag.Tag)5 BlockRail (cn.nukkit.block.BlockRail)4 BlockEntity (cn.nukkit.blockentity.BlockEntity)4 Rail (cn.nukkit.utils.Rail)4 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 Player (cn.nukkit.Player)2 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)2 EntityProjectile (cn.nukkit.entity.projectile.EntityProjectile)2 ProjectileLaunchEvent (cn.nukkit.event.entity.ProjectileLaunchEvent)2 FullChunk (cn.nukkit.level.format.FullChunk)2 Random (java.util.Random)2 BlockAir (cn.nukkit.block.BlockAir)1 BlockEntityBrewingStand (cn.nukkit.blockentity.BlockEntityBrewingStand)1