Search in sources :

Example 1 with MessagePlayInPlayerSneak

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

the class CodecPlayInPlayerVehicleControls method decode.

@Override
public Message decode(CodecContext context, ByteBuffer buf) throws CodecException {
    float sideways = buf.readFloat();
    float forwards = buf.readFloat();
    final byte flags = buf.readByte();
    final boolean jump = (flags & 0x1) != 0;
    final boolean sneak = (flags & 0x2) != 0;
    final List<Message> messages = new ArrayList<>();
    final boolean lastSneak = firstNonNull(context.getChannel().attr(SNEAKING).getAndSet(sneak), false);
    if (lastSneak != sneak) {
        messages.add(new MessagePlayInPlayerSneak(sneak));
    }
    final boolean lastJump = firstNonNull(context.getChannel().attr(JUMPING).getAndSet(jump), false);
    if (lastJump != jump && !firstNonNull(context.getChannel().attr(CodecPlayInPlayerAction.CANCEL_NEXT_JUMP_MESSAGE).getAndSet(false), false)) {
        messages.add(new MessagePlayInPlayerVehicleJump(jump, 0f));
    }
    // The mc client already applies the sneak speed, but we want to choose it
    if (sneak) {
        sideways /= 0.3f;
        forwards /= 0.3f;
    }
    messages.add(new MessagePlayInPlayerMovementInput(forwards, sideways));
    return messages.size() == 1 ? messages.get(0) : new BulkMessage(messages);
}
Also used : MessagePlayInPlayerMovementInput(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerMovementInput) BulkMessage(org.lanternpowered.server.network.message.BulkMessage) Message(org.lanternpowered.server.network.message.Message) BulkMessage(org.lanternpowered.server.network.message.BulkMessage) MessagePlayInPlayerVehicleJump(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerVehicleJump) ArrayList(java.util.ArrayList) MessagePlayInPlayerSneak(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerSneak)

Example 2 with MessagePlayInPlayerSneak

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

the class CodecPlayInPlayerAction method decode.

@Override
public Message decode(CodecContext context, ByteBuffer buf) throws CodecException {
    // Normally should this be the entity id, but only the
    // client player will send this, so it won't be used
    buf.readVarInt();
    final int action = buf.readVarInt();
    final int value = buf.readVarInt();
    // Sneaking states
    if (action == 0 || action == 1) {
        return new MessagePlayInPlayerSneak(action == 0);
    // Sprinting states
    } else if (action == 3 || action == 4) {
        return new MessagePlayInPlayerSprint(action == 3);
    // Leave bed button is pressed
    } else if (action == 2) {
        return new MessagePlayInLeaveBed();
    // Horse jump power action
    } else if (action == 5) {
        // Make sure that the vehicle movement message doesn't add the jump message as well
        context.getChannel().attr(CANCEL_NEXT_JUMP_MESSAGE).set(true);
        return new MessagePlayInPlayerVehicleJump(false, ((float) value) / 100f);
    } else if (action == 6) {
        // be removed in 1.9, so ignoring it.
        return NullMessage.INSTANCE;
    } else if (action == 7) {
        return new MessagePlayInRequestHorseInventory();
    } else if (action == 8) {
        return new MessagePlayInStartElytraFlying();
    }
    throw new CodecException("Unknown action type: " + action);
}
Also used : MessagePlayInPlayerSprint(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerSprint) MessagePlayInStartElytraFlying(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInStartElytraFlying) MessagePlayInPlayerVehicleJump(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerVehicleJump) MessagePlayInPlayerSneak(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerSneak) CodecException(io.netty.handler.codec.CodecException) MessagePlayInRequestHorseInventory(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInRequestHorseInventory) MessagePlayInPlayerSprint(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerSprint) MessagePlayInLeaveBed(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInLeaveBed)

Aggregations

MessagePlayInPlayerSneak (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerSneak)2 MessagePlayInPlayerVehicleJump (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerVehicleJump)2 CodecException (io.netty.handler.codec.CodecException)1 ArrayList (java.util.ArrayList)1 BulkMessage (org.lanternpowered.server.network.message.BulkMessage)1 Message (org.lanternpowered.server.network.message.Message)1 MessagePlayInLeaveBed (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInLeaveBed)1 MessagePlayInPlayerMovementInput (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerMovementInput)1 MessagePlayInPlayerSprint (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerSprint)1 MessagePlayInRequestHorseInventory (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInRequestHorseInventory)1 MessagePlayInStartElytraFlying (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInStartElytraFlying)1