Java Code Examples for cn.nukkit.nbt.tag.ListTag#getAll()

The following examples show how to use cn.nukkit.nbt.tag.ListTag#getAll() . 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: BlockEntityChest.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initBlockEntity() {
    this.inventory = new ChestInventory(this);

    if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) {
        this.namedTag.putList(new ListTag<CompoundTag>("Items"));
    }

    /* for (int i = 0; i < this.getSize(); i++) {
        this.inventory.setItem(i, this.getItem(i));
    } */

    ListTag<CompoundTag> list = (ListTag<CompoundTag>) this.namedTag.getList("Items");
    for (CompoundTag compound : list.getAll()) {
        Item item = NBTIO.getItemHelper(compound);
        this.inventory.slots.put(compound.getByte("Slot"), item);
    }

    super.initBlockEntity();
}
 
Example 2
Source File: Item.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: Item.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
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]);
}
 
Example 4
Source File: Item.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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]);
}
 
Example 5
Source File: Item.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example 6
Source File: BlockEntityChest.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public BlockEntityChest(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    this.inventory = new ChestInventory(this);

    if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) {
        this.namedTag.putList(new ListTag<CompoundTag>("Items"));
    }

    /* for (int i = 0; i < this.getSize(); i++) {
        this.inventory.setItem(i, this.getItem(i));
    } */

    ListTag<CompoundTag> list = this.namedTag.getList("Items", CompoundTag.class);
    for (CompoundTag compound : list.getAll()) {
        Item item = NBTIO.getItemHelper(compound);
        this.inventory.slots.put(compound.getByte("Slot"), item);
    }
}
 
Example 7
Source File: EntityMinecartChest.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initEntity() {
    super.initEntity();

    this.inventory = new MinecartChestInventory(this);
    if (this.namedTag.contains("Items") && this.namedTag.get("Items") instanceof ListTag) {
        ListTag<CompoundTag> inventoryList = this.namedTag.getList("Items", CompoundTag.class);
        for (CompoundTag item : inventoryList.getAll()) {
            this.inventory.setItem(item.getByte("Slot"), NBTIO.getItemHelper(item));
        }
    }

    this.dataProperties
            .putByte(DATA_CONTAINER_TYPE, 10)
            .putInt(DATA_CONTAINER_BASE_SIZE, this.inventory.getSize())
            .putInt(DATA_CONTAINER_EXTRA_SLOTS_PER_STRENGTH, 0);
}
 
Example 8
Source File: EntityMinecartHopper.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initEntity() {
    super.initEntity();

    this.inventory = new MinecartHopperInventory(this);
    if (this.namedTag.contains("Items") && this.namedTag.get("Items") instanceof ListTag) {
        ListTag<CompoundTag> inventoryList = this.namedTag.getList("Items", CompoundTag.class);
        for (CompoundTag item : inventoryList.getAll()) {
            this.inventory.setItem(item.getByte("Slot"), NBTIO.getItemHelper(item));
        }
    }

    this.dataProperties
            .putByte(DATA_CONTAINER_TYPE, 11)
            .putInt(DATA_CONTAINER_BASE_SIZE, this.inventory.getSize())
            .putInt(DATA_CONTAINER_EXTRA_SLOTS_PER_STRENGTH, 0);
}
 
Example 9
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
protected void initEntity() {
    if (this.namedTag.contains("ActiveEffects")) {
        ListTag<CompoundTag> effects = this.namedTag.getList("ActiveEffects", CompoundTag.class);
        for (CompoundTag e : effects.getAll()) {
            Effect effect = Effect.getEffect(e.getByte("Id"));
            if (effect == null) {
                continue;
            }

            effect.setAmplifier(e.getByte("Amplifier")).setDuration(e.getInt("Duration")).setVisible(e.getBoolean("showParticles"));

            this.addEffect(effect);
        }
    }

    if (this.namedTag.contains("CustomName")) {
        this.setNameTag(this.namedTag.getString("CustomName"));
        if (this.namedTag.contains("CustomNameVisible")) {
            this.setNameTagVisible(this.namedTag.getBoolean("CustomNameVisible"));
        }
    }

    this.scheduleUpdate();
}
 
Example 10
Source File: Item.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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"), false);
            enchantments.add(e);
        }
    }

    return enchantments.toArray(new Enchantment[0]);
}
 
Example 11
Source File: Item.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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]);
}
 
Example 12
Source File: BlockEntityShulkerBox.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initBlockEntity() {
    this.inventory = new ShulkerBoxInventory(this);

    if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) {
        this.namedTag.putList(new ListTag<CompoundTag>("Items"));
    }

    ListTag<CompoundTag> list = (ListTag<CompoundTag>) this.namedTag.getList("Items");
    for (CompoundTag compound : list.getAll()) {
        Item item = NBTIO.getItemHelper(compound);
        this.inventory.slots.put(compound.getByte("Slot"), item);
    }

    if (!this.namedTag.contains("facing")) {
        this.namedTag.putByte("facing", 0);
    }

    super.initBlockEntity();
}
 
Example 13
Source File: BlockEntityChest.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initBlockEntity() {
    this.inventory = new ChestInventory(this);

    if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) {
        this.namedTag.putList(new ListTag<CompoundTag>("Items"));
    }

    /* for (int i = 0; i < this.getSize(); i++) {
        this.inventory.setItem(i, this.getItem(i));
    } */

    ListTag<CompoundTag> list = (ListTag<CompoundTag>) this.namedTag.getList("Items");
    for (CompoundTag compound : list.getAll()) {
        Item item = NBTIO.getItemHelper(compound);
        this.inventory.slots.put(compound.getByte("Slot"), item);
    }

    super.initBlockEntity();
}
 
Example 14
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
protected void initEntity() {
    if (this.namedTag.contains("ActiveEffects")) {
        ListTag<CompoundTag> effects = this.namedTag.getList("ActiveEffects", CompoundTag.class);
        for (CompoundTag e : effects.getAll()) {
            Effect effect = Effect.getEffect(e.getByte("Id"));
            if (effect == null) {
                continue;
            }

            effect.setAmplifier(e.getByte("Amplifier")).setDuration(e.getInt("Duration")).setVisible(e.getBoolean("showParticles"));

            this.addEffect(effect);
        }
    }

    if (this.namedTag.contains("CustomName")) {
        this.setNameTag(this.namedTag.getString("CustomName"));
        if (this.namedTag.contains("CustomNameVisible")) {
            this.setNameTagVisible(this.namedTag.getBoolean("CustomNameVisible"));
        }
    }

    this.scheduleUpdate();
}
 
Example 15
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void initEntity() {
    if (this.namedTag.contains("ActiveEffects")) {
        ListTag<CompoundTag> effects = this.namedTag.getList("ActiveEffects", CompoundTag.class);
        for (CompoundTag e : effects.getAll()) {
            Effect effect = Effect.getEffect(e.getByte("Id"));
            if (effect == null) {
                continue;
            }

            effect.setAmplifier(e.getByte("Amplifier")).setDuration(e.getInt("Duration")).setVisible(e.getBoolean("showParticles"));

            this.addEffect(effect);
        }
    }

    if (this.namedTag.contains("CustomName")) {
        this.setNameTag(this.namedTag.getString("CustomName"));
        if (this.namedTag.contains("CustomNameVisible")) {
            this.setNameTagVisible(this.namedTag.getBoolean("CustomNameVisible"));
        }
        if(this.namedTag.contains("CustomNameAlwaysVisible")){
            this.setNameTagAlwaysVisible(this.namedTag.getBoolean("CustomNameAlwaysVisible"));
        }
    }

    this.setDataFlag(DATA_FLAGS, DATA_FLAG_HAS_COLLISION, true);
    this.dataProperties.putFloat(DATA_BOUNDING_BOX_HEIGHT, this.getHeight());
    this.dataProperties.putFloat(DATA_BOUNDING_BOX_WIDTH, this.getWidth());
    this.dataProperties.putInt(DATA_HEALTH, (int) this.getHealth());

    this.scheduleUpdate();
}
 
Example 16
Source File: ItemBookWritten.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 17
Source File: BlockEntityShulkerBox.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public BlockEntityShulkerBox(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    this.inventory = new ShulkerBoxInventory(this);

    if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) {
        this.namedTag.putList(new ListTag<CompoundTag>("Items"));
    }

    ListTag<CompoundTag> list = this.namedTag.getList("Items", CompoundTag.class);
    for (CompoundTag compound : list.getAll()) {
        Item item = NBTIO.getItemHelper(compound);
        this.inventory.slots.put(compound.getByte("Slot"), item);
    }
}
 
Example 18
Source File: BlockBannerStanding.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item toItem() {
	BlockEntity blockEntity = this.level.getBlockEntity(this);
	if (blockEntity != null && blockEntity instanceof BlockEntityBanner) {
		int id = ((BlockEntityBanner) blockEntity).getBase();
		ListTag<CompoundTag> tag = ((BlockEntityBanner) blockEntity).getPatterns();
		ItemBanner item = new ItemBanner(id, 1);
		for (CompoundTag nbt : tag.getAll()) {
			item.addPatterns(nbt);
		}
		return item;
	} else {
		return new ItemBanner();
	}
}
 
Example 19
Source File: ItemBookWritten.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
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;
}