Search in sources :

Example 1 with MessagePlayOutOpenBook

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutOpenBook in project LanternServer by LanternPowered.

the class LanternPlayer method sendBookView.

@Override
public void sendBookView(BookView bookView) {
    checkNotNull(bookView, "bookView");
    final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    WrittenBookItemTypeObjectSerializer.writeBookData(dataView, bookView, this.locale);
    // Written book internal id
    final RawItemStack rawItemStack = new RawItemStack(387, 0, 1, dataView);
    final int slot = this.inventory.getHotbar().getSelectedSlotIndex();
    this.session.send(new MessagePlayOutSetWindowSlot(-2, slot, rawItemStack));
    this.session.send(new MessagePlayOutOpenBook(HandTypes.MAIN_HAND));
    this.session.send(new MessagePlayOutSetWindowSlot(-2, slot, this.inventory.getHotbar().getSelectedSlot().peek().orElse(null)));
}
Also used : DataView(org.spongepowered.api.data.DataView) MessagePlayOutSetWindowSlot(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetWindowSlot) RawItemStack(org.lanternpowered.server.network.objects.RawItemStack) MessagePlayOutOpenBook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutOpenBook)

Example 2 with MessagePlayOutOpenBook

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutOpenBook in project LanternServer by LanternPowered.

the class CodecPlayInOutCustomPayload method encode0.

@Override
protected MessageResult encode0(CodecContext context, Message message) throws CodecException {
    if (message instanceof MessagePlayInOutBrand) {
        return new MessageResult("MC|Brand", context.byteBufAlloc().buffer().writeString(((MessagePlayInOutBrand) message).getBrand()));
    } else if (message instanceof MessagePlayOutOpenBook) {
        final ByteBuffer buf = context.byteBufAlloc().buffer();
        buf.writeVarInt(((MessagePlayOutOpenBook) message).getHandType() == HandTypes.MAIN_HAND ? 0 : 1);
        return new MessageResult("MC|BOpen", buf);
    } else if (message instanceof MessagePlayOutStopSounds) {
        final MessagePlayOutStopSounds message0 = (MessagePlayOutStopSounds) message;
        final ByteBuffer buf = context.byteBufAlloc().buffer();
        buf.writeString(message0.getCategory() == null ? "" : message0.getCategory().getName());
        buf.writeString(message0.getSound() == null ? "" : message0.getSound());
        return new MessageResult("MC|StopSound", buf);
    }
    throw new EncoderException("Unsupported message type: " + message);
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) MessagePlayOutStopSounds(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds) MessagePlayInOutBrand(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutBrand) MessagePlayOutOpenBook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutOpenBook) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Aggregations

MessagePlayOutOpenBook (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutOpenBook)2 EncoderException (io.netty.handler.codec.EncoderException)1 ByteBuffer (org.lanternpowered.server.network.buffer.ByteBuffer)1 RawItemStack (org.lanternpowered.server.network.objects.RawItemStack)1 MessagePlayInOutBrand (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutBrand)1 MessagePlayOutSetWindowSlot (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetWindowSlot)1 MessagePlayOutStopSounds (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds)1 DataView (org.spongepowered.api.data.DataView)1