Search in sources :

Example 56 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutPlayerPositionAndLook method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutPlayerPositionAndLook message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeDouble(message.getX());
    buf.writeDouble(message.getY());
    buf.writeDouble(message.getZ());
    buf.writeFloat(message.getYaw());
    buf.writeFloat(message.getPitch());
    Set<RelativePositions> relativePositions = message.getRelativePositions();
    byte flags = 0;
    if (relativePositions.contains(RelativePositions.X)) {
        flags |= 0x01;
    }
    if (relativePositions.contains(RelativePositions.Y)) {
        flags |= 0x02;
    }
    if (relativePositions.contains(RelativePositions.Z)) {
        flags |= 0x04;
    }
    if (relativePositions.contains(RelativePositions.PITCH)) {
        flags |= 0x08;
    }
    if (relativePositions.contains(RelativePositions.YAW)) {
        flags |= 0x10;
    }
    buf.writeByte(flags);
    buf.writeVarInt(message.getTeleportId());
    return buf;
}
Also used : RelativePositions(org.spongepowered.api.util.RelativePositions) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 57 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayInOutConfirmWindowTransaction method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayInOutConfirmWindowTransaction message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer(6);
    buf.writeByte((byte) message.getWindowId());
    buf.writeShort((short) message.getTransaction());
    buf.writeBoolean(message.isAccepted());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 58 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer 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)

Example 59 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutAddPotionEffect method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutAddPotionEffect message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getEntityId());
    buf.writeByte((byte) ((LanternPotionEffectType) message.getType()).getInternalId());
    buf.writeByte((byte) message.getAmplifier());
    buf.writeVarInt(message.getDuration());
    byte flags = 0;
    if (message.isAmbient()) {
        flags |= 0x1;
    }
    if (message.getShowParticles()) {
        flags |= 0x2;
    }
    buf.writeByte(flags);
    return buf;
}
Also used : LanternPotionEffectType(org.lanternpowered.server.effect.potion.LanternPotionEffectType) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 60 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutSetExperience method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSetExperience message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeFloat(message.getExp());
    buf.writeVarInt(message.getLevel());
    buf.writeVarInt(message.getTotal());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Aggregations

ByteBuffer (org.lanternpowered.server.network.buffer.ByteBuffer)75 EncoderException (io.netty.handler.codec.EncoderException)9 Vector3d (com.flowpowered.math.vector.Vector3d)7 Message (org.lanternpowered.server.network.message.Message)5 Map (java.util.Map)4 MessagePlayInOutChannelPayload (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload)4 AbstractParameterList (org.lanternpowered.server.network.entity.parameter.AbstractParameterList)3 NullMessage (org.lanternpowered.server.network.message.NullMessage)3 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 Vector3i (com.flowpowered.math.vector.Vector3i)2 CodecException (io.netty.handler.codec.CodecException)2 LanternPotionEffectType (org.lanternpowered.server.effect.potion.LanternPotionEffectType)2 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)2 NetworkSession (org.lanternpowered.server.network.NetworkSession)2 LanternByteBuffer (org.lanternpowered.server.network.buffer.LanternByteBuffer)2 BulkMessage (org.lanternpowered.server.network.message.BulkMessage)2 CodecRegistration (org.lanternpowered.server.network.message.CodecRegistration)2 HandlerMessage (org.lanternpowered.server.network.message.HandlerMessage)2 Codec (org.lanternpowered.server.network.message.codec.Codec)2 RawItemStack (org.lanternpowered.server.network.objects.RawItemStack)2