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;
}
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);
}
}
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);
}
}
Aggregations