Search in sources :

Example 16 with ByteBuffer

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

the class CodecPlayOutMultiBlockChange method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutMultiBlockChange message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeInteger(message.getChunkX());
    buf.writeInteger(message.getChunkZ());
    Collection<MessagePlayOutBlockChange> changes = message.getChanges();
    buf.writeVarInt(changes.size());
    for (MessagePlayOutBlockChange change : changes) {
        Vector3i position = change.getPosition();
        buf.writeByte((byte) ((position.getX() & 0xf) << 4 | position.getZ() & 0xf));
        buf.writeByte((byte) position.getY());
        buf.writeVarInt(change.getBlockState());
    }
    return buf;
}
Also used : MessagePlayOutBlockChange(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutBlockChange) Vector3i(com.flowpowered.math.vector.Vector3i) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 17 with ByteBuffer

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

the class CodecPlayOutNamedSoundEffect method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutNamedSoundEffect message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeString(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 18 with ByteBuffer

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

the class CodecPlayOutPlayerAbilities method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutPlayerAbilities message) throws CodecException {
    byte bits = 0;
    if (message.isInvulnerable()) {
        bits |= 0x1;
    }
    if (message.isFlying()) {
        bits |= 0x2;
    }
    if (message.canFly()) {
        bits |= 0x4;
    }
    if (message.isCreative()) {
        bits |= 0x8;
    }
    final ByteBuffer buf = context.byteBufAlloc().buffer(9);
    buf.writeByte(bits);
    buf.writeFloat(message.getFlySpeed());
    buf.writeFloat(message.getFieldOfView());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 19 with ByteBuffer

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

the class CodecPlayOutPlayerJoinGame method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutPlayerJoinGame message) throws CodecException {
    context.getChannel().attr(PLAYER_ENTITY_ID).set(message.getEntityId());
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeInteger(message.getEntityId());
    byte gameMode = (byte) message.getGameMode().getInternalId();
    if (message.isHardcore()) {
        gameMode |= 0x8;
    }
    buf.writeByte(gameMode);
    buf.writeInteger(message.getDimensionType().getInternalId());
    buf.writeByte((byte) message.getDifficulty().getInternalId());
    buf.writeByte((byte) Math.min(message.getPlayerListSize(), 255));
    buf.writeString(message.isLowHorizon() ? "flat" : "default");
    buf.writeBoolean(message.getReducedDebug());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 20 with ByteBuffer

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

the class CodecPlayOutPlayerRespawn method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutPlayerRespawn message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeInteger(message.getDimensionType().getInternalId());
    buf.writeByte((byte) message.getDifficulty().getInternalId());
    buf.writeByte((byte) message.getGameMode().getInternalId());
    buf.writeString(message.isLowHorizon() ? "flat" : "default");
    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