Search in sources :

Example 1 with BlockEntityEnderChest

use of cn.nukkit.blockentity.BlockEntityEnderChest in project Nukkit by Nukkit.

the class BlockEnderChest 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("").putString("id", BlockEntity.ENDER_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());
        }
    }
    new BlockEntityEnderChest(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
    return true;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) Map(java.util.Map) BlockEntityEnderChest(cn.nukkit.blockentity.BlockEntityEnderChest) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 2 with BlockEntityEnderChest

use of cn.nukkit.blockentity.BlockEntityEnderChest in project Nukkit by Nukkit.

the class BlockEnderChest method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        Block top = this.up();
        if (!top.isTransparent()) {
            return true;
        }
        BlockEntity t = this.getLevel().getBlockEntity(this);
        BlockEntityEnderChest chest;
        if (t instanceof BlockEntityEnderChest) {
            chest = (BlockEntityEnderChest) t;
        } else {
            CompoundTag nbt = new CompoundTag("").putString("id", BlockEntity.ENDER_CHEST).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
            chest = new BlockEntityEnderChest(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.setViewingEnderChest(this);
        player.addWindow(player.getEnderChestInventory());
    }
    return true;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) BlockEntityEnderChest(cn.nukkit.blockentity.BlockEntityEnderChest) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Aggregations

BlockEntityEnderChest (cn.nukkit.blockentity.BlockEntityEnderChest)2 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)2 StringTag (cn.nukkit.nbt.tag.StringTag)2 BlockEntity (cn.nukkit.blockentity.BlockEntity)1 Tag (cn.nukkit.nbt.tag.Tag)1 Map (java.util.Map)1