use of cn.nukkit.nbt.tag.StringTag in project Nukkit by Nukkit.
the class BlockChest method onActivate.
@Override
public boolean onActivate(Item item, Player player) {
if (player != null) {
Block top = up();
if (!top.isTransparent()) {
return true;
}
BlockEntity t = this.getLevel().getBlockEntity(this);
BlockEntityChest chest;
if (t instanceof BlockEntityChest) {
chest = (BlockEntityChest) t;
} else {
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);
chest = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
}
if (chest.namedTag.contains("Lock") && chest.namedTag.get("Lock") instanceof StringTag) {
if (!chest.namedTag.getString("Lock").equals(item.getCustomName())) {
return true;
}
}
player.addWindow(chest.getInventory());
}
return true;
}
use of cn.nukkit.nbt.tag.StringTag in project Nukkit by Nukkit.
the class BlockBrewingStand method onActivate.
@Override
public boolean onActivate(Item item, Player player) {
if (player != null) {
BlockEntity t = getLevel().getBlockEntity(this);
BlockEntityBrewingStand brewing;
if (t instanceof BlockEntityBrewingStand) {
brewing = (BlockEntityBrewingStand) t;
} else {
CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.BREWING_STAND).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
brewing = new BlockEntityBrewingStand(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
}
if (brewing.namedTag.contains("Lock") && brewing.namedTag.get("Lock") instanceof StringTag) {
if (!brewing.namedTag.getString("Lock").equals(item.getCustomName())) {
return false;
}
}
player.addWindow(brewing.getInventory());
}
return true;
}
use of cn.nukkit.nbt.tag.StringTag in project Nukkit by Nukkit.
the class BlockFurnaceBurning method onActivate.
@Override
public boolean onActivate(Item item, Player player) {
if (player != null) {
BlockEntity t = this.getLevel().getBlockEntity(this);
BlockEntityFurnace furnace;
if (t instanceof BlockEntityFurnace) {
furnace = (BlockEntityFurnace) t;
} else {
CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.FURNACE).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
furnace = new BlockEntityFurnace(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
}
if (furnace.namedTag.contains("Lock") && furnace.namedTag.get("Lock") instanceof StringTag) {
if (!furnace.namedTag.getString("Lock").equals(item.getCustomName())) {
return true;
}
}
player.addWindow(furnace.getInventory());
}
return true;
}
use of cn.nukkit.nbt.tag.StringTag 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.StringTag 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]);
}
Aggregations