Search in sources :

Example 6 with StringTag

use of cn.nukkit.nbt.tag.StringTag 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)

Example 7 with StringTag

use of cn.nukkit.nbt.tag.StringTag 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

CompoundTag (cn.nukkit.nbt.tag.CompoundTag)7 StringTag (cn.nukkit.nbt.tag.StringTag)7 BlockEntity (cn.nukkit.blockentity.BlockEntity)5 ListTag (cn.nukkit.nbt.tag.ListTag)2 BlockEntityBrewingStand (cn.nukkit.blockentity.BlockEntityBrewingStand)1 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)1 BlockEntityEnchantTable (cn.nukkit.blockentity.BlockEntityEnchantTable)1 BlockEntityEnderChest (cn.nukkit.blockentity.BlockEntityEnderChest)1 BlockEntityFurnace (cn.nukkit.blockentity.BlockEntityFurnace)1 EnchantInventory (cn.nukkit.inventory.EnchantInventory)1 Tag (cn.nukkit.nbt.tag.Tag)1 ArrayList (java.util.ArrayList)1