Search in sources :

Example 1 with StringTag

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

the class BlockChest method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        Block top = up();
        if (!top.isTransparent()) {
            return true;
        }
        BlockEntity t = this.getLevel().getBlockEntity(this);
        BlockEntityChest chest;
        if (t instanceof BlockEntityChest) {
            chest = (BlockEntityChest) t;
        } else {
            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);
            chest = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
        }
        if (chest.namedTag.contains("Lock") && chest.namedTag.get("Lock") instanceof StringTag) {
            if (!chest.namedTag.getString("Lock").equals(item.getCustomName())) {
                return true;
            }
        }
        player.addWindow(chest.getInventory());
    }
    return true;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) BlockEntityChest(cn.nukkit.blockentity.BlockEntityChest) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Example 2 with StringTag

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

the class BlockBrewingStand method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        BlockEntity t = getLevel().getBlockEntity(this);
        BlockEntityBrewingStand brewing;
        if (t instanceof BlockEntityBrewingStand) {
            brewing = (BlockEntityBrewingStand) t;
        } else {
            CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.BREWING_STAND).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
            brewing = new BlockEntityBrewingStand(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
        }
        if (brewing.namedTag.contains("Lock") && brewing.namedTag.get("Lock") instanceof StringTag) {
            if (!brewing.namedTag.getString("Lock").equals(item.getCustomName())) {
                return false;
            }
        }
        player.addWindow(brewing.getInventory());
    }
    return true;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) BlockEntityBrewingStand(cn.nukkit.blockentity.BlockEntityBrewingStand) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Example 3 with StringTag

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

the class BlockFurnaceBurning method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        BlockEntity t = this.getLevel().getBlockEntity(this);
        BlockEntityFurnace furnace;
        if (t instanceof BlockEntityFurnace) {
            furnace = (BlockEntityFurnace) t;
        } else {
            CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.FURNACE).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
            furnace = new BlockEntityFurnace(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
        }
        if (furnace.namedTag.contains("Lock") && furnace.namedTag.get("Lock") instanceof StringTag) {
            if (!furnace.namedTag.getString("Lock").equals(item.getCustomName())) {
                return true;
            }
        }
        player.addWindow(furnace.getInventory());
    }
    return true;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) BlockEntityFurnace(cn.nukkit.blockentity.BlockEntityFurnace) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Example 4 with StringTag

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

use of cn.nukkit.nbt.tag.StringTag 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)

Aggregations

CompoundTag (cn.nukkit.nbt.tag.CompoundTag)7 StringTag (cn.nukkit.nbt.tag.StringTag)7 BlockEntity (cn.nukkit.blockentity.BlockEntity)5 ListTag (cn.nukkit.nbt.tag.ListTag)2 BlockEntityBrewingStand (cn.nukkit.blockentity.BlockEntityBrewingStand)1 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)1 BlockEntityEnchantTable (cn.nukkit.blockentity.BlockEntityEnchantTable)1 BlockEntityEnderChest (cn.nukkit.blockentity.BlockEntityEnderChest)1 BlockEntityFurnace (cn.nukkit.blockentity.BlockEntityFurnace)1 EnchantInventory (cn.nukkit.inventory.EnchantInventory)1 Tag (cn.nukkit.nbt.tag.Tag)1 ArrayList (java.util.ArrayList)1