Search in sources :

Example 61 with ByteBuffer

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

the class CodecPlayOutSpawnMob method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSpawnMob message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getEntityId());
    buf.writeUniqueId(message.getUniqueId());
    buf.writeVarInt(message.getMobType());
    Vector3d vector = message.getPosition();
    buf.writeDouble(vector.getX());
    buf.writeDouble(vector.getY());
    buf.writeDouble(vector.getZ());
    buf.writeByte(message.getYaw());
    buf.writeByte(message.getPitch());
    buf.writeByte(message.getHeadPitch());
    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));
    ((AbstractParameterList) message.getParameterList()).write(buf);
    return buf;
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) AbstractParameterList(org.lanternpowered.server.network.entity.parameter.AbstractParameterList) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 62 with ByteBuffer

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

the class CodecPlayOutSpawnParticle method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSpawnParticle message) throws CodecException {
    Vector3f position = message.getPosition();
    Vector3f offset = message.getOffset();
    int[] extra = message.getExtra();
    ByteBuffer buf = context.byteBufAlloc().buffer(BASE_LENGTH);
    buf.writeInteger(message.getParticleId());
    buf.writeBoolean(message.isLongDistance());
    buf.writeFloat(position.getX());
    buf.writeFloat(position.getY());
    buf.writeFloat(position.getZ());
    buf.writeFloat(offset.getX());
    buf.writeFloat(offset.getY());
    buf.writeFloat(offset.getZ());
    buf.writeFloat(message.getData());
    buf.writeInteger(message.getCount());
    for (int value : extra) {
        buf.writeVarInt(value);
    }
    return buf;
}
Also used : Vector3f(com.flowpowered.math.vector.Vector3f) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 63 with ByteBuffer

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

the class CodecPlayOutSpawnPlayer method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSpawnPlayer message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getEntityId());
    buf.writeUniqueId(message.getUniqueId());
    Vector3d vector = message.getPosition();
    buf.writeDouble(vector.getX());
    buf.writeDouble(vector.getY());
    buf.writeDouble(vector.getZ());
    buf.writeByte((byte) message.getYaw());
    buf.writeByte((byte) message.getPitch());
    ((AbstractParameterList) message.getParameterList()).write(buf);
    return buf;
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) AbstractParameterList(org.lanternpowered.server.network.entity.parameter.AbstractParameterList) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 64 with ByteBuffer

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

the class CodecPlayOutSpawnThunderbolt method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSpawnThunderbolt message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getEntityId());
    buf.writeByte((byte) 1);
    final Vector3d position = message.getPosition();
    buf.writeDouble(position.getX());
    buf.writeDouble(position.getY());
    buf.writeDouble(position.getZ());
    return buf;
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 65 with ByteBuffer

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

the class ProcessorPlayOutParticleEffect method processRemoval.

private void processRemoval(@Nullable ParticleEffect key, @Nullable ICachedMessage value, RemovalCause cause) {
    if (value instanceof CachedFireworksMessage) {
        final ByteBufParameterList parameterList = (ByteBufParameterList) ((CachedFireworksMessage) value).entityMetadataMessage.getParameterList();
        parameterList.getByteBuffer().ifPresent(ByteBuffer::release);
    }
}
Also used : ByteBufParameterList(org.lanternpowered.server.network.entity.parameter.ByteBufParameterList) 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