Search in sources :

Example 1 with ItemRecord

use of cn.nukkit.item.ItemRecord 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)

Example 2 with ItemRecord

use of cn.nukkit.item.ItemRecord in project Nukkit by Nukkit.

the class BlockEntityJukebox method stop.

public void stop() {
    if (this.recordItem instanceof ItemRecord) {
        StopSoundPacket pk = new StopSoundPacket();
        pk.name = ((ItemRecord) this.recordItem).getSoundId();
        Server.broadcastPacket(this.level.getPlayers().values(), pk);
    }
}
Also used : ItemRecord(cn.nukkit.item.ItemRecord) StopSoundPacket(cn.nukkit.network.protocol.StopSoundPacket)

Example 3 with ItemRecord

use of cn.nukkit.item.ItemRecord in project Nukkit by Nukkit.

the class BlockEntityJukebox method play.

public void play() {
    if (this.recordItem instanceof ItemRecord) {
        PlaySoundPacket pk = new PlaySoundPacket();
        pk.name = ((ItemRecord) this.recordItem).getSoundId();
        pk.pitch = 1;
        pk.volume = 1;
        pk.x = getFloorX();
        pk.y = getFloorY();
        pk.z = getFloorZ();
        Server.broadcastPacket(this.level.getPlayers().values(), pk);
    }
}
Also used : ItemRecord(cn.nukkit.item.ItemRecord) PlaySoundPacket(cn.nukkit.network.protocol.PlaySoundPacket)

Aggregations

ItemRecord (cn.nukkit.item.ItemRecord)3 BlockEntity (cn.nukkit.blockentity.BlockEntity)1 BlockEntityJukebox (cn.nukkit.blockentity.BlockEntityJukebox)1 PlaySoundPacket (cn.nukkit.network.protocol.PlaySoundPacket)1 StopSoundPacket (cn.nukkit.network.protocol.StopSoundPacket)1