Search in sources :

Example 6 with ByteBuffer

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

the class CodecPlayOutWindowProperty method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutWindowProperty message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer(9);
    buf.writeByte((byte) message.getWindowId());
    buf.writeShort((short) message.getProperty());
    buf.writeShort((short) message.getValue());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 7 with ByteBuffer

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

the class CodecPlayOutWorldTime method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutWorldTime message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer(LENGTH);
    // The time also uses a negative tag
    long time = message.getTime();
    while (time < 0) {
        time += TimeUniverse.TICKS_IN_A_DAY;
    }
    time %= TimeUniverse.TICKS_IN_A_DAY;
    time += message.getMoonPhase().ordinal() * TimeUniverse.TICKS_IN_A_DAY;
    if (!message.getEnabled()) {
        time = time == 0 ? -1 : -time;
    }
    buf.writeLong(message.getAge());
    buf.writeLong(time);
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 8 with ByteBuffer

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

the class CodecPlayOutSetWindowSlot method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSetWindowSlot message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeByte((byte) message.getWindow());
    buf.writeShort((short) message.getIndex());
    final Object item = message.getItem();
    if (item instanceof ItemStack) {
        buf.write(Types.ITEM_STACK, (ItemStack) item);
    } else if (item instanceof RawItemStack || item == null) {
        buf.write(Types.RAW_ITEM_STACK, (RawItemStack) item);
    } else {
        throw new EncoderException("Invalid item type:" + item.getClass().getName());
    }
    return buf;
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) RawItemStack(org.lanternpowered.server.network.objects.RawItemStack) RawItemStack(org.lanternpowered.server.network.objects.RawItemStack) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 9 with ByteBuffer

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

the class CodecPlayOutSoundEffect method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSoundEffect message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getType());
    buf.writeVarInt(((LanternSoundCategory) message.getCategory()).getInternalId());
    final Vector3d pos = message.getPosition();
    buf.writeInteger((int) (pos.getX() * 8.0));
    buf.writeInteger((int) (pos.getY() * 8.0));
    buf.writeInteger((int) (pos.getZ() * 8.0));
    buf.writeFloat(message.getVolume());
    buf.writeFloat(message.getPitch());
    return buf;
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 10 with ByteBuffer

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

the class CodecPlayOutSpawnExperienceOrb method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSpawnExperienceOrb message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getEntityId());
    final Vector3d position = message.getPosition();
    buf.writeDouble(position.getX());
    buf.writeDouble(position.getY());
    buf.writeDouble(position.getZ());
    buf.writeShort((short) Math.min(message.getQuantity(), Short.MAX_VALUE));
    return buf;
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) 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