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);
}
}
Aggregations