use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class BlockEnchantingTable method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
this.getLevel().setBlock(block, this, true, true);
CompoundTag nbt = new CompoundTag().putString("id", BlockEntity.ENCHANT_TABLE).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.createBlockEntity(BlockEntity.ENCHANT_TABLE, getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
return true;
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class BlockRedstoneComparator method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (super.place(item, block, target, face, fx, fy, fz, player)) {
CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.COMPARATOR).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
new BlockEntityComparator(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
onUpdate(Level.BLOCK_UPDATE_REDSTONE);
return true;
}
return false;
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class BlockFlowerPot method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (face != BlockFace.UP)
return false;
CompoundTag nbt = new CompoundTag().putString("id", BlockEntity.FLOWER_POT).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z).putShort("item", 0).putInt("data", 0);
if (item.hasCustomBlockData()) {
for (Tag aTag : item.getCustomBlockData().getAllTags()) {
nbt.put(aTag.getName(), aTag);
}
}
new BlockEntityFlowerPot(getLevel().getChunk((int) block.x >> 4, (int) block.z >> 4), nbt);
this.getLevel().setBlock(block, this, true, true);
return true;
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class BlockFurnaceBurning method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
int[] faces = { 2, 5, 3, 4 };
this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
this.getLevel().setBlock(block, this, true, true);
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);
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());
}
}
new BlockEntityFurnace(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
return true;
}
use of cn.nukkit.nbt.tag.CompoundTag 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;
}
Aggregations