Search in sources :

Example 1 with BlockEntityJukebox

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

the class BlockJukebox method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    BlockEntity blockEntity = this.getLevel().getBlockEntity(this);
    if (blockEntity == null || !(blockEntity instanceof BlockEntityJukebox)) {
        blockEntity = this.createBlockEntity();
    }
    BlockEntityJukebox jukebox = (BlockEntityJukebox) blockEntity;
    if (jukebox.getRecordItem().getId() != 0) {
        jukebox.dropItem();
    } else if (item instanceof ItemRecord) {
        jukebox.setRecordItem(item);
        jukebox.play();
        player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex());
    }
    return false;
}
Also used : BlockEntityJukebox(cn.nukkit.blockentity.BlockEntityJukebox) ItemRecord(cn.nukkit.item.ItemRecord) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Aggregations

BlockEntity (cn.nukkit.blockentity.BlockEntity)1 BlockEntityJukebox (cn.nukkit.blockentity.BlockEntityJukebox)1 ItemRecord (cn.nukkit.item.ItemRecord)1