use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutPlayerPositionAndLook method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutPlayerPositionAndLook message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeDouble(message.getX());
buf.writeDouble(message.getY());
buf.writeDouble(message.getZ());
buf.writeFloat(message.getYaw());
buf.writeFloat(message.getPitch());
Set<RelativePositions> relativePositions = message.getRelativePositions();
byte flags = 0;
if (relativePositions.contains(RelativePositions.X)) {
flags |= 0x01;
}
if (relativePositions.contains(RelativePositions.Y)) {
flags |= 0x02;
}
if (relativePositions.contains(RelativePositions.Z)) {
flags |= 0x04;
}
if (relativePositions.contains(RelativePositions.PITCH)) {
flags |= 0x08;
}
if (relativePositions.contains(RelativePositions.YAW)) {
flags |= 0x10;
}
buf.writeByte(flags);
buf.writeVarInt(message.getTeleportId());
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayInOutConfirmWindowTransaction method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayInOutConfirmWindowTransaction message) throws CodecException {
ByteBuffer buf = context.byteBufAlloc().buffer(6);
buf.writeByte((byte) message.getWindowId());
buf.writeShort((short) message.getTransaction());
buf.writeBoolean(message.isAccepted());
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayInOutCustomPayload method encode0.
@Override
protected MessageResult encode0(CodecContext context, Message message) throws CodecException {
if (message instanceof MessagePlayInOutBrand) {
return new MessageResult("MC|Brand", context.byteBufAlloc().buffer().writeString(((MessagePlayInOutBrand) message).getBrand()));
} else if (message instanceof MessagePlayOutOpenBook) {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeVarInt(((MessagePlayOutOpenBook) message).getHandType() == HandTypes.MAIN_HAND ? 0 : 1);
return new MessageResult("MC|BOpen", buf);
} else if (message instanceof MessagePlayOutStopSounds) {
final MessagePlayOutStopSounds message0 = (MessagePlayOutStopSounds) message;
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeString(message0.getCategory() == null ? "" : message0.getCategory().getName());
buf.writeString(message0.getSound() == null ? "" : message0.getSound());
return new MessageResult("MC|StopSound", buf);
}
throw new EncoderException("Unsupported message type: " + message);
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutAddPotionEffect method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutAddPotionEffect message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeVarInt(message.getEntityId());
buf.writeByte((byte) ((LanternPotionEffectType) message.getType()).getInternalId());
buf.writeByte((byte) message.getAmplifier());
buf.writeVarInt(message.getDuration());
byte flags = 0;
if (message.isAmbient()) {
flags |= 0x1;
}
if (message.getShowParticles()) {
flags |= 0x2;
}
buf.writeByte(flags);
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutSetExperience method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSetExperience message) throws CodecException {
ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeFloat(message.getExp());
buf.writeVarInt(message.getLevel());
buf.writeVarInt(message.getTotal());
return buf;
}
Aggregations