Search in sources :

Example 1 with BlockEntityEnchantTable

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

the class BlockEnchantingTable method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        BlockEntity t = this.getLevel().getBlockEntity(this);
        BlockEntityEnchantTable enchantTable;
        if (t instanceof BlockEntityEnchantTable) {
            enchantTable = (BlockEntityEnchantTable) t;
        } else {
            CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.ENCHANT_TABLE).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
            enchantTable = new BlockEntityEnchantTable(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
        }
        if (enchantTable.namedTag.contains("Lock") && enchantTable.namedTag.get("Lock") instanceof StringTag) {
            if (!enchantTable.namedTag.getString("Lock").equals(item.getCustomName())) {
                return true;
            }
        }
        player.addWindow(new EnchantInventory(this.getLocation()), Player.ENCHANT_WINDOW_ID);
    }
    return true;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) BlockEntityEnchantTable(cn.nukkit.blockentity.BlockEntityEnchantTable) EnchantInventory(cn.nukkit.inventory.EnchantInventory) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Aggregations

BlockEntity (cn.nukkit.blockentity.BlockEntity)1 BlockEntityEnchantTable (cn.nukkit.blockentity.BlockEntityEnchantTable)1 EnchantInventory (cn.nukkit.inventory.EnchantInventory)1 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)1 StringTag (cn.nukkit.nbt.tag.StringTag)1