Search in sources :

Example 11 with ByteBuffer

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

the class CodecPlayOutSpawnObject method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSpawnObject message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getEntityId());
    buf.writeUniqueId(message.getUniqueId());
    buf.writeByte((byte) message.getObjectType());
    Vector3d vector = message.getPosition();
    buf.writeDouble(vector.getX());
    buf.writeDouble(vector.getY());
    buf.writeDouble(vector.getZ());
    buf.writeByte((byte) message.getPitch());
    buf.writeByte((byte) message.getYaw());
    buf.writeInteger(message.getObjectData());
    vector = message.getVelocity();
    buf.writeShort((short) Math.min(vector.getX() * 8000.0, Short.MAX_VALUE));
    buf.writeShort((short) Math.min(vector.getY() * 8000.0, Short.MAX_VALUE));
    buf.writeShort((short) Math.min(vector.getZ() * 8000.0, Short.MAX_VALUE));
    return buf;
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 12 with ByteBuffer

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

the class CodecPlayOutSpawnPainting method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSpawnPainting message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getEntityId());
    buf.writeUniqueId(message.getUniqueId());
    buf.writeString(message.getArt().getName());
    buf.write(Types.VECTOR_3_I, new Vector3i(message.getX(), message.getY(), message.getZ()));
    buf.writeByte(toId(message.getDirection()));
    return buf;
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 13 with ByteBuffer

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

the class CodecPlayOutEntityAnimation method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutEntityAnimation message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getEntityId());
    buf.writeByte((byte) message.getAnimation());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 14 with ByteBuffer

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

the class CodecPlayOutEntityLookAndRelativeMove method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutEntityLookAndRelativeMove message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getEntityId());
    buf.writeShort((short) message.getDeltaX());
    buf.writeShort((short) message.getDeltaY());
    buf.writeShort((short) message.getDeltaZ());
    buf.writeByte(message.getYaw());
    buf.writeByte(message.getPitch());
    buf.writeBoolean(message.isOnGround());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 15 with ByteBuffer

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

the class CodecPlayOutEntityTeleport method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutEntityTeleport message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getEntityId());
    buf.writeDouble(message.getX());
    buf.writeDouble(message.getY());
    buf.writeDouble(message.getZ());
    buf.writeByte(message.getYaw());
    buf.writeByte(message.getPitch());
    buf.writeBoolean(message.isOnGround());
    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