use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerMovementInput 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);
}
Aggregations