use of cn.nukkit.nbt.tag.ListTag in project Nukkit by Nukkit.
the class ItemMinecartTNT method onActivate.
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
if (Rail.isRailBlock(target)) {
Rail.Orientation type = ((BlockRail) target).getOrientation();
double adjacent = 0.0D;
if (type.isAscending()) {
adjacent = 0.5D;
}
EntityMinecartTNT minecart = new EntityMinecartTNT(level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<>("Pos").add(new DoubleTag("", target.getX() + 0.5)).add(new DoubleTag("", target.getY() + 0.0625D + adjacent)).add(new DoubleTag("", target.getZ() + 0.5))).putList(new ListTag<>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))));
minecart.spawnToAll();
count -= 1;
return true;
}
return false;
}
use of cn.nukkit.nbt.tag.ListTag 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.ListTag 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.ListTag 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.ListTag in project Nukkit by Nukkit.
the class BlockChest method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
BlockEntityChest chest = null;
int[] faces = { 2, 5, 3, 4 };
this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
for (int side = 2; side <= 5; ++side) {
if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == 4 || side == 5)) {
continue;
} else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == 2 || side == 3)) {
continue;
}
Block c = this.getSide(BlockFace.fromIndex(side));
if (c instanceof BlockChest && c.getDamage() == this.getDamage()) {
BlockEntity blockEntity = this.getLevel().getBlockEntity(c);
if (blockEntity instanceof BlockEntityChest && !((BlockEntityChest) blockEntity).isPaired()) {
chest = (BlockEntityChest) blockEntity;
break;
}
}
}
this.getLevel().setBlock(block, this, true, true);
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);
if (item.hasCustomName()) {
nbt.putString("CustomName", item.getCustomName());
}
if (item.hasCustomBlockData()) {
Map<String, Tag> customData = item.getCustomBlockData().getTags();
for (Map.Entry<String, Tag> tag : customData.entrySet()) {
nbt.put(tag.getKey(), tag.getValue());
}
}
BlockEntity blockEntity = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
if (chest != null) {
chest.pairWith(((BlockEntityChest) blockEntity));
((BlockEntityChest) blockEntity).pairWith(chest);
}
return true;
}
Aggregations