use of cn.nukkit.nbt.tag.CompoundTag 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;
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class Item method getEnchantments.
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);
}
use of cn.nukkit.nbt.tag.CompoundTag 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]);
}
use of cn.nukkit.nbt.tag.CompoundTag 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;
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class BlockPistonBase method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (Math.abs(player.x - this.x) < 2 && Math.abs(player.z - this.z) < 2) {
double y = player.y + player.getEyeHeight();
if (y - this.y > 2) {
this.setDamage(BlockFace.UP.getIndex());
} else if (this.y - y > 0) {
this.setDamage(BlockFace.DOWN.getIndex());
} else {
this.setDamage(player.getHorizontalFacing().getIndex());
}
} else {
this.setDamage(player.getHorizontalFacing().getIndex());
}
this.level.setBlock(block, this, true, false);
CompoundTag nbt = new CompoundTag("").putString("id", BlockEntity.PISTON_ARM).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z).putBoolean("Sticky", this.sticky);
BlockEntityPistonArm be = new BlockEntityPistonArm(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
// this.checkState();
return true;
}
Aggregations