Java Code Examples for cn.nukkit.nbt.tag.CompoundTag#get()

The following examples show how to use cn.nukkit.nbt.tag.CompoundTag#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Item.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public CompoundTag getCustomBlockData() {
    if (!this.hasCompoundTag()) {
        return null;
    }

    CompoundTag tag = this.getNamedTag();

    if (tag.contains("BlockEntityTag")) {
        Tag bet = tag.get("BlockEntityTag");
        if (bet instanceof CompoundTag) {
            return (CompoundTag) bet;
        }
    }

    return null;
}
 
Example 2
Source File: ItemBookWritable.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Inserts a new page with the given text and moves other pages upwards.
 * @return boolean indicating success
 */
public boolean insertPage(int pageId, String pageText) {
    Preconditions.checkArgument(pageId >= 0 && pageId < 50, "Page number " + pageId + " is out of range");
    CompoundTag tag = this.hasCompoundTag() ? this.getNamedTag() : new CompoundTag();
    ListTag<CompoundTag> pages;
    if (!tag.contains("pages") || !(tag.get("pages") instanceof ListTag)) {
        pages = new ListTag<>("pages");
        tag.putList(pages);
    } else {
        pages = tag.getList("pages", CompoundTag.class);
    }

    if (pages.size() <= pageId) {
        for (int current = pages.size(); current <= pageId; current++) {
            pages.add(createPageTag());
        }
        pages.get(pageId).putString("text", pageText);
    } else {
        pages.add(pageId, createPageTag(pageText));
    }
    this.setCompoundTag(tag);
    return true;
}
 
Example 3
Source File: Item.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public CompoundTag getCustomBlockData() {
    if (!this.hasCompoundTag()) {
        return null;
    }

    CompoundTag tag = this.getNamedTag();

    if (tag.contains("BlockEntityTag")) {
        Tag bet = tag.get("BlockEntityTag");
        if (bet instanceof CompoundTag) {
            return (CompoundTag) bet;
        }
    }

    return null;
}
 
Example 4
Source File: Item.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public boolean hasEnchantments() {
    if (!this.hasCompoundTag()) {
        return false;
    }

    CompoundTag tag = this.getNamedTag();

    if (tag.contains("ench")) {
        Tag enchTag = tag.get("ench");
        if (enchTag instanceof ListTag) {
            return true;
        }
    }

    return false;
}
 
Example 5
Source File: Item.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public Item clearCustomName() {
    if (!this.hasCompoundTag()) {
        return this;
    }

    CompoundTag tag = this.getNamedTag();

    if (tag.contains("display") && tag.get("display") instanceof CompoundTag) {
        tag.getCompound("display").remove("Name");
        if (tag.getCompound("display").isEmpty()) {
            tag.remove("display");
        }

        this.setNamedTag(tag);
    }

    return this;
}
 
Example 6
Source File: Item.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public Item clearCustomName() {
    if (!this.hasCompoundTag()) {
        return this;
    }

    CompoundTag tag = this.getNamedTag();

    if (tag.contains("display") && tag.get("display") instanceof CompoundTag) {
        tag.getCompound("display").remove("Name");
        if (tag.getCompound("display").isEmpty()) {
            tag.remove("display");
        }

        this.setNamedTag(tag);
    }

    return this;
}
 
Example 7
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean hasEnchantments() {
    if (!this.hasCompoundTag()) {
        return false;
    }

    CompoundTag tag = this.getNamedTag();

    if (tag.contains("ench")) {
        Tag enchTag = tag.get("ench");
        return enchTag instanceof ListTag;
    }

    return false;
}
 
Example 9
Source File: ItemBookWritable.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns an list containing all pages of this book.
 */
public List getPages() {
    CompoundTag tag = this.hasCompoundTag() ? this.getNamedTag() : new CompoundTag();
    ListTag<CompoundTag> pages;
    if (!tag.contains("pages") || !(tag.get("pages") instanceof ListTag)) {
        pages = new ListTag<>("pages");
        tag.putList(pages);
    } else {
        pages = tag.getList("pages", CompoundTag.class);
    }
    return pages.parseValue();
}
 
Example 10
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: ItemBookWritable.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether the given page exists in this book.
 */
public boolean pageExists(int pageId) {
    Preconditions.checkArgument(pageId >= 0 && pageId < 50, "Page number " + pageId + " is out of range");
    if (this.hasCompoundTag()) {
        CompoundTag tag = this.getNamedTag();
        if (tag.contains("pages") && tag.get("pages") instanceof ListTag) {
            return tag.getList("pages", CompoundTag.class).size() > pageId;
        }
    }
    return false;
}
 
Example 12
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean hasCustomBlockData() {
    if (!this.hasCompoundTag()) {
        return false;
    }

    CompoundTag tag = this.getNamedTag();
    return tag.contains("BlockEntityTag") && tag.get("BlockEntityTag") instanceof CompoundTag;

}
 
Example 13
Source File: Chunk.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static Chunk fromFastBinary(byte[] data, LevelProvider provider) {
    try {
        CompoundTag chunk = NBTIO.read(new DataInputStream(new ByteArrayInputStream(data)), ByteOrder.BIG_ENDIAN);
        if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) {
            return null;
        }

        return new Chunk(provider, chunk.getCompound("Level"));
    } catch (Exception e) {
        return null;
    }
}
 
Example 14
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static Chunk fromBinary(byte[] data, LevelProvider provider) {
    try {
        CompoundTag chunk = NBTIO.read(new ByteArrayInputStream(Zlib.inflate(data)), ByteOrder.BIG_ENDIAN);

        if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) {
            return null;
        }
        return new Chunk(provider != null ? provider : McRegion.class.newInstance(), chunk.getCompound("Level"));
    } catch (Exception e) {
        return null;
    }
}
 
Example 15
Source File: NBTIO.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static Item getItemHelper(CompoundTag tag) {
    if (!tag.contains("id") || !tag.contains("Count")) {
        return Item.get(0);
    }

    Item item = Item.get(tag.getShort("id"), !tag.contains("Damage") ? 0 : tag.getShort("Damage"), tag.getByte("Count"));

    if (tag.contains("tag") && tag.get("tag") instanceof CompoundTag) {
        CompoundTag nbt = tag.getCompound("tag").clone();
        nbt.setName("");
        item.setNamedTag(nbt);
    }

    return item;
}
 
Example 16
Source File: Item.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public Tag getNamedTagEntry(String name) {
    CompoundTag tag = this.getNamedTag();
    if (tag != null) {
        return tag.contains(name) ? tag.get(name) : null;
    }

    return null;
}
 
Example 17
Source File: Item.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public String getCustomName() {
    if (!this.hasCompoundTag()) {
        return "";
    }

    CompoundTag tag = this.getNamedTag();
    if (tag.contains("display")) {
        Tag tag1 = tag.get("display");
        if (tag1 instanceof CompoundTag && ((CompoundTag) tag1).contains("Name") && ((CompoundTag) tag1).get("Name") instanceof StringTag) {
            return ((CompoundTag) tag1).getString("Name");
        }
    }

    return "";
}
 
Example 18
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public Tag getNamedTagEntry(String name) {
    CompoundTag tag = this.getNamedTag();
    if (tag != null) {
        return tag.contains(name) ? tag.get(name) : null;
    }

    return null;
}
 
Example 19
Source File: Item.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 20
Source File: Item.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public boolean hasCustomBlockData() {
    if (!this.hasCompoundTag()) {
        return false;
    }

    CompoundTag tag = this.getNamedTag();
    return tag.contains("BlockEntityTag") && tag.get("BlockEntityTag") instanceof CompoundTag;

}