use of cn.nukkit.nbt.tag.Tag in project Nukkit by Nukkit.
the class BlockTrappedChest 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 };
BlockEntityChest chest = null;
this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
for (BlockFace side : Plane.HORIZONTAL) {
if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == BlockFace.WEST || side == BlockFace.EAST)) {
continue;
} else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == BlockFace.NORTH || side == BlockFace.SOUTH)) {
continue;
}
Block c = this.getSide(side);
if (c instanceof BlockTrappedChest && 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;
}
use of cn.nukkit.nbt.tag.Tag in project Nukkit by Nukkit.
the class BlockSignPost 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.DOWN) {
CompoundTag nbt = new CompoundTag().putString("id", BlockEntity.SIGN).putInt("x", (int) block.x).putInt("y", (int) block.y).putInt("z", (int) block.z).putString("Text1", "").putString("Text2", "").putString("Text3", "").putString("Text4", "");
if (face == BlockFace.UP) {
setDamage((int) Math.floor(((player.yaw + 180) * 16 / 360) + 0.5) & 0x0f);
getLevel().setBlock(block, new BlockSignPost(getDamage()), true);
} else {
setDamage(face.getIndex());
getLevel().setBlock(block, new BlockWallSign(getDamage()), true);
}
if (player != null) {
nbt.putString("Creator", player.getUniqueId().toString());
}
if (item.hasCustomBlockData()) {
for (Tag aTag : item.getCustomBlockData().getAllTags()) {
nbt.put(aTag.getName(), aTag);
}
}
new BlockEntitySign(getLevel().getChunk((int) block.x >> 4, (int) block.z >> 4), nbt);
return true;
}
return false;
}
use of cn.nukkit.nbt.tag.Tag in project Nukkit by Nukkit.
the class BlockSkull method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
switch(face) {
case NORTH:
case SOUTH:
case EAST:
case WEST:
case UP:
this.setDamage(face.getIndex());
break;
case DOWN:
default:
return false;
}
this.getLevel().setBlock(block, this, true, true);
CompoundTag nbt = new CompoundTag().putString("id", BlockEntity.SKULL).putByte("SkullType", item.getDamage()).putInt("x", block.getFloorX()).putInt("y", block.getFloorY()).putInt("z", block.getFloorZ()).putByte("Rot", (int) Math.floor((player.yaw * 16 / 360) + 0.5) & 0x0f);
if (item.hasCustomBlockData()) {
for (Tag aTag : item.getCustomBlockData().getAllTags()) {
nbt.put(aTag.getName(), aTag);
}
}
new BlockEntitySkull(getLevel().getChunk((int) block.x >> 4, (int) block.z >> 4), nbt);
return true;
}
use of cn.nukkit.nbt.tag.Tag 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.Tag in project Nukkit by Nukkit.
the class BlockItemFrame method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) {
switch(face) {
case NORTH:
this.setDamage(3);
break;
case SOUTH:
this.setDamage(2);
break;
case WEST:
this.setDamage(1);
break;
case EAST:
this.setDamage(0);
break;
default:
return false;
}
this.getLevel().setBlock(block, this, true, true);
CompoundTag nbt = new CompoundTag().putString("id", BlockEntity.ITEM_FRAME).putInt("x", (int) block.x).putInt("y", (int) block.y).putInt("z", (int) block.z).putByte("ItemRotation", 0).putFloat("ItemDropChance", 1.0f);
if (item.hasCustomBlockData()) {
for (Tag aTag : item.getCustomBlockData().getAllTags()) {
nbt.put(aTag.getName(), aTag);
}
}
new BlockEntityItemFrame(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_PLACE);
return true;
}
return false;
}
Aggregations