use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class Item method setCustomBlockData.
public Item setCustomBlockData(CompoundTag compoundTag) {
CompoundTag tags = compoundTag.copy();
tags.setName("BlockEntityTag");
CompoundTag tag;
if (!this.hasCompoundTag()) {
tag = new CompoundTag();
} else {
tag = this.getNamedTag();
}
tag.putCompound("BlockEntityTag", tags);
this.setNamedTag(tag);
return this;
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class Item method addEnchantment.
public void addEnchantment(Enchantment... enchantments) {
CompoundTag tag;
if (!this.hasCompoundTag()) {
tag = new CompoundTag();
} else {
tag = this.getNamedTag();
}
ListTag<CompoundTag> ench;
if (!tag.contains("ench")) {
ench = new ListTag<>("ench");
tag.putList(ench);
} else {
ench = tag.getList("ench", CompoundTag.class);
}
for (Enchantment enchantment : enchantments) {
boolean found = false;
for (int k = 0; k < ench.size(); k++) {
CompoundTag entry = ench.get(k);
if (entry.getShort("id") == enchantment.getId()) {
ench.add(k, new CompoundTag().putShort("id", enchantment.getId()).putShort("lvl", enchantment.getLevel()));
found = true;
break;
}
}
if (!found) {
ench.add(new CompoundTag().putShort("id", enchantment.getId()).putShort("lvl", enchantment.getLevel()));
}
}
this.setNamedTag(tag);
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class Item method setCustomName.
public Item setCustomName(String name) {
if (name == null || name.equals("")) {
this.clearCustomName();
}
CompoundTag tag;
if (!this.hasCompoundTag()) {
tag = new CompoundTag();
} else {
tag = this.getNamedTag();
}
if (tag.contains("display") && tag.get("display") instanceof CompoundTag) {
tag.getCompound("display").putString("Name", name);
} else {
tag.putCompound("display", new CompoundTag("display").putString("Name", name));
}
this.setNamedTag(tag);
return this;
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class Item method clearCustomBlockData.
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;
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class ItemBoat method onActivate.
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
if (face != BlockFace.UP)
return false;
EntityBoat boat = new EntityBoat(level.getChunk(block.getFloorX() >> 4, block.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", block.getX() + 0.5)).add(new DoubleTag("", block.getY() - 0.0625)).add(new DoubleTag("", block.getZ() + 0.5))).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", (float) ((player.yaw + 90f) % 360))).add(new FloatTag("", 0))).putByte("woodID", this.getDamage()));
if (player.isSurvival()) {
Item item = player.getInventory().getItemInHand();
item.setCount(item.getCount() - 1);
player.getInventory().setItemInHand(item);
}
boat.spawnToAll();
return true;
}
Aggregations