Search in sources :

Example 1 with MessagePlayInUseEntity

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInUseEntity in project LanternServer by LanternPowered.

the class CodecPlayInUseEntity method decode.

@Override
public MessagePlayInUseEntity decode(CodecContext context, ByteBuffer buf) throws CodecException {
    final int entityId = buf.readVarInt();
    final int action = buf.readVarInt();
    if (action == 1) {
        return new MessagePlayInUseEntity.Attack(entityId);
    } else if (action == 0 || action == 2) {
        Vector3d position = null;
        if (action == 2) {
            final double x = buf.readFloat();
            final double y = buf.readFloat();
            final double z = buf.readFloat();
            position = new Vector3d(x, y, z);
        }
        final HandType hand = buf.readVarInt() == 0 ? HandTypes.MAIN_HAND : HandTypes.OFF_HAND;
        return new MessagePlayInUseEntity.Interact(entityId, hand, position);
    } else {
        throw new DecoderException("Received a UseEntity message with a unknown action: " + action);
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) Vector3d(com.flowpowered.math.vector.Vector3d) HandType(org.spongepowered.api.data.type.HandType) MessagePlayInUseEntity(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInUseEntity)

Aggregations

Vector3d (com.flowpowered.math.vector.Vector3d)1 DecoderException (io.netty.handler.codec.DecoderException)1 MessagePlayInUseEntity (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInUseEntity)1 HandType (org.spongepowered.api.data.type.HandType)1